Skip to content

Instantly share code, notes, and snippets.

# 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 """
# 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'
# 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
// 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 );
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
@cosmin
cosmin / dupfinder.rb
Created March 30, 2009 09:44
Find and remove duplicate files using Ruby
require 'find'
source = ARGV[0]
destination = ARGV[1]
print "Source = #{source}\n"
print "Destination = #{destination}\n"
files = {}
match_keys = []
# 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))
# parse a DSN
import re
regex = re.compile(r':(mysql|postgres)://(?:([\w]+)(?::([\w]+))?@)?([\w.-]+)(?::([\d]{1,5}))?')
def parsedsn(string):
return regex.match(string)
# 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.
#!/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