Skip to content

Instantly share code, notes, and snippets.

View syntacticsugar's full-sized avatar
🎯
Focusing

RomyRomy syntacticsugar

🎯
Focusing
View GitHub Profile
@syntacticsugar
syntacticsugar / smoking_lisp_through_ruby.rb
Created October 20, 2012 22:52
wherein i lose my shit and go to town playing with Rubified `car`/`cdr`
Death-Lair-of-Killer-Bambi:Desktop stickycake$ irb
cannot load such file -- irb/autocompletion
1.9.3-p194 :001 > boys = %w{jarry larry parry gary}
=> ["jarry", "larry", "parry", "gary"]
1.9.3-p194 :002 > boys.is_a(Array)
NoMethodError: undefined method `is_a' for ["jarry", "larry", "parry", "gary"]:Array
from (irb):2
from /Users/stickycake/.rvm/rubies/ruby-1.9.3-p194/bin/irb:16:in `<main>'
1.9.3-p194 :003 > boys.is_a?(Array)
=> true
@syntacticsugar
syntacticsugar / strong_fail.clj
Created October 22, 2012 06:36
error message from misaki server
Caused by java.lang.RuntimeException: Unable to resolve symbol: necessarily in this context
at misaki.compiler.default.evaluator$evaluate_to_function$fn__139 / invoke (evaluator.clj:62)
at misaki.compiler.default.evaluator$evaluate_to_function / invoke (evaluator.clj:62)
at misaki.compiler.default.template$load_template$fn__247 / invoke (template.clj:82)
at misaki.compiler.default.template$load_template / invoke (template.clj:89)
at misaki.compiler.default.core$file__GT_template_sexp / doInvoke (core.clj:193)
at misaki.compiler.default.core$generate_post_content / invoke (core.clj:95)
at misaki.compiler.default.core$get_post_info$fn__2230 / invoke (core.clj:108)
at misaki.compiler.default.core$get_compile_fn$fn__2277 / invoke (core.clj:221)
at misaki.compiler.default.core$compile_STAR_ / invoke (core.clj:229)
@syntacticsugar
syntacticsugar / david_albert_is_awesome_factorial.rb
Created October 22, 2012 21:02
Ruby Or-Equals ||= weirdness
@factorial_results = {}
def factorial(num)
start = Time.now
raise "num has to be greater than 0" if num < 0
return 1 if num == 0
if @factorial_results.has_key?(num)
puts "found it!"
@syntacticsugar
syntacticsugar / gist:3936358
Created October 23, 2012 02:39 — forked from lfborjas/gist:817504
Filter even numbers in a list; fork it for maximum fun!
#these are meant to be run in a REPL, and the java one in beanshell of something of the sort:
#ruby
[1,2,3,4].select{ |x| x.even? }
#python
[x for x in [1,2,3,4] if not x%2]
#or, more norvingly
filter(lambda x: not x%2, [1,2,3,4])
#clojure
@syntacticsugar
syntacticsugar / cat.js
Created November 7, 2012 00:55 — forked from lfborjas/cat.js
kittehs
sys = require("child_process");
var Cat = function( name ){
this.name = name;
};
Cat.prototype.meow = function(){
sys.exec('say "' + this.name + ' says MEEEEOOOOOOOOOWOWOWOW"');
};
@syntacticsugar
syntacticsugar / gist:4041425
Created November 8, 2012 20:37 — forked from nicholasbs/gist:3259846
Implementing the "new" operator in JavaScript
// New is a function that takes a function F
function New (F) {
var o = {}; // and creates a new object o
o.__proto__ = F.prototype // and sets o.__proto__ to be F's prototype
// New returns a function that...
return function () {
F.apply(o, arguments); // runs F with o as "this", passing along any arguments
return o; // and returns o, the new object we created
}
@syntacticsugar
syntacticsugar / curly_braces_do_end_ruby.md
Created November 20, 2012 19:06
Ruby: {} versus 'do/end' syntax

Curly braces vs. do/end in code block syntax

The difference between the two ways of delimiting a code block is a difference in pre- cedence. Look at this example, and you’ll start to see how this plays out:

array = [1,2,3]
  => [1,2,3]
array.map {|n| n * 10 }
  => [10, 20, 30]
array.map do |n| n * 10 end
  => [10, 20, 30]
puts array.map {|n| n * 10 }
countZeroes :: [String] -> Int
countZeroes = sum . map length . map (filter (=='0'))
countZeroesAgain :: Show a => [a] -> Int
countZeroesAgain = countZeroes . map show
-- and for the one line, because I guess that's the challenge
-- btw, it's type is
-- cz :: Show a => [a] -> Int
-- which means that this function works any list of things that can be printed
@syntacticsugar
syntacticsugar / korean_woman_in_a_shop.markdown
Created November 26, 2012 05:33
korean woman in a shop

Well, I've certainly been on the lookout for leggings.

I told myself this as I entered the small clothing shop on 14th St. It was a Saturday afternoon in Union Square when I spotted the rack of navy, brown, and black. '$3.99' was scrawled in cardboard. I chose a pair in black and headed toward the register to pay.

The second I stepped inside I heard her voice. An older Asian woman, perhaps in her fifties, held a phone to her face and manned the register in the back. She spoke in loud and brusque Korean, sans affectation. I imagined she was talking to her sister on a different continent. Or an old friend.

Or a daughter.

As I brought the pair of leggings up to the counter her voice lowered slightly in acknowledgement. Polite, I noted. She held up four fingers. I reached for my wallet, and waited for the questions that would inevitably follow.

<?php
/**
* Higher order functions in PHP
*
* Please let me know of any differences in the the uses and actual definitions of partial v. curry.
*/
/**
* Returns a partially applied function.