# Ruby
# v1
->(x, s) { s.tr (0..25).map { |n| [(n+65).chr, (n+97).chr] }.flatten.join, (0..25).map { |n| [((n+x)%26+65).chr, ((n+x)%26+97).chr] }.flatten.join }
# v2
->(x, s) { (->(a) { s.tr a.join, (a*2).drop((x%26)*2).take(52).join })[(0..25).map{|n| [(n+65).chr, (n+97).chr]}.flatten] }
This file contains hidden or 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
#!/usr/bin/env python | |
import sqlite3 | |
SQL_EAV_TABLE = """ | |
CREATE TABLE IF NOT EXISTS eav ( | |
entity TEXT NOT NULL, | |
attr TEXT NOT NULL, | |
value BLOB, |
This file contains hidden or 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
var exists = function(x) { return x != null; }; | |
var truthy = function(x) { | |
return (x !== false) && exists(x); | |
}; | |
var _filter = function(fun) { | |
return function(coll) { | |
var results = []; | |
if (coll == null) return results; |
This file contains hidden or 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
(defn crypt-range [low high] | |
(let [chars (map char (range low high))] | |
(zipmap chars (shuffle chars)))) | |
(defn make-crypto [] | |
(let [ranges [[97 123] [65 91] [48 58]]] | |
(apply merge (map #(apply crypt-range %) ranges)))) | |
(defn encrypt [crypto s] | |
"Encrypt string with crypto map" |
This file contains hidden or 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
#!/usr/bin/env python | |
from operator import itemgetter | |
## ELAPSED DEVELOPMENT TIME: ~45m ## | |
## Helper Functions ## | |
def juxt(*fns): | |
def _juxter(arg): | |
return [fn(arg) for fn in fns] |
This file contains hidden or 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
#!/usr/bin/python | |
import time | |
def fib(n): | |
if n < 2: return n | |
else: return fib(n - 1) + fib(n - 2) | |
def fast_fib(n, a, b): | |
if n == 0: return a |
This file contains hidden or 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
import os.path | |
import lxml.html | |
SPRING_URL = "http://docs.spring.io/spring/docs/3.2.x/javadoc-api/overview-tree.html" | |
SWING_URL = "http://www.cs.rit.edu/usr/local/pub/swm/jdoc6/overview-tree.html" | |
concat = lambda l: [e for v in l for e in v] | |
def longest(url): | |
files = [os.path.basename(f[2]) for f in lxml.html.parse(url).getroot().iterlinks()] | |
print '\n'.join(sorted(concat([f.split(".")[:-1] for f in files]), key=len, reverse=True)[:10]) |
This file contains hidden or 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
package forcomp | |
import common._ | |
object Phonenumber { | |
val dictionary = loadDictionary | |
val keyMap = Map( | |
'2' -> "ABC", '3' -> "DEF", '4' -> "GHI", '5' -> "JKL", | |
'6' -> "MNO", '7' -> "PQRS", '8' -> "TUV", '9' -> "WXYZ" | |
) |
This file contains hidden or 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
user=> (source letfn) | |
(defmacro letfn | |
"fnspec ==> (fname [params*] exprs) or (fname ([params*] exprs)+) | |
Takes a vector of function specs and a body, and generates a set of | |
bindings of functions to their names. All of the names are available | |
in all of the definitions of the functions, as well as the body." | |
{:added "1.0", :forms '[(letfn [fnspecs*] exprs*)], | |
:special-form true, :url nil} | |
[fnspecs & body] |
This file contains hidden or 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
#!/usr/bin/env python | |
import re | |
def powerset(l): | |
def _reducer(acc, e): | |
return acc + [x + [e] for x in acc] | |
return sorted(reduce(_reducer, l, [[]]), key=len) | |
def words(s): |