Skip to content

Instantly share code, notes, and snippets.

Steve Losh sjl

Block or report user

Report or block sjl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
sjl / which is best? .py
Created Nov 16, 2009 — forked from inky/which is best? .py
They're completely different.
View which is best? .py
>>> x = '0123456789'
>>> a, b = [{} for _ in x], [{}] * len(x)
>>> a[0]['test'], b[0]['test'] = 1, 1
>>> p(a)
[{'test': 1}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
>>> p(b)
View git vs mercurial
# Discard local changes
git checkout -f (git co -f)
# This will change the current parent revision if you're not at a branch tip.
# The fact that it discards local changes is just a side effect.
hg update --clean (hg co -C)
# What you really want is the command *designed* to throw away changes: revert.
hg revert --all [--no-backup] (hg rev -a)
sjl /
Created Apr 29, 2010 — forked from bobthecow/cdg.bash
A function to cd to the root of the current Mercurial repository.
#!/usr/bin/env bash
# cd to the root of the current Mercurial repo
# usage:
# Add the following function to your `.bashrc` or `.bash_profile` file,
# or save it somewhere (i.e. `~/`) and source it in `.bashrc`
cdh () {
hg root >/dev/null && cd "`hg root`"
# Plant rope vim's plugin
# This is a script to install or update 'ropevim'
# Copyright Alexander Artemenko, 2008
# Contact me at svetlyak.40wt at gmail com
function create_dirs
mkdir -p src
sjl /
Created Nov 1, 2010
A command-line client for A Feed Apart
import json, time, urllib
n = 0
while 1:
resp = json.load(urllib.urlopen('' % n))
except ValueError:
sjl / google-jslint.vim
Created Dec 2, 2010
Use Google's JSLint with Vim. Now you can use :make when in a .js file to run gjslint on it and get a list of errors in the quickfix window. This was thrown together hastily and Vim's errorformat is confusing as hell, so feel free to fork and improve
View google-jslint.vim
au BufNewFile,BufRead *.js set makeprg=gjslint\ %
" The ^G at the end is an actual <Ctrl-G> char.
" Gist won't let me include it, so you'll have to delete the last two characters
" and insert it yourself with <Ctrl-V><Ctrl-G>
au BufNewFile,BufRead *.js set errorformat=%-P-----\ FILE\ \ :\ \ %f\ -----,Line\ %l\\,\ E:%n:\ %m,%-Q,%-GFound\ %s,%-GSome\ %s,%-Gfixjsstyle%s,%-Gscript\ can\ %s,%-G^G
View gist:792670
(let [faved (brains.db/user-site-faved-count uid)
mehed (brains.db/user-mehed-count uid)
hated (brains.db/user-hated-count uid)] ...)
View gist:792678
(defn personality-score
[faved mehed hated]
(/ (+ faved (* mehed 0.5)) (+ faved mehed hated)))
View gist:792680
(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)))))
View gist:792684
(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) }))
You can’t perform that action at this time.