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
curl -v http://www.nytimes.com | |
> GET / HTTP/1.1 | |
> User-Agent: curl/7.19.7 (universal-apple-darwin10.0) libcurl/7.19.7 OpenSSL/0.9.8l zlib/1.2.3 | |
> Host: www.nytimes.com | |
> Accept: */* | |
< Server: Sun-ONE-Web-Server/6.1 | |
< Date: Fri, 29 Apr 2011 20:25:26 GMT | |
< Content-type: text/html; charset=UTF-8 | |
< Expires: Thu, 01 Dec 1994 16:00:00 GMT |
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
# shorten a URL | |
# curl -X POST --data "url=http://livingsocial.com" localhost:9292 | |
# | |
# --> returns the shortened url in the body | |
# | |
# to retrieve a shortened URL | |
# open http://localhost:9292/a723bae | |
# | |
require 'rubygems' |
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
def dictionary | |
lambda {|x| nil } | |
end | |
def add(key, value, dictionary) | |
lambda do |x| | |
key == x ? value : dictionary.call(x) | |
end | |
end |
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 new-dict | |
[x] | |
'nil) | |
(defn add-to-dict | |
[dict key val] | |
#(if (= key %) val (dict %))) | |
(def mydict (add-to-dict (add-to-dict new-dict "b" 42) "a" 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
require 'redis' | |
# | |
# The drawback with this approach is old members are deleted as you add new, creates a bit of overhead. | |
# The whole set expires, using normal redis expiration, if you don't add anything until the last member was added | |
# | |
class ExpiringSortedSet | |
attr_reader :key | |
def initialize(args) |
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
; solution to http://www.4clojure.com/problem/177 | |
(defn balanced? | |
[x] | |
(let [tokens (vec (clojure.string/replace x #"[^\(\)\[\]\{\}]" "")) | |
brackets { \{ \} \( \) \[ \]} | |
starting-bracket? (fn [x] (brackets x)) | |
matching-bracket? (fn [a b] (= (brackets a) b))] | |
(loop [stack '() | |
[curr & more] tokens] |
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
; given {1 [:a :b :c] 2 [:b :c :d]} | |
; flip the keys like so | |
; {:a [1] :b [1 2] :c [1 2] :d [2] | |
(defn explode-keys-to-map | |
"take [a b c] 1, return {a [1] b [1] c [1]}" | |
[m ks v] | |
(let [add-val-to-seq (fn [m k v] | |
(if (m k) | |
(assoc m k (conj (m k) v)) |
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
javascript:(function() { | |
var puppyBasket = { | |
square: [ | |
"http://fc04.deviantart.net/fs48/i/2012/019/e/b/husky_puppy_2151_by_sooper_husky-d28f7yz.jpg", | |
"http://www.rollingmeadowspuppies.com/images/Rose_poochon_male_Rm2_3_2.JPG", | |
"http://us.123rf.com/400wm/400/400/isselee/isselee0803/isselee080300569/2776137-yorkshire-terrier-puppies-1-month-in-front-of-a-white-background.jpg", | |
"http://media.bureauoftrade.com/p/2013/09/29/apollo-labrador-retriever-puppy-400c.jpg", | |
"http://helenwoodwardanimalcenter.files.wordpress.com/2012/04/snowcone-headshot.jpg%3Fw%3D400", | |
"http://imagecache6.allposters.com/LRG/61/6167/9LTG100Z.jpg", | |
"http://thumbs.dreamstime.com/x/german-shepherd-puppies-448837.jpg", |
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
;; With these plates | |
(def available-plates [45 25 15 10 5 2.5 1.25]) | |
;; Create a function that loads a barbell (weighs 45). | |
;; With the available plates as close to the goal weight as possible. | |
;; Assume you have unlimited supply of each plate. | |
;; Weight has to be evenly distributed on each side. | |
;; Use as few plates as possible. | |
;; Example: 45 pound bar bell with 152.5 pounds goal weight |
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 commas-foul [n] | |
(->> n | |
.toString | |
reverse | |
(partition-all 3) | |
(interpose ",") | |
flatten | |
reverse | |
(apply str))) |