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
// transliterate (Char a) :: [a] -> [a] -> [a] -> [a] | |
var transliterate = function(from, to) { | |
var approximations = {}; | |
for (var i = 0, len = from.length; i < len; ++i) { | |
approximations[from.charAt(i)] = to.charAt(i); | |
} | |
return function(input) { | |
return input.replace(/[^\x00-\x7f]/g, function(char) { |
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
var person = { name: "John" }; | |
window.name = "Paul"; | |
mediator.on("call-people", function() { | |
console.log(this.name); // print "Paul" | |
}); | |
mediator.on("call-people", function() { | |
console.log(this.name); // print "John" |
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
(def check-sum | |
(fn [sequence] | |
(apply + (map (fn [position digit] | |
(* digit (if (odd? position) 1 3))) | |
(range 1 (inc (count sequence))) | |
sequence)))) | |
(defn check-sum-upc [coll] | |
(apply + (map * | |
(take (count coll) (cycle '(1 3))) |
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
(defn add-first-uniq [target coll] | |
(cond (not (contains? target (first coll))) | |
(conj target (first coll)) | |
:else | |
(add-first-uniq target (rest coll)))) | |
(reduce add-first-uniq | |
#{} | |
'((1 2 3) (1 2) (4 5))) |
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
; might not be the proper way to do it, but it is how I was able to run repl with some libraries | |
; in this case I created a lein project, add the monad dependency to the project, and then started | |
; a repl session, and run: | |
; | |
; need to include pomegranate | |
; | |
; it seems to be the best way to deal with it | |
; | |
(use '[cemerick.pomegranate :only (add-dependencies)]) | |
(add-dependencies :coordinates '[[org.clojure/algo.monads "0.1.4"]]) |
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
<style> | |
.yui3-overlay-hidden { | |
visibility: hidden; | |
} | |
</style> | |
<input type="text" id="input-date" /> | |
<div id="calendar-overlay"> | |
<div class="yui3-widget-bd" id="calendar"></div> |
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
# Since Mongoid switched to its own driver, many of the mongo API | |
# (available in mongo-ruby-drive) are missing. This is allows you | |
# to rename a collection thru command message. | |
# | |
# Be aware that the API constantly changes in mongoid | |
# | |
# Mongoid (3.1.0), Moped (1.4.2) | |
class MyModel | |
include Mongoid::Document |
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 "https://rubygems.org" | |
gem "mongo", "~> 1.8.2" | |
gem "bson_ext", "~> 1.8.2" | |
gem "actionpack", "~> 3.2.12" |
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
#!/bin/bash | |
# This is the 'mover' script used for moving files from the cache disk to the | |
# main array. It is typically invoked via cron. | |
# After checking if it's valid for this script to run, we check each of the top-level | |
# directories (shares) on the cache disk. If, and only if, the 'Use Cache' setting for the | |
# share is set to "yes", we use 'find' to process the objects (files and directories) of | |
# that directory, moving them to the array. |
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
require 'pp' | |
require 'benchmark' | |
# compute all possible expressions to the given string of digits to a given set of operations. | |
# the digits are kept in order | |
# | |
# ex. 1234 | |
# generates: 1234, 1+234, 1-234, 12+34, 123-4... | |
# | |
# but selects only expressions that evaluate to a given value |