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
>>> x = '0123456789' | |
>>> a, b = [{} for _ in x], [{}] * len(x) | |
>>> a[0]['test'], b[0]['test'] = 1, 1 | |
>>> p(a) | |
[{'test': 1}, {}, {}, {}, {}, {}, {}, {}, {}, {}] | |
>>> p(b) |
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
# 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) |
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
#!/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. `~/.cdg.sh`) and source it in `.bashrc` | |
cdh () { | |
hg root >/dev/null && cd "`hg root`" |
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 | |
# 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 |
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 json, time, urllib | |
n = 0 | |
while 1: | |
try: | |
resp = json.load(urllib.urlopen('http://afeedapart.com/u/%s' % n)) | |
except ValueError: | |
time.sleep(1) | |
continue |
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
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 |
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
(let [faved (brains.db/user-site-faved-count uid) | |
mehed (brains.db/user-mehed-count uid) | |
hated (brains.db/user-hated-count uid)] ...) |
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 personality-score | |
[faved mehed hated] | |
(/ (+ faved (* mehed 0.5)) (+ faved mehed hated))) |
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 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))))) |
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 personality | |
[faved mehed hated] | |
(let [score (personality-score faved mehed hated)] | |
{ :score score | |
:stddev (personality-stddev faved mehed hated score) | |
:total (+ faved mehed hated) })) |
OlderNewer