Skip to content

Instantly share code, notes, and snippets.

View sjl's full-sized avatar

Steve Losh sjl

View GitHub Profile
@sjl
sjl / which is best? .py
Created November 16, 2009 20:16 — forked from inky/which is best? .py
They're completely different.
>>> x = '0123456789'
>>> a, b = [{} for _ in x], [{}] * len(x)
>>> a[0]['test'], b[0]['test'] = 1, 1
>>> p(a)
[{'test': 1}, {}, {}, {}, {}, {}, {}, {}, {}, {}]
>>> p(b)
# 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
sjl / .cdg.sh
Created April 29, 2010 16:57 — 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. `~/.cdg.sh`) and source it in `.bashrc`
cdh () {
hg root >/dev/null && cd "`hg root`"
#!/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
@sjl
sjl / markdown.vim
Created June 21, 2011 19:47 — forked from vim-voom/markdown.vim
Markdown folding for Vim
" folding for Markdown headers, both styles (atx- and setex-)
" http://daringfireball.net/projects/markdown/syntax#header
"
" this code can be placed in file
" $HOME/.vim/after/ftplugin/markdown.vim
func! Foldexpr_markdown(lnum)
let l1 = getline(a:lnum)
if l1 =~ '^\s*$'
@sjl
sjl / jquerytest.cljs
Created July 21, 2011 14:05 — forked from ryancrum/jquerytest.cljs
How to use jQuery from ClojureScript
(ns jquerytest.core)
(def jquery (js* "$"))
; Can you not use the short form?
(jquery
(fn []
(-> (jquery "div.meat")
(.html "This is a test.")
(.append "<div>Look here!</div>"))))
@sjl
sjl / next_motion_mapping.vim
Created August 25, 2011 19:43 — forked from AndrewRadev/LICENSE
Execute a vim motion on the "next" text object
" Motion for "next/last object". For example, "din(" would go to the next "()" pair
" and delete its contents.
onoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
xnoremap an :<c-u>call <SID>NextTextObject('a', 'f')<cr>
onoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
xnoremap in :<c-u>call <SID>NextTextObject('i', 'f')<cr>
onoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
xnoremap al :<c-u>call <SID>NextTextObject('a', 'F')<cr>
@sjl
sjl / gist:1296686
Created October 18, 2011 20:50 — forked from aduston/gist:1296656
unisubs.streamer.StreamBox.prototype.transcriptScrolled_ = function(e) {
if (this.videoScrolling_) {
this.videoScrolling_ = false;
} else {
this.showResyncButton_(true);
this.ignoreVideoScrolling_ = true;
}
};
unisubs.streamer.StreamBox.prototype.scrollIntoView_ = function(streamSub) {
@sjl
sjl / ui.cljs
Created February 7, 2012 15:27 — forked from srid/ui.cljs
ClojureScript - prependChild implementation using Google Closure
(defn ^:export prependChild
[parent node]
(dom/insertChildAt parent node 0))
@sjl
sjl / fib.js
Created May 4, 2012 00:25 — forked from ry/fib.js
(fixed) a proper fibonacci server in node. it will light up all your cores.
var http = require('http')
var fork = require('child_process').fork;
function fib(n) {
if (n < 2) {
return 1;
} else {
return fib(n - 2) + fib(n - 1);
}
}