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
;; vanilla version | |
(defn make-lock [] | |
(atom nil)) | |
(defn has-lock? [lock id] | |
(= id @lock)) | |
(defn set-lock! [lock id new-id] | |
(let [lock-id @lock] |
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 debounce [func wait immediate] | |
(let [timeout (atom nil)] | |
(fn [] | |
(this-as this | |
(let [context this | |
args js/arguments | |
later (fn [] | |
(reset! timeout nil) | |
(when-not immediate | |
(.apply func context args)))] |
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
(ns rxjs.client.core | |
(:use [jayq.core :only [$ on off document-ready]] | |
[jayq.util :only [log]])) | |
(defn on-as-observable [$elem events & [sel data]] | |
(js/Rx.Observable.create | |
(fn [observer] | |
(let [handler (fn [evt-object] | |
(.onNext observer evt-object))] | |
(on $elem events sel data handler) |
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
(ns oauth.digest | |
(:import (javax.crypto Mac) | |
(javax.crypto.spec SecretKeySpec))) | |
(defn hmac | |
"Calculate HMAC signature for given data." | |
[^String key ^String data] | |
(let [hmac-sha1 "HmacSHA1" | |
signing-key (SecretKeySpec. (.getBytes key) hmac-sha1) | |
mac (doto (Mac/getInstance hmac-sha1) (.init signing-key))] |
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
tell application "Google Chrome" | |
activate | |
tell application "System Events" | |
tell process "Google Chrome" | |
keystroke "r" using {command down, shift down} | |
end tell | |
end tell | |
end tell | |
-- Save that in a text file somewhere and run it from terminal with: |
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/sh | |
exec <"$0" || exit; read v; read v; exec /usr/bin/osascript - "$@"; exit | |
-- the above is some shell trickery that lets us write the rest of | |
-- the file in plain applescript | |
tell application "Google Chrome" | |
activate | |
tell application "System Events" | |
tell process "Google Chrome" |
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
{-# LANGUAGE OverloadedStrings #-} | |
import qualified Data.Aeson as A | |
import qualified Data.Aeson.Types as AT | |
import qualified Data.Bson as B | |
import qualified Data.Attoparsec as AP | |
import qualified Data.Attoparsec.Number as APN | |
import qualified Data.Vector as V | |
import qualified Data.HashMap.Strict as M | |
import qualified Data.ByteString as BS |
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
import Data.List (inits, tails, sortBy) | |
import Data.Ord (comparing) | |
type Result = ([Int], Int) | |
cSum :: [Int] -> [Result] | |
cSum = reverse . sortBy (comparing snd) . map result . cSubs | |
where | |
result xs = (xs, sum xs) | |
cSubs = concatMap (tail . inits) . tails |
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
import Data.Binary.Put (runPut) | |
import Data.Binary.Get (runGet) | |
import Data.Binary.Bits.Put | |
import Data.Binary.Bits.Get | |
-- helper function to create a bytestring from a list of [Int] | |
toByteString = runPut . runBitPut . mapM_ (putBool . toBool) | |
where | |
toBool n = n /= 0 || False | |
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
import Data.List | |
check = filter (and . sequence conditions) | |
where | |
conditions = map divsBy $ reverse [2..9] | |
divsBy x = (== 0) . (`rem` x) . fromDigits . take x | |
fromDigits = foldl' ((+) . (10 *)) 0 | |
solutions = check $ permutations [1..9] |