spade-packager 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (316) hide show
  1. data/.gitignore +2 -0
  2. data/.gitmodules +6 -0
  3. data/bin/spadepkg +8 -0
  4. data/lib/libgems_ext.rb +8 -0
  5. data/lib/libgems_ext/config_file.rb +33 -0
  6. data/lib/libgems_ext/dependency_installer.rb +150 -0
  7. data/lib/libgems_ext/installer.rb +39 -0
  8. data/lib/libgems_ext/libgems.rb +39 -0
  9. data/lib/libgems_ext/spec_fetcher.rb +11 -0
  10. data/lib/spade-packager.rb +1 -0
  11. data/lib/spade/packager.rb +18 -0
  12. data/lib/spade/packager/cli.rb +9 -0
  13. data/lib/spade/packager/cli/base.rb +196 -0
  14. data/lib/spade/packager/cli/owner.rb +46 -0
  15. data/lib/spade/packager/cli/project_generator.rb +117 -0
  16. data/lib/spade/packager/credentials.rb +38 -0
  17. data/lib/spade/packager/local.rb +50 -0
  18. data/lib/spade/packager/package.rb +160 -0
  19. data/lib/spade/packager/remote.rb +98 -0
  20. data/lib/spade/packager/repository.rb +18 -0
  21. data/lib/spade/packager/version.rb +5 -0
  22. data/packages/coffee-script/.gitignore +8 -0
  23. data/packages/coffee-script/.npmignore +11 -0
  24. data/packages/coffee-script/Cakefile +229 -0
  25. data/packages/coffee-script/LICENSE +22 -0
  26. data/packages/coffee-script/README +47 -0
  27. data/packages/coffee-script/Rakefile +78 -0
  28. data/packages/coffee-script/bin/cake +7 -0
  29. data/packages/coffee-script/bin/coffee +7 -0
  30. data/packages/coffee-script/documentation/coffee/aliases.coffee +11 -0
  31. data/packages/coffee-script/documentation/coffee/array_comprehensions.coffee +2 -0
  32. data/packages/coffee-script/documentation/coffee/block_comment.coffee +6 -0
  33. data/packages/coffee-script/documentation/coffee/cake_tasks.coffee +9 -0
  34. data/packages/coffee-script/documentation/coffee/classes.coffee +25 -0
  35. data/packages/coffee-script/documentation/coffee/comparisons.coffee +5 -0
  36. data/packages/coffee-script/documentation/coffee/conditionals.coffee +13 -0
  37. data/packages/coffee-script/documentation/coffee/default_args.coffee +8 -0
  38. data/packages/coffee-script/documentation/coffee/do.coffee +4 -0
  39. data/packages/coffee-script/documentation/coffee/embedded.coffee +5 -0
  40. data/packages/coffee-script/documentation/coffee/existence.coffee +10 -0
  41. data/packages/coffee-script/documentation/coffee/expressions.coffee +9 -0
  42. data/packages/coffee-script/documentation/coffee/expressions_assignment.coffee +3 -0
  43. data/packages/coffee-script/documentation/coffee/expressions_comprehension.coffee +3 -0
  44. data/packages/coffee-script/documentation/coffee/expressions_try.coffee +7 -0
  45. data/packages/coffee-script/documentation/coffee/fat_arrow.coffee +6 -0
  46. data/packages/coffee-script/documentation/coffee/functions.coffee +2 -0
  47. data/packages/coffee-script/documentation/coffee/heredocs.coffee +7 -0
  48. data/packages/coffee-script/documentation/coffee/heregexes.coffee +11 -0
  49. data/packages/coffee-script/documentation/coffee/interpolation.coffee +6 -0
  50. data/packages/coffee-script/documentation/coffee/multiple_return_values.coffee +7 -0
  51. data/packages/coffee-script/documentation/coffee/object_comprehensions.coffee +4 -0
  52. data/packages/coffee-script/documentation/coffee/object_extraction.coffee +13 -0
  53. data/packages/coffee-script/documentation/coffee/objects_and_arrays.coffee +19 -0
  54. data/packages/coffee-script/documentation/coffee/objects_reserved.coffee +5 -0
  55. data/packages/coffee-script/documentation/coffee/overview.coffee +28 -0
  56. data/packages/coffee-script/documentation/coffee/parallel_assignment.coffee +6 -0
  57. data/packages/coffee-script/documentation/coffee/patterns_and_splats.coffee +7 -0
  58. data/packages/coffee-script/documentation/coffee/prototypes.coffee +3 -0
  59. data/packages/coffee-script/documentation/coffee/range_comprehensions.coffee +2 -0
  60. data/packages/coffee-script/documentation/coffee/scope.coffee +5 -0
  61. data/packages/coffee-script/documentation/coffee/slices.coffee +7 -0
  62. data/packages/coffee-script/documentation/coffee/soaks.coffee +1 -0
  63. data/packages/coffee-script/documentation/coffee/splats.coffee +27 -0
  64. data/packages/coffee-script/documentation/coffee/splices.coffee +5 -0
  65. data/packages/coffee-script/documentation/coffee/strings.coffee +8 -0
  66. data/packages/coffee-script/documentation/coffee/switch.coffee +10 -0
  67. data/packages/coffee-script/documentation/coffee/try.coffee +8 -0
  68. data/packages/coffee-script/documentation/coffee/while.coffee +10 -0
  69. data/packages/coffee-script/documentation/css/docs.css +374 -0
  70. data/packages/coffee-script/documentation/css/idle.css +64 -0
  71. data/packages/coffee-script/documentation/docs/browser.html +25 -0
  72. data/packages/coffee-script/documentation/docs/cake.html +43 -0
  73. data/packages/coffee-script/documentation/docs/coffee-script.html +51 -0
  74. data/packages/coffee-script/documentation/docs/command.html +161 -0
  75. data/packages/coffee-script/documentation/docs/docco.css +186 -0
  76. data/packages/coffee-script/documentation/docs/grammar.html +399 -0
  77. data/packages/coffee-script/documentation/docs/helpers.html +31 -0
  78. data/packages/coffee-script/documentation/docs/index.html +3 -0
  79. data/packages/coffee-script/documentation/docs/lexer.html +490 -0
  80. data/packages/coffee-script/documentation/docs/nodes.html +1338 -0
  81. data/packages/coffee-script/documentation/docs/optparse.html +78 -0
  82. data/packages/coffee-script/documentation/docs/repl.html +24 -0
  83. data/packages/coffee-script/documentation/docs/rewriter.html +251 -0
  84. data/packages/coffee-script/documentation/docs/scope.html +54 -0
  85. data/packages/coffee-script/documentation/docs/underscore.html +295 -0
  86. data/packages/coffee-script/documentation/images/background.png +0 -0
  87. data/packages/coffee-script/documentation/images/banding.png +0 -0
  88. data/packages/coffee-script/documentation/images/button_bg.png +0 -0
  89. data/packages/coffee-script/documentation/images/button_bg_dark.gif +0 -0
  90. data/packages/coffee-script/documentation/images/button_bg_green.gif +0 -0
  91. data/packages/coffee-script/documentation/images/favicon.ico +0 -0
  92. data/packages/coffee-script/documentation/images/logo.png +0 -0
  93. data/packages/coffee-script/documentation/images/screenshadow.png +0 -0
  94. data/packages/coffee-script/documentation/index.html.erb +1607 -0
  95. data/packages/coffee-script/documentation/js/aliases.js +17 -0
  96. data/packages/coffee-script/documentation/js/array_comprehensions.js +6 -0
  97. data/packages/coffee-script/documentation/js/block_comment.js +4 -0
  98. data/packages/coffee-script/documentation/js/cake_tasks.js +10 -0
  99. data/packages/coffee-script/documentation/js/classes.js +44 -0
  100. data/packages/coffee-script/documentation/js/comparisons.js +3 -0
  101. data/packages/coffee-script/documentation/js/conditionals.js +12 -0
  102. data/packages/coffee-script/documentation/js/default_args.js +7 -0
  103. data/packages/coffee-script/documentation/js/do.js +10 -0
  104. data/packages/coffee-script/documentation/js/embedded.js +4 -0
  105. data/packages/coffee-script/documentation/js/existence.js +6 -0
  106. data/packages/coffee-script/documentation/js/expressions.js +15 -0
  107. data/packages/coffee-script/documentation/js/expressions_assignment.js +2 -0
  108. data/packages/coffee-script/documentation/js/expressions_comprehension.js +9 -0
  109. data/packages/coffee-script/documentation/js/expressions_try.js +7 -0
  110. data/packages/coffee-script/documentation/js/fat_arrow.js +9 -0
  111. data/packages/coffee-script/documentation/js/functions.js +7 -0
  112. data/packages/coffee-script/documentation/js/heredocs.js +2 -0
  113. data/packages/coffee-script/documentation/js/heregexes.js +2 -0
  114. data/packages/coffee-script/documentation/js/interpolation.js +4 -0
  115. data/packages/coffee-script/documentation/js/multiple_return_values.js +5 -0
  116. data/packages/coffee-script/documentation/js/object_comprehensions.js +15 -0
  117. data/packages/coffee-script/documentation/js/object_extraction.js +10 -0
  118. data/packages/coffee-script/documentation/js/objects_and_arrays.js +17 -0
  119. data/packages/coffee-script/documentation/js/objects_reserved.js +4 -0
  120. data/packages/coffee-script/documentation/js/overview.js +35 -0
  121. data/packages/coffee-script/documentation/js/parallel_assignment.js +4 -0
  122. data/packages/coffee-script/documentation/js/patterns_and_splats.js +4 -0
  123. data/packages/coffee-script/documentation/js/prototypes.js +3 -0
  124. data/packages/coffee-script/documentation/js/range_comprehensions.js +9 -0
  125. data/packages/coffee-script/documentation/js/scope.js +8 -0
  126. data/packages/coffee-script/documentation/js/slices.js +4 -0
  127. data/packages/coffee-script/documentation/js/soaks.js +2 -0
  128. data/packages/coffee-script/documentation/js/splats.js +15 -0
  129. data/packages/coffee-script/documentation/js/splices.js +3 -0
  130. data/packages/coffee-script/documentation/js/strings.js +2 -0
  131. data/packages/coffee-script/documentation/js/switch.js +23 -0
  132. data/packages/coffee-script/documentation/js/try.js +8 -0
  133. data/packages/coffee-script/documentation/js/while.js +18 -0
  134. data/packages/coffee-script/documentation/vendor/jquery-1.4.2.js +6240 -0
  135. data/packages/coffee-script/examples/beautiful_code/binary_search.coffee +16 -0
  136. data/packages/coffee-script/examples/beautiful_code/quicksort_runtime.coffee +13 -0
  137. data/packages/coffee-script/examples/beautiful_code/regular_expression_matcher.coffee +34 -0
  138. data/packages/coffee-script/examples/blocks.coffee +54 -0
  139. data/packages/coffee-script/examples/code.coffee +167 -0
  140. data/packages/coffee-script/examples/computer_science/README +4 -0
  141. data/packages/coffee-script/examples/computer_science/binary_search.coffee +25 -0
  142. data/packages/coffee-script/examples/computer_science/bubble_sort.coffee +11 -0
  143. data/packages/coffee-script/examples/computer_science/linked_list.coffee +108 -0
  144. data/packages/coffee-script/examples/computer_science/luhn_algorithm.coffee +36 -0
  145. data/packages/coffee-script/examples/computer_science/merge_sort.coffee +19 -0
  146. data/packages/coffee-script/examples/computer_science/selection_sort.coffee +23 -0
  147. data/packages/coffee-script/examples/poignant.coffee +181 -0
  148. data/packages/coffee-script/examples/potion.coffee +206 -0
  149. data/packages/coffee-script/examples/underscore.coffee +682 -0
  150. data/packages/coffee-script/examples/web_server.coffee +12 -0
  151. data/packages/coffee-script/extras/EXTRAS +7 -0
  152. data/packages/coffee-script/extras/coffee-script.js +8 -0
  153. data/packages/coffee-script/extras/jsl.conf +44 -0
  154. data/packages/coffee-script/index.html +2515 -0
  155. data/packages/coffee-script/lib/browser.js +52 -0
  156. data/packages/coffee-script/lib/cake.js +76 -0
  157. data/packages/coffee-script/lib/coffee-script.js +82 -0
  158. data/packages/coffee-script/lib/command.js +263 -0
  159. data/packages/coffee-script/lib/grammar.js +581 -0
  160. data/packages/coffee-script/lib/helpers.js +66 -0
  161. data/packages/coffee-script/lib/index.js +8 -0
  162. data/packages/coffee-script/lib/lexer.js +633 -0
  163. data/packages/coffee-script/lib/nodes.js +2165 -0
  164. data/packages/coffee-script/lib/optparse.js +111 -0
  165. data/packages/coffee-script/lib/parser.js +649 -0
  166. data/packages/coffee-script/lib/repl.js +42 -0
  167. data/packages/coffee-script/lib/rewriter.js +353 -0
  168. data/packages/coffee-script/lib/scope.js +120 -0
  169. data/packages/coffee-script/lib/spade-format.js +45 -0
  170. data/packages/coffee-script/package.json +26 -0
  171. data/packages/coffee-script/src/browser.coffee +43 -0
  172. data/packages/coffee-script/src/cake.coffee +69 -0
  173. data/packages/coffee-script/src/coffee-script.coffee +92 -0
  174. data/packages/coffee-script/src/command.coffee +214 -0
  175. data/packages/coffee-script/src/grammar.coffee +590 -0
  176. data/packages/coffee-script/src/helpers.coffee +56 -0
  177. data/packages/coffee-script/src/index.coffee +2 -0
  178. data/packages/coffee-script/src/lexer.coffee +653 -0
  179. data/packages/coffee-script/src/nodes.coffee +1754 -0
  180. data/packages/coffee-script/src/optparse.coffee +99 -0
  181. data/packages/coffee-script/src/repl.coffee +42 -0
  182. data/packages/coffee-script/src/rewriter.coffee +326 -0
  183. data/packages/coffee-script/src/scope.coffee +94 -0
  184. data/packages/coffee-script/test/arguments.coffee +127 -0
  185. data/packages/coffee-script/test/assignment.coffee +98 -0
  186. data/packages/coffee-script/test/break.coffee +18 -0
  187. data/packages/coffee-script/test/comments.coffee +201 -0
  188. data/packages/coffee-script/test/conditionals.coffee +181 -0
  189. data/packages/coffee-script/test/exception_handling.coffee +90 -0
  190. data/packages/coffee-script/test/helpers.coffee +96 -0
  191. data/packages/coffee-script/test/importing.coffee +18 -0
  192. data/packages/coffee-script/test/operators.coffee +225 -0
  193. data/packages/coffee-script/test/ranges_slices_and_splices.coffee +186 -0
  194. data/packages/coffee-script/test/regular_expressions.coffee +56 -0
  195. data/packages/coffee-script/test/test.html +123 -0
  196. data/packages/coffee-script/test/test_chaining.coffee +77 -0
  197. data/packages/coffee-script/test/test_classes.coffee +372 -0
  198. data/packages/coffee-script/test/test_compilation.coffee +26 -0
  199. data/packages/coffee-script/test/test_comprehensions.coffee +318 -0
  200. data/packages/coffee-script/test/test_existence.coffee +165 -0
  201. data/packages/coffee-script/test/test_functions.coffee +379 -0
  202. data/packages/coffee-script/test/test_heredocs.coffee +111 -0
  203. data/packages/coffee-script/test/test_literals.coffee +270 -0
  204. data/packages/coffee-script/test/test_option_parser.coffee +27 -0
  205. data/packages/coffee-script/test/test_pattern_matching.coffee +162 -0
  206. data/packages/coffee-script/test/test_returns.coffee +63 -0
  207. data/packages/coffee-script/test/test_splats.coffee +102 -0
  208. data/packages/coffee-script/test/test_strings.coffee +118 -0
  209. data/packages/coffee-script/test/test_switch.coffee +103 -0
  210. data/packages/coffee-script/test/test_while.coffee +71 -0
  211. data/packages/ivory/LICENSE.txt +1 -0
  212. data/packages/ivory/README.md +19 -0
  213. data/packages/ivory/lib/buffer.js +111 -0
  214. data/packages/ivory/lib/events.js +137 -0
  215. data/packages/ivory/lib/fs.js +266 -0
  216. data/packages/ivory/lib/main.js +13 -0
  217. data/packages/ivory/lib/path.js +158 -0
  218. data/packages/ivory/lib/ruby/buffer.rb +145 -0
  219. data/packages/ivory/lib/ruby/constants.rb +585 -0
  220. data/packages/ivory/lib/ruby/events.rb +32 -0
  221. data/packages/ivory/lib/ruby/fs.rb +245 -0
  222. data/packages/ivory/lib/ruby/process.rb +28 -0
  223. data/packages/ivory/lib/stream.js +115 -0
  224. data/packages/ivory/lib/util.js +414 -0
  225. data/packages/ivory/package.json +11 -0
  226. data/packages/ivory/spade-boot.js +78 -0
  227. data/packages/jquery/main.js +7179 -0
  228. data/packages/jquery/package.json +10 -0
  229. data/packages/json/lib/main.js +14 -0
  230. data/packages/json/package.json +8 -0
  231. data/packages/lproj/README.md +77 -0
  232. data/packages/lproj/examples/demo-app/en.lproj/localized.strings +2 -0
  233. data/packages/lproj/examples/demo-app/fr.lproj/localized.strings +3 -0
  234. data/packages/lproj/examples/demo-app/index.html +8 -0
  235. data/packages/lproj/examples/demo-app/lib/main.js +7 -0
  236. data/packages/lproj/examples/demo-app/package.json +9 -0
  237. data/packages/lproj/lib/main.js +78 -0
  238. data/packages/lproj/lib/strings-format.js +6 -0
  239. data/packages/lproj/package.json +9 -0
  240. data/packages/optparse/README.md +161 -0
  241. data/packages/optparse/TODO +1 -0
  242. data/packages/optparse/examples/browser-test.html +75 -0
  243. data/packages/optparse/examples/nodejs-test.js +90 -0
  244. data/packages/optparse/lib/optparse.js +309 -0
  245. data/packages/optparse/package.json +13 -0
  246. data/packages/optparse/seed.yml +5 -0
  247. data/packages/text/lib/main.js +8 -0
  248. data/packages/text/package.json +9 -0
  249. data/packages/web-file/README.md +7 -0
  250. data/packages/web-file/lib/errors.js +32 -0
  251. data/packages/web-file/lib/file-reader.js +10 -0
  252. data/packages/web-file/lib/file-system.js +234 -0
  253. data/packages/web-file/lib/file-writer.js +10 -0
  254. data/packages/web-file/lib/file.js +9 -0
  255. data/packages/web-file/lib/main.js +34 -0
  256. data/packages/web-file/lib/platform.js +25 -0
  257. data/packages/web-file/lib/ruby/file.rb +252 -0
  258. data/packages/web-file/lib/ruby/file_reader.rb +69 -0
  259. data/packages/web-file/lib/ruby/file_system.rb +134 -0
  260. data/packages/web-file/lib/ruby/file_writer.rb +78 -0
  261. data/packages/web-file/package.json +12 -0
  262. data/packages/web-typed-array/README.md +7 -0
  263. data/packages/web-typed-array/lib/array-buffer-view.js +9 -0
  264. data/packages/web-typed-array/lib/array-buffer.js +7 -0
  265. data/packages/web-typed-array/lib/main.js +33 -0
  266. data/packages/web-typed-array/lib/platform.js +20 -0
  267. data/packages/web-typed-array/lib/ruby/array_buffer.rb +31 -0
  268. data/packages/web-typed-array/lib/ruby/array_buffer_view.rb +130 -0
  269. data/packages/web-typed-array/lib/ruby/typed_array.rb +133 -0
  270. data/packages/web-typed-array/lib/typed-array.js +26 -0
  271. data/packages/web-typed-array/package.json +9 -0
  272. data/spade-packager.gemspec +39 -0
  273. data/spec/cli/build_spec.rb +57 -0
  274. data/spec/cli/install_spec.rb +119 -0
  275. data/spec/cli/installed_spec.rb +55 -0
  276. data/spec/cli/list_spec.rb +74 -0
  277. data/spec/cli/login_spec.rb +75 -0
  278. data/spec/cli/new_spec.rb +5 -0
  279. data/spec/cli/owner_spec.rb +114 -0
  280. data/spec/cli/push_spec.rb +73 -0
  281. data/spec/cli/uninstall_spec.rb +58 -0
  282. data/spec/cli/unpack_spec.rb +72 -0
  283. data/spec/cli/unyank_spec.rb +73 -0
  284. data/spec/cli/yank_spec.rb +73 -0
  285. data/spec/credentials_spec.rb +23 -0
  286. data/spec/fixtures/badrake-0.8.7.spd +0 -0
  287. data/spec/fixtures/builder-3.0.0.spd +0 -0
  288. data/spec/fixtures/bundler-1.1.pre.spd +0 -0
  289. data/spec/fixtures/coffee-1.0.1.pre.spd +0 -0
  290. data/spec/fixtures/core-test-0.4.3.spd +0 -0
  291. data/spec/fixtures/core-test/bin/cot +3 -0
  292. data/spec/fixtures/core-test/lib/main.js +1 -0
  293. data/spec/fixtures/core-test/resources/runner.css +0 -0
  294. data/spec/fixtures/core-test/tests/test.js +1 -0
  295. data/spec/fixtures/highline-1.6.1.spd +0 -0
  296. data/spec/fixtures/ivory-0.0.1.spd +0 -0
  297. data/spec/fixtures/jquery-1.4.3.spd +0 -0
  298. data/spec/fixtures/optparse-1.0.1.spd +0 -0
  299. data/spec/fixtures/package.json +30 -0
  300. data/spec/fixtures/rake-0.8.6.spd +0 -0
  301. data/spec/fixtures/rake-0.8.7.spd +0 -0
  302. data/spec/gauntlet_spec.rb +27 -0
  303. data/spec/package_spec.rb +267 -0
  304. data/spec/spec_helper.rb +32 -0
  305. data/spec/support/cli.rb +103 -0
  306. data/spec/support/fake.rb +48 -0
  307. data/spec/support/fake_gem_server.rb +67 -0
  308. data/spec/support/fake_gemcutter.rb +50 -0
  309. data/spec/support/matchers.rb +32 -0
  310. data/spec/support/path.rb +61 -0
  311. data/templates/project/LICENSE +19 -0
  312. data/templates/project/README.md +21 -0
  313. data/templates/project/lib/main.js +9 -0
  314. data/templates/project/project.json +31 -0
  315. data/templates/project/tests/main-test.js +8 -0
  316. metadata +484 -0
@@ -0,0 +1,16 @@
1
+ # Beautiful Code, Chapter 6.
2
+ # The implementation of binary search that is tested.
3
+
4
+ # Return the index of an element in a sorted list. (or -1, if not present)
5
+ index = (list, target) ->
6
+ [low, high] = [0, list.length]
7
+ while low < high
8
+ mid = (low + high) >> 1
9
+ val = list[mid]
10
+ return mid if val is target
11
+ if val < target then low = mid + 1 else high = mid
12
+ return -1
13
+
14
+ console.log 2 is index [10, 20, 30, 40, 50], 30
15
+ console.log 4 is index [-97, 35, 67, 88, 1200], 1200
16
+ console.log 0 is index [0, 45, 70], 0
@@ -0,0 +1,13 @@
1
+ # Beautiful Code, Chapter 3.
2
+ # Produces the expected runtime of Quicksort, for every integer from 1 to N.
3
+
4
+ runtime = (N) ->
5
+ [sum, t] = [0, 0]
6
+ for n in [1..N]
7
+ sum += 2 * t
8
+ t = n - 1 + sum / n
9
+ t
10
+
11
+ console.log runtime(3) is 2.6666666666666665
12
+ console.log runtime(5) is 7.4
13
+ console.log runtime(8) is 16.92142857142857
@@ -0,0 +1,34 @@
1
+ # Beautiful Code, Chapter 1.
2
+ # Implements a regular expression matcher that supports character matches,
3
+ # '.', '^', '$', and '*'.
4
+
5
+ # Search for the regexp anywhere in the text.
6
+ match = (regexp, text) ->
7
+ return match_here(regexp.slice(1), text) if regexp[0] is '^'
8
+ while text
9
+ return true if match_here(regexp, text)
10
+ text = text.slice(1)
11
+ false
12
+
13
+ # Search for the regexp at the beginning of the text.
14
+ match_here = (regexp, text) ->
15
+ [cur, next] = [regexp[0], regexp[1]]
16
+ if regexp.length is 0 then return true
17
+ if next is '*' then return match_star(cur, regexp.slice(2), text)
18
+ if cur is '$' and not next then return text.length is 0
19
+ if text and (cur is '.' or cur is text[0]) then return match_here(regexp.slice(1), text.slice(1))
20
+ false
21
+
22
+ # Search for a kleene star match at the beginning of the text.
23
+ match_star = (c, regexp, text) ->
24
+ loop
25
+ return true if match_here(regexp, text)
26
+ return false unless text and (text[0] is c or c is '.')
27
+ text = text.slice(1)
28
+
29
+ console.log match("ex", "some text")
30
+ console.log match("s..t", "spit")
31
+ console.log match("^..t", "buttercup")
32
+ console.log match("i..$", "cherries")
33
+ console.log match("o*m", "vrooooommm!")
34
+ console.log match("^hel*o$", "hellllllo")
@@ -0,0 +1,54 @@
1
+ # After wycats' http://yehudakatz.com/2010/02/07/the-building-blocks-of-ruby/
2
+
3
+ # Sinatra.
4
+ get '/hello', ->
5
+ 'Hello World'
6
+
7
+
8
+ # Append.
9
+ append = (location, data) ->
10
+ path = new Pathname location
11
+ throw new Error("Location does not exist") unless path.exists()
12
+
13
+ File.open path, 'a', (file) ->
14
+ file.console.log YAML.dump data
15
+
16
+ data
17
+
18
+
19
+ # Rubinius' File.open implementation.
20
+ File.open = (path, mode, block) ->
21
+ io = new File path, mode
22
+
23
+ return io unless block
24
+
25
+ try
26
+ block io
27
+ finally
28
+ io.close() unless io.closed()
29
+
30
+
31
+ # Write.
32
+ write = (location, data) ->
33
+ path = new Pathname location
34
+ raise "Location does not exist" unless path.exists()
35
+
36
+ File.open path, 'w', (file) ->
37
+ return false if Digest.MD5.hexdigest(file.read()) is data.hash()
38
+ file.console.log YAML.dump data
39
+ true
40
+
41
+
42
+ # Rails' respond_to.
43
+ index = ->
44
+ people = Person.find 'all'
45
+
46
+ respond_to (format) ->
47
+ format.html()
48
+ format.xml -> render xml: people.xml()
49
+
50
+
51
+ # Synchronization.
52
+ synchronize = (block) ->
53
+ lock()
54
+ try block() finally unlock()
@@ -0,0 +1,167 @@
1
+ # Functions:
2
+ square = (x) -> x * x
3
+
4
+ sum = (x, y) -> x + y
5
+
6
+ odd = (x) -> x % 2 isnt 0
7
+
8
+ even = (x) -> x % 2 is 0
9
+
10
+ run_loop = ->
11
+ fire_events((e) -> e.stopPropagation())
12
+ listen()
13
+ wait()
14
+
15
+ # Objects:
16
+ dense_object_literal = {one: 1, two: 2, three: 3}
17
+
18
+ spaced_out_multiline_object =
19
+ pi: 3.14159
20
+ list: [1, 2, 3, 4]
21
+ regex: /match[ing](every|thing|\/)/gi
22
+ three: new Idea
23
+
24
+ inner_obj:
25
+ freedom: -> _.freedom()
26
+
27
+ # Arrays:
28
+ stooges = [{moe: 45}, {curly: 43}, {larry: 46}]
29
+
30
+ exponents = [((x) -> x), ((x) -> x * x), ((x) -> x * x * x)]
31
+
32
+ empty = []
33
+
34
+ multiline = [
35
+ 'line one'
36
+ 'line two'
37
+ ]
38
+
39
+ # Conditionals and ternaries.
40
+ if submarine.shields_up
41
+ full_speed_ahead()
42
+ fire_torpedos()
43
+ else if submarine.sinking
44
+ abandon_ship()
45
+ else
46
+ run_away()
47
+
48
+ eldest = if 25 > 21 then liz else marge
49
+
50
+ decoration = medal_of_honor if war_hero
51
+
52
+ go_to_sleep() unless coffee
53
+
54
+ # Returning early:
55
+ race = ->
56
+ run()
57
+ walk()
58
+ crawl()
59
+ if tired then return sleep()
60
+ race()
61
+
62
+ # Conditional assignment:
63
+ good or= evil
64
+ wine and= cheese
65
+
66
+ # Nested property access and calls.
67
+ ((moon.turn(360))).shapes[3].move({x: 45, y: 30}).position['top'].offset('x')
68
+
69
+ a = b = c = 5
70
+
71
+ # Embedded JavaScript.
72
+ callback(
73
+ `function(e) { e.stop(); }`
74
+ )
75
+
76
+ # Try/Catch/Finally/Throw.
77
+ try
78
+ all_hell_breaks_loose()
79
+ dogs_and_cats_living_together()
80
+ throw "up"
81
+ catch error
82
+ print(error)
83
+ finally
84
+ clean_up()
85
+
86
+ try all_hell_breaks_loose() catch error then print(error) finally clean_up()
87
+
88
+ # While loops, break and continue.
89
+ while demand > supply
90
+ sell()
91
+ restock()
92
+
93
+ while supply > demand then buy()
94
+
95
+ loop
96
+ break if broken
97
+ continue if continuing
98
+
99
+ # Unary operators.
100
+ !!true
101
+
102
+ # Lexical scoping.
103
+ v_1 = 5
104
+ change_a_and_set_b = ->
105
+ v_1 = 10
106
+ v_2 = 15
107
+ v_2 = 20
108
+
109
+ # Array comprehensions.
110
+ supper = food.capitalize() for food in ['toast', 'cheese', 'wine']
111
+
112
+ drink bottle for bottle, i in ['soda', 'wine', 'lemonade'] when even i
113
+
114
+ # Switch statements ("else" serves as a default).
115
+ activity = switch day
116
+ when "Tuesday" then eat_breakfast()
117
+ when "Sunday" then go_to_church()
118
+ when "Saturday" then go_to_the_park()
119
+ when "Wednesday"
120
+ if day is bingo_day
121
+ go_to_bingo()
122
+ else
123
+ eat_breakfast()
124
+ go_to_work()
125
+ eat_dinner()
126
+ else go_to_work()
127
+
128
+ # Semicolons can optionally be used instead of newlines.
129
+ wednesday = -> eat_breakfast(); go_to_work(); eat_dinner()
130
+
131
+ # Multiline strings with inner quotes.
132
+ story = "Lorem ipsum dolor \"sit\" amet, consectetuer adipiscing elit,
133
+ sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna
134
+ aliquam erat volutpat. Ut wisi enim ad."
135
+
136
+ # Inheritance and calling super.
137
+ class Animal
138
+ (@name) ->
139
+
140
+ move: (meters) ->
141
+ alert this.name + " moved " + meters + "m."
142
+
143
+ class Snake extends Animal
144
+ move: ->
145
+ alert 'Slithering...'
146
+ super 5
147
+
148
+ class Horse extends Animal
149
+ move: ->
150
+ alert 'Galloping...'
151
+ super 45
152
+
153
+ sam = new Snake "Sammy the Snake"
154
+ tom = new Horse "Tommy the Horse"
155
+
156
+ sam.move()
157
+ tom.move()
158
+
159
+ # Numbers.
160
+ a_googol = 1e100
161
+ hex = 0xff0000
162
+ negative = -1.0
163
+ infinity = Infinity
164
+ nan = NaN
165
+
166
+ # Deleting.
167
+ delete secret.identity
@@ -0,0 +1,4 @@
1
+ Ported from Nicholas Zakas' collection of computer science fundamentals, written
2
+ in JavaScript. Originals available here:
3
+
4
+ http://github.com/nzakas/computer-science-in-javascript
@@ -0,0 +1,25 @@
1
+ # Uses a binary search algorithm to locate a value in the specified array.
2
+ binary_search = (items, value) ->
3
+
4
+ start = 0
5
+ stop = items.length - 1
6
+ pivot = Math.floor (start + stop) / 2
7
+
8
+ while items[pivot] isnt value and start < stop
9
+
10
+ # Adjust the search area.
11
+ stop = pivot - 1 if value < items[pivot]
12
+ start = pivot + 1 if value > items[pivot]
13
+
14
+ # Recalculate the pivot.
15
+ pivot = Math.floor (stop + start) / 2
16
+
17
+ # Make sure we've found the correct value.
18
+ if items[pivot] is value then pivot else -1
19
+
20
+
21
+ # Test the function.
22
+ console.log 2 is binary_search [10, 20, 30, 40, 50], 30
23
+ console.log 4 is binary_search [-97, 35, 67, 88, 1200], 1200
24
+ console.log 0 is binary_search [0, 45, 70], 0
25
+ console.log(-1 is binary_search [0, 45, 70], 10)
@@ -0,0 +1,11 @@
1
+ # A bubble sort implementation, sorting the given array in-place.
2
+ bubble_sort = (list) ->
3
+ for i in [0...list.length]
4
+ for j in [0...list.length - i]
5
+ [list[j], list[j+1]] = [list[j+1], list[j]] if list[j] > list[j+1]
6
+ list
7
+
8
+
9
+ # Test the function.
10
+ console.log bubble_sort([3, 2, 1]).join(' ') is '1 2 3'
11
+ console.log bubble_sort([9, 2, 7, 0, 1]).join(' ') is '0 1 2 7 9'
@@ -0,0 +1,108 @@
1
+ # "Classic" linked list implementation that doesn't keep track of its size.
2
+ class LinkedList
3
+
4
+ ->
5
+ this._head = null # Pointer to the first item in the list.
6
+
7
+
8
+ # Appends some data to the end of the list. This method traverses the existing
9
+ # list and places the value at the end in a new node.
10
+ add: (data) ->
11
+
12
+ # Create a new node object to wrap the data.
13
+ node = data: data, next: null
14
+
15
+ current = this._head or= node
16
+
17
+ if this._head isnt node
18
+ (current = current.next) while current.next
19
+ current.next = node
20
+
21
+ this
22
+
23
+
24
+ # Retrieves the data at the given position in the list.
25
+ item: (index) ->
26
+
27
+ # Check for out-of-bounds values.
28
+ return null if index < 0
29
+
30
+ current = this._head or null
31
+ i = -1
32
+
33
+ # Advance through the list.
34
+ (current = current.next) while current and index > (i += 1)
35
+
36
+ # Return null if we've reached the end.
37
+ current and current.data
38
+
39
+
40
+ # Remove the item from the given location in the list.
41
+ remove: (index) ->
42
+
43
+ # Check for out-of-bounds values.
44
+ return null if index < 0
45
+
46
+ current = this._head or null
47
+ i = -1
48
+
49
+ # Special case: removing the first item.
50
+ if index is 0
51
+ this._head = current.next
52
+ else
53
+
54
+ # Find the right location.
55
+ ([previous, current] = [current, current.next]) while index > (i += 1)
56
+
57
+ # Skip over the item to remove.
58
+ previous.next = current.next
59
+
60
+ # Return the value.
61
+ current and current.data
62
+
63
+
64
+ # Calculate the number of items in the list.
65
+ size: ->
66
+ current = this._head
67
+ count = 0
68
+
69
+ while current
70
+ count += 1
71
+ current = current.next
72
+
73
+ count
74
+
75
+
76
+ # Convert the list into an array.
77
+ toArray: ->
78
+ result = []
79
+ current = this._head
80
+
81
+ while current
82
+ result.push current.data
83
+ current = current.next
84
+
85
+ result
86
+
87
+
88
+ # The string representation of the linked list.
89
+ toString: -> this.toArray().toString()
90
+
91
+
92
+ # Tests.
93
+ list = new LinkedList
94
+
95
+ list.add("Hi")
96
+ console.log list.size() is 1
97
+ console.log list.item(0) is "Hi"
98
+ console.log list.item(1) is null
99
+
100
+ list = new LinkedList
101
+ list.add("zero").add("one").add("two")
102
+ console.log list.size() is 3
103
+ console.log list.item(2) is "two"
104
+ console.log list.remove(1) is "one"
105
+ console.log list.item(0) is "zero"
106
+ console.log list.item(1) is "two"
107
+ console.log list.size() is 2
108
+ console.log list.item(-10) is null
@@ -0,0 +1,36 @@
1
+ # Use the Luhn algorithm to validate a numeric identifier, such as credit card
2
+ # numbers, national insurance numbers, etc.
3
+ # See: http://en.wikipedia.org/wiki/Luhn_algorithm
4
+
5
+ is_valid_identifier = (identifier) ->
6
+
7
+ sum = 0
8
+ alt = false
9
+
10
+ for i in [identifier.length - 1..0] by -1
11
+
12
+ # Get the next digit.
13
+ num = parseInt identifier.charAt(i), 10
14
+
15
+ # If it's not a valid number, abort.
16
+ return false if isNaN(num)
17
+
18
+ # If it's an alternate number...
19
+ if alt
20
+ num *= 2
21
+ num = (num % 10) + 1 if num > 9
22
+
23
+ # Flip the alternate bit.
24
+ alt = !alt
25
+
26
+ # Add to the rest of the sum.
27
+ sum += num
28
+
29
+ # Determine if it's valid.
30
+ sum % 10 is 0
31
+
32
+
33
+ # Tests.
34
+ console.log is_valid_identifier("49927398716") is true
35
+ console.log is_valid_identifier("4408041234567893") is true
36
+ console.log is_valid_identifier("4408041234567890") is false