Skip to content

Instantly share code, notes, and snippets.

@b1naryth1ef
b1naryth1ef / method1.py
Created July 28, 2011 17:03
Method 1: Eval()
def MyFunction(iny):
print iny
MyVar = MyFunction
eval('MyVar("hi!")')
@b1naryth1ef
b1naryth1ef / method2.py
Created July 28, 2011 17:07
Method 2: Dictionarys
def MyFunc1(iny):
print iny
def MyFunc2(iny):
print iny*2
def MyFunc3(iny):
print iny*3
d = {"A":MyFunc1,"B":MyFunc2,"C":MyFunc3}
@b1naryth1ef
b1naryth1ef / method3.py
Created July 28, 2011 17:13
Method 3: GetATTR()
import dictt
x = MyFunc1
y = getattr(dictt,x)
y("HIIII!")
@b1naryth1ef
b1naryth1ef / ittermethods.py
Created July 28, 2011 17:19
Get all python script from a directory, load them into the environment, and set up a dictionary for usage.
import os
def loadmodules():
"""
Loads all Python scripts in a directory into the enviroment, and a dictionary for easy calling
"""
#Define our variables
home = os.getcwd()
filenames = []
mody = {}
@b1naryth1ef
b1naryth1ef / multicore.py
Created July 29, 2011 21:41
Multicore random number generator
from multiprocessing import Process, Queue
import random
seed = "123456789"
#10,000,000
county = 10000000
count = county/8
print count
def generate(seed2, count, filey):
f = open("./random-"+str(filey)+".txt", "w")
kant
7/29/11 4:46 PM
Hardware:
Hardware Overview:
Model Name: Mac Pro
Model Identifier: MacPro4,1
@b1naryth1ef
b1naryth1ef / multimatrix.py
Created August 18, 2011 03:21
MultiMatrix
def zero(m,n):
return [[0 for row in range(n)] for col in range(m)]
def mult(matrix1,matrix2):
if len(matrix1[0]) != len(matrix2):
print 'Cant do that on that shiznip!'
else:
new_matrix = zero(len(matrix1),len(matrix2[0]))
for i in range(len(matrix1)):
for j in range(len(matrix2[0])):
@b1naryth1ef
b1naryth1ef / install_2.py
Created August 23, 2011 05:25
New Checkin Install
"""The install file for checkin. Rewritten 8/23/2011"""
import getpass
from MySQLdb import *
import MySQLdb
import sys
#Vars
dev_flag = 0 #1-on, 0-off
default_name = "Pycheckins"
c_db = ""
@b1naryth1ef
b1naryth1ef / dlf_blogpost.py
Created August 24, 2011 02:52
Dynamic linking functions!
#FILE 1
def funcy(a,b,c):
print (a,b,c)
#FILE 2
import file1
def funcx(*vars):
file1.funcy([i for i in vars])
@b1naryth1ef
b1naryth1ef / reqs.py
Created September 13, 2011 20:29
Gametasim Level Example
testlevel = {
1:"################",
2:"# # ####",
3:"# # ####",
4:"### ########",
5:"################"
}