Skip to content

Instantly share code, notes, and snippets.

Avatar
🎄
Sticking packages under the pypi tree.....

Sorin Sbarnea ssbarnea

🎄
Sticking packages under the pypi tree.....
View GitHub Profile
View collectmedia.py
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
Bash script for setting up OS X for power users
View .profile
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'
View py27-str-unicode-bytes.py
#! /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 Jun 27, 2011
Script to remove Office 2011 from OS X - one essential feature that was dropped from 2011 release ;)
View remove-office-2011.py
#! /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",
View osx-add-to-path-env.py
#! /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 Jul 6, 2011
Script to convert a a database to use utf8 encoding
View mysql-convert-utf8.py
#! /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()
View brew-install-git-lion.log
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 Oct 26, 2011
ANSI support detection code for Python.
View test_ansi.py
#!/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 Nov 4, 2011
Python script that enables and handles edit:// hyperlinks under Windows.
View edit-uri-handler.py
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 Nov 22, 2011
test-python-path-detection
View path-tester.cmd
@cls
@echo --- testing ---
@echo Should all return:
@echo %~dp0
@echo.
@echo.
@echo #1
@cd /D %~dp0
python path-tester.py