Skip to content

Instantly share code, notes, and snippets.

View sjl's full-sized avatar

Steve Losh sjl

View GitHub Profile
(defn personality-stddev
[faved mehed hated mean]
(let [points (concat (take faved (cycle [1]))
(take mehed (cycle [0.5]))
(take hated (cycle [0])))
squared (map #(expt (- % mean) 2) points)]
(sqrt (/ (apply + squared) (count squared)))))
(defn personality
[faved mehed hated]
(let [score (personality-score faved mehed hated)]
{ :score score
:stddev (personality-stddev faved mehed hated score)
:total (+ faved mehed hated) }))
(let [faved (brains.db/user-site-faved-count uid)
mehed (brains.db/user-mehed-count uid)
hated (brains.db/user-hated-count uid)] ...)
(defn personality-score
[faved mehed hated]
(/ (+ faved (* mehed 0.5)) (+ faved mehed hated)))
{ :score AVERAGE-RATING
:stddev STANDARD-DEVIATION
:total TOTAL-RATINGS }
(defn db-personality-user
[uid]
(let [faved (brains.db/user-site-faved-count uid)
mehed (brains.db/user-mehed-count uid)
hated (brains.db/user-hated-count uid)]
(assoc (personality faved mehed hated)
:uid uid)))
(defn db-personality-users
[]
@sjl
sjl / correct_shift_keys.xml
Created April 8, 2011 14:36
A snippet for KeyRemap4MacBook that will teach you to use the correct shift keys.
<list>
<item>
<name>Use the correct goddamed shift keys.</name>
<identifier>private.fucking_shift_keys_how_do_they_work</identifier>
<autogen>--KeyToKey-- KeyCode::Q, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
<autogen>--KeyToKey-- KeyCode::W, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
<autogen>--KeyToKey-- KeyCode::E, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
<autogen>--KeyToKey-- KeyCode::R, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
<autogen>--KeyToKey-- KeyCode::T, ModifierFlag::SHIFT_L, KeyCode::VK_NONE</autogen>
\sR - Open a REPL
\et - Eval current toplevel form
\ef - Eval current file
\lw - Look up documentation for current word
C-X C-O - Autocomplete current word smartly
Firefox
|
V
OS X Laptop port 4565 on OS X Linux VM
Nginx on port 80 -------> is forwarded to 80 on ------> Nginx on port 80
the VM |
V
Gunicorn server
import sys, os
old_file = sys.argv[1].rsplit('.', 2)[0]
if os.path.exists(old_file):
os.system('osascript -e \'tell app "Finder" '
+ 'to move the POSIX file "'
+ os.path.abspath(old_file) + '" to trash\'')