Skip to content

Instantly share code, notes, and snippets.

@insom
insom / test.py
Created June 6, 2014 14:14
PyMongo BSON encodes the same object differently if C or Python version is used
(cextensionvenv)% python test.py
{u'foo': [u'bar'], u'bacon': [u'cheeseburger']}
(pythonvenv)% python test.py
{u'foo': u'bar', u'bacon': u'cheeseburger'}

Keybase proof

I hereby claim:

  • I am insom on github.
  • I am insom (https://keybase.io/insom) on keybase.
  • I have a public key whose fingerprint is 30D9 81E4 DEB1 FF5D 8CAA D832 8CCE 2412 3B8F 78F8

To claim this, I am signing this object:

@insom
insom / gist:0070d6dd9c3d18f3c8db
Created May 25, 2014 22:13
Add ASCII-art underlines to H2's
// Happy "I can copy and paste and write enough JavaScript to get the thing that I wanted to do done" Day
// - Aaron
String.prototype.repeat = function(times) {
return (new Array(times + 1)).join(this);
}; // from http://stackoverflow.com/questions/4549894/how-can-i-repeat-strings-in-javascript
function insertAfter(referenceNode, newNode) {
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
}; // from http://stackoverflow.com/questions/4793604/how-to-do-insert-after-in-javascript-without-using-a-library
@insom
insom / gist:8008090
Created December 17, 2013 16:45
How old are inetd's children? #badpython
import os
import stat
from os.path import dirname
from glob import glob
import time
for cmdline in glob('/proc/*/cmdline'):
f = open(cmdline).read()
if f.startswith('/usr/sbin/inetd'):
inetd_pid = int(cmdline.split('/')[2])
@insom
insom / get-blog-post-as-markdown.py
Created November 29, 2013 15:48
Get a post from a WP blog and render as an ASCII Markdown file
import sys, urllib
from pyquery import PyQuery as pq
from html2text import html2text
from unidecode import unidecode
d = pq(urllib.urlopen(sys.argv[1]).read())
print unidecode(html2text(d(".entry-content").html()))
@insom
insom / insom.zsh-theme
Created October 16, 2013 11:33
My oh-my-zsh theme.
function box_name {
[ -f ~/.box-name ] && cat ~/.box-name || hostname -s
}
local current_dir='${PWD/#$HOME/~}'
local git_info='$(git_prompt_info)'
function virtualenv_info_2 {
[ $VIRTUAL_ENV ] && (
echo "%{$terminfo[bold]$fg[red]%}v:%{$fg[yellow]%}`basename $VIRTUAL_ENV`%{$reset_color%}"
@insom
insom / trc.py
Created October 4, 2013 11:28
Manually control a Python Turtle with the keyboard.
#!/usr/bin/env python
# Adapted from David Llewellyn-Jones's code
# http://www.flypig.co.uk/?page=list&list_id=363&list=blog
# By Aaron Brady
# http://insom.me.uk/
import turtle as t
import sys
import tty
@insom
insom / parse-cg.py
Last active December 24, 2015 11:48
Parse a PHP-format callgrind file and produce a summary of what time was spent in what files.
import re
import sys
states = ('DEFAULT', 'HAVE_FILE')
fl = re.compile('^fl=(.*)')
num = re.compile('^\d+ (\d+)')
state = 0
current_file = ''
inclusive = False
diff -ru magento-17/app/code/core/Mage/Core/Helper/Cookie.php magento-patched/app/code/core/Mage/Core/Helper/Cookie.php
--- magento-17/app/code/core/Mage/Core/Helper/Cookie.php 2012-07-05 11:49:29.000000000 +0100
+++ magento-patched/app/code/core/Mage/Core/Helper/Cookie.php 2013-09-26 10:52:24.701527319 +0100
@@ -69,7 +69,7 @@
{
$acceptedSaveCookiesWebsites = $this->_getAcceptedSaveCookiesWebsites();
$acceptedSaveCookiesWebsites[Mage::app()->getWebsite()->getId()] = 1;
- return serialize($acceptedSaveCookiesWebsites);
+ return json_encode($acceptedSaveCookiesWebsites);
}
@insom
insom / git-annex-ftp.py
Created September 24, 2013 12:33
Git Annex FTP backend, particularly for iWeb FTP (create a space called "Annex" and include your username and password in the source to use, for now).
#!/usr/bin/python
# git config annex.ftp-hook = "/usr/local/bin/git-annex-ftp.py"
# git annex initremote iwebftp type=hook hooktype=ftp encryption=none
from ftplib import FTP
import os
f = FTP('prefix.iweb-storage.com', 'prefix-admin', 'password')
f.set_pasv(True)