This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# An example of separating behavior from data in Python | |
import copy, new | |
### Class helpers | |
def create_class(__bases__=(object, ), **kw): | |
return new.classobj('FakeClass', __bases__, kw) | |
def combine(*classes): | |
""" Create class hierarchies programatically """ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# a basic example for taking a title and url, shortening it with bit.ly and posting it to twitter | |
# trimming the title down if necessary. | |
import os | |
import urllib2 | |
import urllib | |
TWITTER_USERNAME = 'test' | |
TWITTER_PASSWORD = 'test' | |
BITLY_USERNAME = 'test' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Nose plugin to dump and restore a database, example of writing a Nose plugin | |
import logging | |
import tempfile | |
import os, sys | |
import re | |
import subprocess | |
from nose.plugins import Plugin | |
from nose.util import tolist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Show a hidden Altiris Client Service, worked against older versions. | |
#include <stdio.h> | |
#include <windows.h> | |
int main( void ) | |
{ | |
HWND hWnd; | |
char szWindowName[] = "Altiris Client Service"; | |
printf( "Finding window %s\n", szWindowName ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
On Error Resume Next | |
'================================================================================ | |
' * Adds users or groups from a domain to a workstation's local groups * | |
' | |
'Example usage | |
'addLocalToLocal "LocalGroup","Administrators" | |
'addToLocal "DomainGroup","Administrators","DOMAINNAME" | |
'================================================================================ | |
'Clean up objects | |
Set oGroup = nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'find' | |
source = ARGV[0] | |
destination = ARGV[1] | |
print "Source = #{source}\n" | |
print "Destination = #{destination}\n" | |
files = {} | |
match_keys = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Constant time Fib using Binet's formula | |
def fib(n): | |
q = (1 + math.sqrt(5)) / 2 | |
return int(((q ** n) - (1 - q) ** n) / math.sqrt(5)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# parse a DSN | |
import re | |
regex = re.compile(r':(mysql|postgres)://(?:([\w]+)(?::([\w]+))?@)?([\w.-]+)(?::([\d]{1,5}))?') | |
def parsedsn(string): | |
return regex.match(string) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Python 2.5 has support for partial function evaluation in the functools module. | |
# Here's is something I hacked out to do the same in Python 2.4 | |
# This is not as complete as the wrapper in Python 2.5: | |
# it doesn't attempt to preserve doc strings, etc. But it should work just fine for most cases. | |
# Be warned however that it doesn't know how many parameters the function being decorated | |
# is supposed to take so if you end up passing it more than necessary you'll never a result. | |
# Also if your function raises a TypeError for other reasons it won't work as well. | |
# If you have any suggestions or improvements you'd like to share post them below. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh # this will loop over all the installed packages | |
for i in `python -c "for dist in __import__('pkg_resources').working_set: print dist.project_name"`: | |
do | |
echo "`sudo easy_install -U $i`" # run easy_install and echo the results | |
echo "----------------------------------------" # | |
done |
OlderNewer