Skip to content

Instantly share code, notes, and snippets.

View flashingpumpkin's full-sized avatar
🏠
Working from home

Alen Mujezinovic flashingpumpkin

🏠
Working from home
View GitHub Profile
normpath(Path) ->
filename:join(normpath(filename:split(Path), [])).
normpath([], Acc) ->
lists:reverse(Acc);
normpath([".." | Rest], [Prev|Acc]) ->
normpath(Rest, Acc);
normpath([Head|Rest], Acc) ->
normpath(Rest, [Head|Acc]).
-ifdef(TEST).
@flashingpumpkin
flashingpumpkin / twittercompress.py
Created September 3, 2011 18:35 — forked from alexalemi/twittercompress.py
Twitter Compression
""" A script to attempt the compression of written english
to the chinese character set """
import os
from collections import OrderedDict
from math import log
import itertools
from collections import Counter
#!/bin/bash
#
# Usage: bulkreplace <path> <filetype> <find_pattern> <replace>
function infile(){
find $1 -name "*$2" -exec grep -H "$3" {} \; | sed 's/:.*//';
}
for f in $(infile $1 $2 $3); do replace "$3" "$4" -- $f; done
@flashingpumpkin
flashingpumpkin / randompw.py
Created December 5, 2011 12:10
randompw.py
#!/usr/bin/env python
import random
import string
def random_pw():
char_set = list(string.letters + string.letters.upper() + string.digits + string.punctuation)
return ''.join(random.sample(char_set, 20))
@flashingpumpkin
flashingpumpkin / partial.py
Created December 7, 2011 18:20
Render only part of a django template
from django import template
tpl = template.Template("""
{% block head %}{% endblock %}
{% block body %}
{% block content %}{% endblock %}
{% endblock %}
""")
def getnode(node, name = 'content'):
@flashingpumpkin
flashingpumpkin / ssh-host-complete.sh
Created December 8, 2011 14:26
Auto completing for some commands from your hosts file
#!/bin/bash
# Choose one
complete -W "$(grep -E '^[0-9]' /etc/hosts | awk '{ print $2 }')" ssh scp rsync ping
complete -W "$(grep -E '^ssh' ~/.bash_history | awk '{ print $2 }')" ssh scp rsync
complete -W "$(grep -E '^(\w)' ~/.ssh/known_hosts | awk '{ print $1 }' | sort -u | cut -d ',' -f 1)" ssh scp rsync ping
@flashingpumpkin
flashingpumpkin / gmail.monospace.coffee.js
Created December 9, 2011 14:13
Gmail Monospace Font
css = """
div.Bk {
font-family: DejaVu Sans Mono, Courier, Monospace !important;
}
textarea {
font-family: DejaVu Sans Mono, Courier, Monospace !important;
}
td > div {
font-family: DejaVu Sans Mono, Courier, Monospace !important;
}
"""
jQuery templates use constructs like:
{{if condition}} print something{{/if}}
This, of course, completely screws up Django templates,
because Django thinks {{ and }} mean something.
Wrap {% verbatim %} and {% endverbatim %} around those
blocks of jQuery templates and this will try its best
@flashingpumpkin
flashingpumpkin / default-app-recipe.rb
Created December 15, 2011 14:29
Pretty much what every python web dev should do when starting a new project
# Defaults that we'll need
include_recipe "apt"
package "vim"
package "screen"
package "git-core"
package "mercurial"
package "subversion"
package "python"
;; add this to your ~/.emacs or ~/.emacs.d/init.el file
;; jump parens
(defun match-paren (arg)
(interactive "p")
(cond
((looking-at "\\s\(") (forward-list 1) (backward-char 1))
((looking-at "\\s\)") (forward-char 1) (backward-list 1))
((looking-at "\\s\{") (forward-list 1) (backward-char 1))
((looking-at "\\s\}") (forward-char 1) (backward-list 1))