Skip to content

Instantly share code, notes, and snippets.

View sanfx's full-sized avatar
🎯
Focusing

Sanjeev Kumar sanfx

🎯
Focusing
  • London
  • 14:43 (UTC +01:00)
View GitHub Profile
@kennethreitz
kennethreitz / 0_urllib2.py
Created May 16, 2011 00:17
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@dequegorg
dequegorg / QAnimation.py
Created August 19, 2011 07:33
Qt Child Widget Slide Animation
#!/usr/bin/env python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="benjamin"
__date__ ="$Aug 19, 2011 8:23:20 AM$"
@brantfaircloth
brantfaircloth / paths_to_full_paths.py
Created September 30, 2011 00:27
Convert paths to full paths (argparse)
class FullPaths(argparse.Action):
"""Expand user- and relative-paths"""
def __call__(self, parser, namespace, values, option_string=None):
setattr(namespace, self.dest, os.path.abspath(os.path.expanduser(values)))
def get_args():
parser = argparse.ArgumentParser(description='Something smart here')
parser.add_argument('my_conf', help='The configuration file for the db', action = FullPaths)
return parser.parse_args()
@ibeex
ibeex / auth.py
Created October 14, 2011 20:04
Python LDAP (ActiveDirectory) authentication
import ldap
def check_credentials(username, password):
"""Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
# Adapt to your needs
"""
LDAP_SERVER = 'ldap://xxx'
# fully qualified AD user name
LDAP_USERNAME = '%s@xxx.xx' % username
@matthewmccullough
matthewmccullough / git-compressing-and-deltas.md
Created May 14, 2012 19:05
Git, Compression, and Deltas - An explanation

Git Compression of Blobs and Packfiles.

Many users of Git are curious about the lack of delta compression at the object (blob) level when commits are first written. This efficiency is saved until the pack file is written. Loose objects are written in compressed, but non-delta format at the time of each commit.

A simple run though of a commit sequence with only the smallest change to the image (in uncompressed TIFF format to amplify the observable behavior) aids the understanding of this deferred and different approach efficiency.

The command sequence:

Create the repo:

@Bluehorn
Bluehorn / thread_stop_fail.py
Created May 25, 2012 10:29
An example of how Thread._Thread__stop() does not stop a thread
#! /usr/bin/python
import time
import threading
def f():
for x in range(10):
print "I am alive and running"
time.sleep(0.1)
@nicwolff
nicwolff / gist:2925803
Created June 13, 2012 19:00
'tcsh' Git prompt to show current branch
# in ~/bin/gitprompt.csh:
setenv GIT_BRANCH_CMD "sh -c 'git branch --no-color 2> /dev/null' | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'"
set prompt="%m:%~ `$GIT_BRANCH_CMD`%B%#%b "
# and then in ~/.cshrc:
alias precmd "source ~/bin/gitprompt.csh"
@ibeex
ibeex / foo.log
Created August 4, 2012 13:46
Flask logging example
A warning occurred (42 apples)
An error occurred
@imom0
imom0 / myopt.py
Created September 10, 2012 15:29
simple gists: argparse vs docopt
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""Test docopt example.
Usage:
myopt.py run (update|watch)
myopt.py -h | --help
myopt.py --version
@tito
tito / gist:4215906
Created December 5, 2012 14:30
Notes for rebuilding Kivy OSX package / Python 2.7
Kivy OSX - Portable package
Librairies:
- pygame
- gstreamer (avec tous les plugins)
- pygst (gst-python)
- docutils
Global way to work:
- clean your env, everywhere (brew, python etc.)