Skip to content

Instantly share code, notes, and snippets.

View ssbarnea's full-sized avatar
🎄
Sticking packages under the pypi tree.....

Sorin Sbarnea ssbarnea

🎄
Sticking packages under the pypi tree.....
View GitHub Profile
from django.core.management.base import BaseCommand, CommandError
from django.conf import settings
from optparse import make_option
import os
import sys
import glob
import shutil
try:
set
except NameError:
@ssbarnea
ssbarnea / .profile
Created May 26, 2011 19:21
Bash script for setting up OS X for power users
alias dos2unix-recursive='find . -iname '*.tpl' | xargs dos2unix'
alias edit='mcedit'
alias del='rm'
alias deltree='rm -r'
alias dir='/bin/ls $LS_OPTIONS --format=vertical'
alias attrib='chmod'
alias chdir='cd'
alias copy='cp'
alias ls='ls -a'
#! /usr/bin/env python
"""
This code works with Python 2.6 but fails on Python 2.7
"""
import httplib, urllib2
params = b'\x40\x00\x01\x02\xFF'
url = unicode("http://posttestserver.com/post.php")
@ssbarnea
ssbarnea / remove-office-2011.py
Created June 27, 2011 14:12
Script to remove Office 2011 from OS X - one essential feature that was dropped from 2011 release ;)
#! /usr/bin/env python
import os, sys
paths = ["/Applications/Microsoft Office 2011/",
"/Applications/Remote Desktop Connection",
"/Applications/Microsoft Communicator",
"/Applications/Microsoft Messenger",
"/Users/username/Library/Preferences/Microsoft/Office 2011/",
"/~/Library/Application Support/Microsoft/",
"/~/Documents/Microsoft User Data/",
"/Library/Automator",
#! /usr/bin/env python
import os, sys, plistlib
# Warning this solution works with 10.6+ (including 10.7)
# On 10.5 the apps executed via Spotlight are not going to see the new PATH
f = os.path.expanduser("~/.MacOSX/environment.plist")
try:
dic = plistlib.readPlist(f)
except Exception as e:
@ssbarnea
ssbarnea / mysql-convert-utf8.py
Created July 6, 2011 18:48
Script to convert a a database to use utf8 encoding
#! /usr/bin/env python
import MySQLdb
host = "localhost"
passwd = ""
user = "root"
dbname = "mydbname"
db = MySQLdb.connect(host=host, user=user, passwd=passwd, db=dbname)
cursor = db.cursor()
@ssbarnea
ssbarnea / brew-install-git-lion.log
Created August 19, 2011 09:23
brew-install-git-lion
94:~ ssbarnea$ brew install git
==> Downloading http://kernel.org/pub/software/scm/git/git-1.7.6.tar.bz2
File already downloaded in /Users/ssbarnea/Library/Caches/Homebrew
==> make prefix=/usr/local/Cellar/git/1.7.6 install
GIT_VERSION = 1.7.6
* new build flags or prefix
./generate-cmdlist.sh > common-cmds.h+ && mv common-cmds.h+ common-cmds.h
gcc -o hex.o -c -O3 -w -pipe -I. -DUSE_ST_TIMESPEC -DSHA1_HEADER='<openssl/sha.h>' -DNO_MEMMEM hex.c
gcc -o ident.o -c -O3 -w -pipe -I. -DUSE_ST_TIMESPEC -DSHA1_HEADER='<openssl/sha.h>' -DNO_MEMMEM ident.c
gcc -o levenshtein.o -c -O3 -w -pipe -I. -DUSE_ST_TIMESPEC -DSHA1_HEADER='<openssl/sha.h>' -DNO_MEMMEM levenshtein.c
@ssbarnea
ssbarnea / test_ansi.py
Created October 26, 2011 16:18
ANSI support detection code for Python.
#!/usr/bin/env python
import sys, os, time, platform
sample_ansi = '\x1b[31mRED' + '\x1b[33mYELLOW' + '\x1b[32mGREEN' + '\x1b[35mPINK' + '\x1b[0m' + '\n'
for handle in [sys.stdout, sys.stderr]:
if (hasattr(handle, "isatty") and handle.isatty()) or \
('TERM' in os.environ and os.environ['TERM']=='ANSI'):
if platform.system()=='Windows' and not ('TERM' in os.environ and os.environ['TERM']=='ANSI'):
@ssbarnea
ssbarnea / edit-uri-handler.py
Created November 4, 2011 17:20
Python script that enables and handles edit:// hyperlinks under Windows.
import sys, os, subprocess, shutil
import traceback
from _winreg import *
from ctypes import c_int, WINFUNCTYPE, windll
from ctypes.wintypes import HWND, LPCSTR, UINT
prototype = WINFUNCTYPE(c_int, HWND, LPCSTR, LPCSTR, UINT)
paramflags = (1, "hwnd", 0), (1, "text", "Hi"), (1, "caption", None), (1, "flags", 0)
MessageBox = prototype(("MessageBoxA", windll.user32), paramflags)
# use flag=1 to make it Yes|No
# See http://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx)
@ssbarnea
ssbarnea / path-tester.cmd
Created November 22, 2011 12:27
test-python-path-detection
@cls
@echo --- testing ---
@echo Should all return:
@echo %~dp0
@echo.
@echo.
@echo #1
@cd /D %~dp0
python path-tester.py