require_gist 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/require_gist.rb CHANGED
@@ -3,7 +3,7 @@ require "open-uri"
3
3
 
4
4
  def require_gist(gist_url, gist_sha1 = nil)
5
5
  if gist_url =~ /^\d/
6
- gist_url = "https://gist.github.com/raw/#{ gist_url }"
6
+ gist_url = "http://gist.github.com/raw/#{ gist_url }"
7
7
  end
8
8
  gist_id, gist_rev, file = gist_url.match(%r{ https://gist.github.com/raw/(.+?)/(.+?)/(.+) }x).captures
9
9
  dir = FileUtils.mkdir_p(File.join(ENV["HOME"], ".gist"))
data/require_gist.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{require_gist}
5
- s.version = "0.0.2"
5
+ s.version = "0.0.3"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Evgeniy Dolzhenko"]
@@ -6,7 +6,7 @@ require "require_gist"
6
6
 
7
7
  describe "RequireGist" do
8
8
  it "requires gists" do
9
- require_gist "https://gist.github.com/raw/372689/df2b91fc88db48e3fa58a1cfffdbf214651a1bbf/require_gist_test_gist.rb"
9
+ require_gist "372689/df2b91fc88db48e3fa58a1cfffdbf214651a1bbf/require_gist_test_gist.rb"
10
10
  ::RequireGistTestGist.should == 4
11
11
  end
12
12
 
@@ -1,219 +1,223 @@
1
1
  // ==UserScript==
2
2
  // @name require_gist
3
3
  // @namespace http://userscripts.org/users/151038
4
- // @include http://gist.github.com/*
4
+ // @include http://gist.github.com/*
5
5
  // @include https://gist.github.com/*
6
6
  // @require http://userscripts.org/scripts/source/68059.user.js
7
7
  // ==/UserScript==
8
8
 
9
9
  (function() {
10
- var main = function() {
11
- console.log("require_gist");
12
-
13
- var jQuery = unsafeWindow.jQuery;
14
-
15
- if (/http:\/\/gist.github.com\/\d+/.test(window.location.href)) {
16
- var raw_link = jQuery("a[href^=/raw]:first");
17
- console.log("found link");
18
- if (raw_link.length) {
19
- console.log("requesting link");
20
- jQuery.get(raw_link.attr("href"), function(data) {
21
- var require_gist_code = "require_gist \"" + raw_link.attr("href").replace("/raw/", "") + "\", \"" + SHA1(data) + "\" # " + window.location.href;
22
- var label = "<td class=\"label\">require_gist:</td>";
23
- var code = "<td>" +
24
- "<a class=\"gist-embed-link\" href=\"#\" style=\"display: inline;\">show code</a>" +
25
- "<input type=\"text\" style=\"display: none;\" size=25 class=\"gist-embed-box\">" +
26
- "</td>";
27
- var tr = jQuery("<tr>" + label + code + "</tr>");
28
- tr.find(".gist-embed-link").click(function(event) {
29
- event.preventDefault();
30
- jQuery(this).hide();
31
- var input = tr.find("td:last input").val(require_gist_code).show();
32
- input.get(0).select();
33
- });
34
-
35
- jQuery("#repos .meta table").append(tr);
36
-
37
- console.log();
38
- });
39
- }
10
+ var main = function() {
11
+ var jQuery = unsafeWindow.jQuery;
12
+
13
+ if (/http:\/\/gist.github.com\/\d+/.test(window.location.href)) {
14
+ var raw_link = jQuery("a[href^=/raw]:first");
15
+ if (raw_link.length) {
16
+ jQuery.get(raw_link.attr("href"), function(data) {
17
+ var require_gist_code = "require_gist \"" + raw_link.attr("href").replace("/raw/", "") + "\", \"" + SHA1(data) + "\" # " + window.location.href;
18
+ var label = "<td class=\"label\">require_gist:</td>";
19
+ var code = "<td>" +
20
+ "<a class=\"gist-embed-link\" href=\"#\" style=\"display: inline;\">show code</a>" +
21
+ "<input type=\"text\" style=\"display: none;\" size=25 class=\"gist-embed-box\">" +
22
+ "</td>";
23
+ var tr = jQuery("<tr>" + label + code + "</tr>");
24
+ tr.find(".gist-embed-link").click(function(event) {
25
+ event.preventDefault();
26
+ jQuery(this).hide();
27
+ var input = tr.find("td:last input").val(require_gist_code).show();
28
+ input.get(0).select();
29
+ });
30
+
31
+ jQuery("#repos .meta table").append(tr);
32
+
33
+ console.log();
34
+ });
35
+ }
36
+ }
37
+ }
38
+
39
+ /**
40
+ *
41
+ * Secure Hash Algorithm (SHA1)
42
+ * http://www.webtoolkit.info/
43
+ *
44
+ **/
45
+
46
+ function SHA1(msg) {
47
+
48
+ function rotate_left(n, s) {
49
+ var t4 = ( n << s ) | (n >>> (32 - s));
50
+ return t4;
51
+ }
52
+
53
+ ;
54
+
55
+ function lsb_hex(val) {
56
+ var str = "";
57
+ var i;
58
+ var vh;
59
+ var vl;
60
+
61
+ for (i = 0; i <= 6; i += 2) {
62
+ vh = (val >>> (i * 4 + 4)) & 0x0f;
63
+ vl = (val >>> (i * 4)) & 0x0f;
64
+ str += vh.toString(16) + vl.toString(16);
65
+ }
66
+ return str;
67
+ }
68
+
69
+ ;
70
+
71
+ function cvt_hex(val) {
72
+ var str = "";
73
+ var i;
74
+ var v;
75
+
76
+ for (i = 7; i >= 0; i--) {
77
+ v = (val >>> (i * 4)) & 0x0f;
78
+ str += v.toString(16);
79
+ }
80
+ return str;
81
+ }
82
+
83
+ ;
84
+
85
+
86
+ function Utf8Encode(string) {
87
+ string = string.replace(/\r\n/g, "\n");
88
+ var utftext = "";
89
+
90
+ for (var n = 0; n < string.length; n++) {
91
+
92
+ var c = string.charCodeAt(n);
93
+
94
+ if (c < 128) {
95
+ utftext += String.fromCharCode(c);
96
+ }
97
+ else if ((c > 127) && (c < 2048)) {
98
+ utftext += String.fromCharCode((c >> 6) | 192);
99
+ utftext += String.fromCharCode((c & 63) | 128);
100
+ }
101
+ else {
102
+ utftext += String.fromCharCode((c >> 12) | 224);
103
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128);
104
+ utftext += String.fromCharCode((c & 63) | 128);
40
105
  }
106
+
107
+ }
108
+
109
+ return utftext;
110
+ }
111
+
112
+ ;
113
+
114
+ var blockstart;
115
+ var i, j;
116
+ var W = new Array(80);
117
+ var H0 = 0x67452301;
118
+ var H1 = 0xEFCDAB89;
119
+ var H2 = 0x98BADCFE;
120
+ var H3 = 0x10325476;
121
+ var H4 = 0xC3D2E1F0;
122
+ var A, B, C, D, E;
123
+ var temp;
124
+
125
+ msg = Utf8Encode(msg);
126
+
127
+ var msg_len = msg.length;
128
+
129
+ var word_array = new Array();
130
+ for (i = 0; i < msg_len - 3; i += 4) {
131
+ j = msg.charCodeAt(i) << 24 | msg.charCodeAt(i + 1) << 16 |
132
+ msg.charCodeAt(i + 2) << 8 | msg.charCodeAt(i + 3);
133
+ word_array.push(j);
134
+ }
135
+
136
+ switch (msg_len % 4) {
137
+ case 0:
138
+ i = 0x080000000;
139
+ break;
140
+ case 1:
141
+ i = msg.charCodeAt(msg_len - 1) << 24 | 0x0800000;
142
+ break;
143
+
144
+ case 2:
145
+ i = msg.charCodeAt(msg_len - 2) << 24 | msg.charCodeAt(msg_len - 1) << 16 | 0x08000;
146
+ break;
147
+
148
+ case 3:
149
+ i = msg.charCodeAt(msg_len - 3) << 24 | msg.charCodeAt(msg_len - 2) << 16 | msg.charCodeAt(msg_len - 1) << 8 | 0x80;
150
+ break;
41
151
  }
42
-
43
- /**
44
- *
45
- * Secure Hash Algorithm (SHA1)
46
- * http://www.webtoolkit.info/
47
- *
48
- **/
49
-
50
- function SHA1 (msg) {
51
-
52
- function rotate_left(n,s) {
53
- var t4 = ( n<<s ) | (n>>>(32-s));
54
- return t4;
55
- };
56
-
57
- function lsb_hex(val) {
58
- var str="";
59
- var i;
60
- var vh;
61
- var vl;
62
-
63
- for( i=0; i<=6; i+=2 ) {
64
- vh = (val>>>(i*4+4))&0x0f;
65
- vl = (val>>>(i*4))&0x0f;
66
- str += vh.toString(16) + vl.toString(16);
67
- }
68
- return str;
69
- };
70
-
71
- function cvt_hex(val) {
72
- var str="";
73
- var i;
74
- var v;
75
-
76
- for( i=7; i>=0; i-- ) {
77
- v = (val>>>(i*4))&0x0f;
78
- str += v.toString(16);
79
- }
80
- return str;
81
- };
82
-
83
-
84
- function Utf8Encode(string) {
85
- string = string.replace(/\r\n/g,"\n");
86
- var utftext = "";
87
-
88
- for (var n = 0; n < string.length; n++) {
89
-
90
- var c = string.charCodeAt(n);
91
-
92
- if (c < 128) {
93
- utftext += String.fromCharCode(c);
94
- }
95
- else if((c > 127) && (c < 2048)) {
96
- utftext += String.fromCharCode((c >> 6) | 192);
97
- utftext += String.fromCharCode((c & 63) | 128);
98
- }
99
- else {
100
- utftext += String.fromCharCode((c >> 12) | 224);
101
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
102
- utftext += String.fromCharCode((c & 63) | 128);
103
- }
104
-
105
- }
106
-
107
- return utftext;
108
- };
109
-
110
- var blockstart;
111
- var i, j;
112
- var W = new Array(80);
113
- var H0 = 0x67452301;
114
- var H1 = 0xEFCDAB89;
115
- var H2 = 0x98BADCFE;
116
- var H3 = 0x10325476;
117
- var H4 = 0xC3D2E1F0;
118
- var A, B, C, D, E;
119
- var temp;
120
-
121
- msg = Utf8Encode(msg);
122
-
123
- var msg_len = msg.length;
124
-
125
- var word_array = new Array();
126
- for( i=0; i<msg_len-3; i+=4 ) {
127
- j = msg.charCodeAt(i)<<24 | msg.charCodeAt(i+1)<<16 |
128
- msg.charCodeAt(i+2)<<8 | msg.charCodeAt(i+3);
129
- word_array.push( j );
130
- }
131
-
132
- switch( msg_len % 4 ) {
133
- case 0:
134
- i = 0x080000000;
135
- break;
136
- case 1:
137
- i = msg.charCodeAt(msg_len-1)<<24 | 0x0800000;
138
- break;
139
-
140
- case 2:
141
- i = msg.charCodeAt(msg_len-2)<<24 | msg.charCodeAt(msg_len-1)<<16 | 0x08000;
142
- break;
143
-
144
- case 3:
145
- i = msg.charCodeAt(msg_len-3)<<24 | msg.charCodeAt(msg_len-2)<<16 | msg.charCodeAt(msg_len-1)<<8 | 0x80;
146
- break;
147
- }
148
-
149
- word_array.push( i );
150
-
151
- while( (word_array.length % 16) != 14 ) word_array.push( 0 );
152
-
153
- word_array.push( msg_len>>>29 );
154
- word_array.push( (msg_len<<3)&0x0ffffffff );
155
-
156
-
157
- for ( blockstart=0; blockstart<word_array.length; blockstart+=16 ) {
158
-
159
- for( i=0; i<16; i++ ) W[i] = word_array[blockstart+i];
160
- for( i=16; i<=79; i++ ) W[i] = rotate_left(W[i-3] ^ W[i-8] ^ W[i-14] ^ W[i-16], 1);
161
-
162
- A = H0;
163
- B = H1;
164
- C = H2;
165
- D = H3;
166
- E = H4;
167
-
168
- for( i= 0; i<=19; i++ ) {
169
- temp = (rotate_left(A,5) + ((B&C) | (~B&D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
170
- E = D;
171
- D = C;
172
- C = rotate_left(B,30);
173
- B = A;
174
- A = temp;
175
- }
176
-
177
- for( i=20; i<=39; i++ ) {
178
- temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
179
- E = D;
180
- D = C;
181
- C = rotate_left(B,30);
182
- B = A;
183
- A = temp;
184
- }
185
-
186
- for( i=40; i<=59; i++ ) {
187
- temp = (rotate_left(A,5) + ((B&C) | (B&D) | (C&D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
188
- E = D;
189
- D = C;
190
- C = rotate_left(B,30);
191
- B = A;
192
- A = temp;
193
- }
194
-
195
- for( i=60; i<=79; i++ ) {
196
- temp = (rotate_left(A,5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
197
- E = D;
198
- D = C;
199
- C = rotate_left(B,30);
200
- B = A;
201
- A = temp;
202
- }
203
-
204
- H0 = (H0 + A) & 0x0ffffffff;
205
- H1 = (H1 + B) & 0x0ffffffff;
206
- H2 = (H2 + C) & 0x0ffffffff;
207
- H3 = (H3 + D) & 0x0ffffffff;
208
- H4 = (H4 + E) & 0x0ffffffff;
209
-
210
- }
211
-
212
- var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
213
-
214
- return temp.toLowerCase();
215
-
216
- }
217
-
218
- main();
152
+
153
+ word_array.push(i);
154
+
155
+ while ((word_array.length % 16) != 14) word_array.push(0);
156
+
157
+ word_array.push(msg_len >>> 29);
158
+ word_array.push((msg_len << 3) & 0x0ffffffff);
159
+
160
+
161
+ for (blockstart = 0; blockstart < word_array.length; blockstart += 16) {
162
+
163
+ for (i = 0; i < 16; i++) W[i] = word_array[blockstart + i];
164
+ for (i = 16; i <= 79; i++) W[i] = rotate_left(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
165
+
166
+ A = H0;
167
+ B = H1;
168
+ C = H2;
169
+ D = H3;
170
+ E = H4;
171
+
172
+ for (i = 0; i <= 19; i++) {
173
+ temp = (rotate_left(A, 5) + ((B & C) | (~B & D)) + E + W[i] + 0x5A827999) & 0x0ffffffff;
174
+ E = D;
175
+ D = C;
176
+ C = rotate_left(B, 30);
177
+ B = A;
178
+ A = temp;
179
+ }
180
+
181
+ for (i = 20; i <= 39; i++) {
182
+ temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0x6ED9EBA1) & 0x0ffffffff;
183
+ E = D;
184
+ D = C;
185
+ C = rotate_left(B, 30);
186
+ B = A;
187
+ A = temp;
188
+ }
189
+
190
+ for (i = 40; i <= 59; i++) {
191
+ temp = (rotate_left(A, 5) + ((B & C) | (B & D) | (C & D)) + E + W[i] + 0x8F1BBCDC) & 0x0ffffffff;
192
+ E = D;
193
+ D = C;
194
+ C = rotate_left(B, 30);
195
+ B = A;
196
+ A = temp;
197
+ }
198
+
199
+ for (i = 60; i <= 79; i++) {
200
+ temp = (rotate_left(A, 5) + (B ^ C ^ D) + E + W[i] + 0xCA62C1D6) & 0x0ffffffff;
201
+ E = D;
202
+ D = C;
203
+ C = rotate_left(B, 30);
204
+ B = A;
205
+ A = temp;
206
+ }
207
+
208
+ H0 = (H0 + A) & 0x0ffffffff;
209
+ H1 = (H1 + B) & 0x0ffffffff;
210
+ H2 = (H2 + C) & 0x0ffffffff;
211
+ H3 = (H3 + D) & 0x0ffffffff;
212
+ H4 = (H4 + E) & 0x0ffffffff;
213
+
214
+ }
215
+
216
+ var temp = cvt_hex(H0) + cvt_hex(H1) + cvt_hex(H2) + cvt_hex(H3) + cvt_hex(H4);
217
+
218
+ return temp.toLowerCase();
219
+
220
+ }
221
+
222
+ main();
219
223
  })();
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 2
9
- version: 0.0.2
8
+ - 3
9
+ version: 0.0.3
10
10
  platform: ruby
11
11
  authors:
12
12
  - Evgeniy Dolzhenko