Skip to content

Instantly share code, notes, and snippets.

@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@prestontimmons
prestontimmons / gist:2423821
Created April 19, 2012 20:07
Replaced {{ STATIC_URL }} with {% static %} using sed
$ find -name "*.html" | xargs sed -i "s/{{ STATIC_URL }}\([^\"]\+\)/{% static '\1' %}/g"
@jacobvosmaer
jacobvosmaer / gist:3187346
Created July 27, 2012 10:35
Open all files with git merge conflicts in Vim

Open all files with git merge conflicts in MacVim

git diff --name-only | uniq | xargs mvim

When git encounters a merge conflict, e.g. during a rebase, it drops you back into the shell with a dirty working directory. I like this one-liner for opening all files with a merge conflict in MacVim.

Once you're in Vim, you can then switch between the files with :n and :prev, or another favourite: :w | n (save current file and open the next command line-supplied file).

UPDATE: see below for a version that works with real terminal commands.

@impressiver
impressiver / raven-config.html
Last active February 27, 2024 14:27
Raven.js configuration for logging JavaScript exceptions to Sentry (https://getsentry.com/). Without the added ignore options, you'll quickly find yourself swamped with unactionable exceptions due to shoddy browser plugins and 3rd party script errors.
<!-- Raven.js Config -->
<script src="{{ JS_PATH }}/lib/raven.js" type="text/javascript"></script>
<script type="text/javascript">
// Ignore list based off: https://gist.github.com/1878283
var ravenOptions = {
// Will cause a deprecation warning, but the demise of `ignoreErrors` is still under discussion.
// See: https://github.com/getsentry/raven-js/issues/73
ignoreErrors: [
// Random plugins/extensions
'top.GLOBALS',
@xymostech
xymostech / chromium-no-ctrl-scroll-zoom.patch
Created March 10, 2013 01:28
Make Chromium not scroll on ctrl-zoom. Use these patch files on the source directory, and then build.
--- content/browser/web_contents/web_contents_view_gtk.cc.orig 2013-03-09 20:16:51.437945192 -0500
+++ content/browser/web_contents/web_contents_view_gtk.cc 2013-03-09 20:16:56.151278267 -0500
@@ -56,6 +56,8 @@
// See tab_contents_view_views.cc for discussion of mouse scroll zooming.
gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event,
WebContentsImpl* web_contents) {
+ return FALSE;
+
if ((event->state & gtk_accelerator_get_default_mod_mask()) !=
GDK_CONTROL_MASK) {
@jbonney
jbonney / spotify_keybindings
Created June 9, 2013 13:22
Spotify - Linux key bindings. From XFCE / Ubuntu keyboard shortcuts configuration, assign the control command to their key. http://shkspr.mobi/blog/2011/12/linux-spotify-keybindings/
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.PlayPause" XF86AudioPlay
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Stop" XF86AudioStop
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Next" XF86AudioNext
"dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.Previous" XF86AudioPrevious
@jphalip
jphalip / poweroff.py
Last active October 18, 2021 21:54
A Python script I wrote to quickly shut down Vagrant/VirtualBox VMs. See also the associated blog post: https://www.julienphalip.com/blog/fast-shutdown-of-development-vagrantvirtualbox/
#!/usr/bin/env python
import argparse
import re
import os
import subprocess
try:
import json
except ImportError:
import simplejson as json
@gasman
gasman / Vagrantfile
Last active August 29, 2015 13:56
Wagtail developer setup in Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant::Config.run do |config|
# Base box to build off, and download URL for when it doesn't exist on the user's system already
config.vm.box = "wagtail-base-v0.1"
config.vm.box_url = "http://downloads.torchbox.com/wagtail-base-v0.1.box"
# You can also build from a vanilla precise32 box, although it'll take longer
@staltz
staltz / introrx.md
Last active May 18, 2024 05:17
The introduction to Reactive Programming you've been missing
@egel
egel / auto-remove-sublime-license-popup
Last active April 8, 2024 23:00
Auto-remove Sublime's license popup
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sublime_plugin
import subprocess
from time import sleep
import sys
cl = lambda line: subprocess.Popen(line, shell=True, stdout=subprocess.PIPE).communicate()[0].strip()
log = lambda message: sys.stderr.write("Log: %s\n" % message)