Skip to content

Instantly share code, notes, and snippets.

View gotcha.py
def make_adder():
grand_total = 0
def adder(to_add):
nonlocal grand_total
print("Grand total moved from: %s" % grand_total)
grand_total += to_add
print("To: %s \n" % grand_total)
return grand_total
return adder
View little_rust.rs
fn main() {
let args = os::args();
let mut washed_args = Vec::new();
for arg in args.iter() {
washed_args.push(arg.as_slice())
}
match washed_args.as_slice() {
[_, "review", opts..] => { review(opts) }
_ => { usage() }
@panzi
panzi / .bashrc
Last active Mar 26, 2017 — forked from henrik/.bashrc
No color and only show basename of current working directory.
View .bashrc
# http://henrik.nyh.se/2008/12/git-dirty-prompt
# http://www.simplisticcomplexity.com/2008/03/13/show-your-git-branch-name-in-your-prompt/
# username@Machine dir [master]$ # clean working directory
# username@Machine dir [master*]$ # dirty working directory
function parse_git_dirty {
[[ $(git status 2> /dev/null | tail -n1) != "nothing to commit (working directory clean)" ]] && echo "*"
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/ [\1$(parse_git_dirty)]/"
View capybara-helpers.rb
def screenshot
require 'capybara/util/save_and_open_page'
now = Time.now
p = "/#{now.strftime('%Y-%m-%d-%H-%M-%S')}-#{rand}"
Capybara.save_page body, "#{p}.html"
path = Rails.root.join("#{Capybara.save_and_open_page_path}#{p}.png").to_s
page.driver.render path
Launchy.open path
end
@panzi
panzi / escapeXml.js
Created Feb 18, 2012 — forked from atesgoral/escapeXml.js
Escape XML in JavaScript.
View escapeXml.js
var XML_CHAR_MAP = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;',
'"': '&quot;',
"'": '&apos;'
};
function escapeXml (s) {
return s.replace(/[<>&"']/g, function (ch) {
You can’t perform that action at this time.