Skip to content

Instantly share code, notes, and snippets.

View un33k's full-sized avatar
🎯
Focusing

Val Neekman un33k

🎯
Focusing
View GitHub Profile
@un33k
un33k / profileit.py
Last active October 2, 2024 02:37
Performance Profile Decorator (function wrapper based on cProfile). Decorate any function to profile it.
import cProfile
def profileit(func):
"""
Decorator (function wrapper) that profiles a single function
@profileit()
def func1(...)
# do something
pass
# The author disclaims copyright to this source code. In place of a legal
# notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
import hashlib, cPickle as pickle, logging
from django.db.models import signals as db_signals
from django.core.cache import cache
# The author disclaims copyright to this source code. In place of a legal
# notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
import hashlib, cPickle as pickle, logging
from django.db.models import signals as db_signals
from django.core.cache import cache
def smart_truncate(text, max_length=0, word_boundary=False):
if not max_length or len(text) < max_length:
return text
if not word_boundary:
return text[:max_length].strip('-')
truncated = ''
for i, word in enumerate(text.split('-')):
if not word: continue
# https://code.djangoproject.com/ticket/17209
import urlparse
from django.conf import settings
from django.core.urlresolvers import reverse_lazy
from django.http import HttpResponseRedirect, QueryDict
from django.utils.decorators import method_decorator
from django.utils.http import base36_to_int
from django.utils.translation import ugettext as _
from django.views import generic
@un33k
un33k / reserved_usernames.rb
Created December 3, 2012 18:37 — forked from caseyohara/reserved_usernames.rb
A list of reserved usernames to avoid vanity URL collision with resource paths
# A list of possible usernames to reserve to avoid
# vanity URL collision with resource paths
# It is a merged list of the recommendations from this Quora discussion:
# http://www.quora.com/How-do-sites-prevent-vanity-URLs-from-colliding-with-future-features
# Country TLDs found here:
# http://en.wikipedia.org/wiki/List_of_Internet_top-level_domains#Country_code_top-level_domains
# Languages found here:
@un33k
un33k / salt-master
Created October 22, 2012 03:22 — forked from justone/salt-master
saltstack on lenny
#!/bin/sh
#
# Salt master
###################################
# LSB header
### BEGIN INIT INFO
# Provides: salt-master
# Required-Start: $remote_fs $network
@un33k
un33k / gist:3886896
Created October 14, 2012 01:28 — forked from EspadaV8/gist:1357237
Script to import Geonames into PostgreSQL taken from http://forum.geonames.org/gforum/posts/list/15/926.page
#!/bin/bash
#===============================================================================
#
# FILE: getgeo.sh
#
# USAGE: ./getgeo.sh
#
# DESCRIPTION: run the script so that the geodata will be downloaded and inserted into your
# database
#
@un33k
un33k / Conways_Game_Of_Life.py
Created October 8, 2012 03:42
Conway's Game of Life
#!/usr/bin/env python
# one approach to the Conway's Game of Life
# http://en.wikipedia.org/wiki/Conway's_Game_of_Life
# Val Neekman [email protected]
# Open a terminal (Mac) 170 x 40, then run this script and see it for yourself
# It is fun
import os
@un33k
un33k / redirect_to_local_port.txt
Created September 11, 2012 22:41
Redirect an integration domain name to a local port to test oAut
RewriteEngine On
RewriteRule ^(.*)$ http://192.168.224.128:8080/$1 [R=301,L]