This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__all__ = ( | |
'build', | |
'endode', | |
'decode', | |
) | |
phrase = 'A man a plan a canal Panama'.lower() | |
def build(phrase): | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source :rubygems | |
gem 'sinatra' | |
gem 'json' | |
gem 'omniauth' | |
gem 'omniauth-oauth2' | |
gem 'omniauth-github' | |
# gem 'omniauth-att', :path => File.expand_path("./../../omniauth-att", __FILE__) | |
gem 'thin' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
require 'sinatra' | |
require 'slim' | |
require 'warden' | |
require 'dm-core' | |
require 'dm-migrations' | |
DataMapper::Logger.new(STDOUT, :debug) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sys = require("child_process"); | |
var Cat = function( name ){ | |
this.name = name; | |
}; | |
Cat.prototype.meow = function(){ | |
sys.exec('say "' + this.name + ' says MEEEEOOOOOOOOOWOWOWOW"'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def insert_every!(skip, str) | |
orig_ary_length = self.length | |
new_ary_length = orig_ary_length + ((orig_ary_length-1) / skip) | |
i = skip | |
while(i<new_ary_length) do self.insert(i,str); i+=(skip+1) end | |
self | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Euclid's formula yields Pythagorean triples for integers m and n with m < n: | |
# a = m**2 - n**2 ; b = 2*m*n ; c = m**2 + n**2 | |
x = 1000 | |
def euclids upto | |
result = [] | |
(2..upto).each do |m| # Start at 2 as 1 results nothing anyway | |
(1...m).each do |n| # Euclid's formula only works for m > n | |
result << [m**2 - n**2, 2*m*n, m**2 + n**2] |
OlderNewer