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
@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 / 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 / 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))
#!/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 / 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
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).
abspath(Path)->
Bits = filename:split(Path),
Folder = fun(Elem, Acc)->
case Elem of
".." ->
[ lists:nth(Seq, Acc) || Seq <- lists:seq(1, length(Acc)), Seq < length(Acc) ];
_ ->
Acc ++ [Elem]
end
~ $ python
>>> import os
>>> os.path.abspath("../foo")
'/home/foo'
~ $ erl
1> filename:absname("../foo").
"/home/alen/../foo"
;; Because my musclememory is used to :wq - don't shoot me
(global-unset-key "\M-:")
(global-set-key "\M-:wq" 'save-buffers-kill-terminal)
# Tests performed on a Linode 512 instance.
# Keep in mind that Nginx is writing logs and Spooky is not.
# Kudos definitely go to http://twitter.com/ostinelli for Misultin!
########################################################################
###################### Nginx ###########################################
########################################################################
## Testing Nginx with http://owns.ch/pong