Skip to content

Instantly share code, notes, and snippets.

View narfdotpl's full-sized avatar

Maciej Konieczny aka narf narfdotpl

View GitHub Profile
@konradhalas
konradhalas / fabfile.py
Created April 25, 2012 18:41
fabfile - simple django app deploy
import os
from fabric.api import run, cd, env, abort
from fabric.contrib.console import confirm
from fabric.context_managers import prefix
from fabric.tasks import Task
env.hosts = ['[email protected]']
env.settings = ['staging', 'production']
@narfdotpl
narfdotpl / jc.py
Created August 15, 2011 09:58
invalidate Johnny Cache
#!/usr/bin/env python
# encoding: utf-8
"""
Invalidate Johnny Cache's cache for given models outside "normal Django"
(e.g. in a management command).
"""
from johnny.cache import invalidate
from johnny.middleware import QueryCacheMiddleware
@tcr
tcr / async.coffee
Created July 19, 2011 05:40 — forked from walling/async.coffee
Lean and Mean Serial function in CoffeeScript
# Lean and Mean Serial/Parallel DSL for CoffeeScript
# - based of https://gist.github.com/1090670 by timcameronryan,
# https://gist.github.com/1091019 by walling
serial = (spec) ->
steps = (func for key, func of spec when key != 'catch')
next = (err, args...) ->
return spec.catch(err) if err
steps.shift().apply(next, args) if steps.length > 0
next null
@narfdotpl
narfdotpl / fix-it-fix-it
Created June 18, 2011 13:01
fix iTunes icon
#!/usr/bin/env sh
sudo curl -L http://3.narf.pl/iTunes.icns > /Applications/iTunes.app/Contents/Resources/iTunes.icns
echo 'relog, remove itunes from dock, go to /Applications and drag it back'
@inky
inky / gist:888762
Created March 27, 2011 00:02
over the phone effect
lame -m s -a --preset 64 --lowpass 3.4 --highpass 0.42 in.mp3 out.mp3
# https://twitter.com/#!/marcoarment/status/51790511643697153
#!/bin/bash
set -e
# full path in finder windows
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
# flat dock style
defaults write com.apple.dock no-glass -bool YES
# reduce the dock autohide delay
"""
Here's how to run a command from Python piping a string in to stdin and reading the
output back in to another string. It took me way too long to work this out.
"""
from subprocess import Popen, PIPE
output = Popen(
['java', '-jar', 'yuicompressor-2.4.2.jar', '--type=css'],
stdin=PIPE, stdout=PIPE
$(function() {
var iPhone = /AppleWebKit.*Mobile/.test(navigator.userAgent),
iPhoneApp = iPhone && !(/Mobile.*Safari/.test(navigator.userAgent));
if (iPhone && !iPhoneApp) {
setTimeout(function() { window.scrollTo(0, 1); }, 0);
}
});
# -*- coding: utf-8 -*-
from django.db import models
class LtreeField(models.CharField):
"""Field implementation of PostgreSQL ltree type"""
def __init__(self, *args, **kwds):
super(LtreeField, self).__init__(max_length=128, *args, **kwds)
@inky
inky / convert_nfo.py
Created July 11, 2010 13:01
Convert a file from UTF-8 to CP437.
#!/usr/bin/env python
import codecs, sys
try:
infile, outfile = sys.argv[1], sys.argv[2]
except IndexError:
sys.stderr.write('usage: %s input_file output_file\n' % sys.argv[0])
sys.exit(1)
nfo = codecs.open(infile, encoding='utf-8').read()
codecs.open(outfile, 'w', encoding='cp437').write(nfo)