Skip to content

Instantly share code, notes, and snippets.

View ColtonPhillips's full-sized avatar

Colton Phillips ColtonPhillips

View GitHub Profile
@ColtonPhillips
ColtonPhillips / Randomizer
Created October 9, 2012 19:31
Retrieves a variable amount of random files of a given type and copys them to an output directory
import sys
import os
import string
import random
import shutil
# Usage: "python Randomizer.py root_dir out_dir number_to_get [file_extensions]"
# file_extensions e.g. -> ".mp3 .wav .ogg .flac"
if __name__ == '__main__':
@ColtonPhillips
ColtonPhillips / NoteFlashAssetBuilder
Created October 9, 2012 19:38
A simple python script to build embed tags for my flash music games
#[Embed(source = 'res/treble/a2.mp3')] public static const T_A2:Class;
#public static var bassArray:Array = [B_A, B_C, B_D, B_E, B_G, B_A1 ];
import sys, string
def main():
relative_path = sys.argv[1]
identifier = sys.argv[2]
underscore = "_"
if (identifier == "!"):
@ColtonPhillips
ColtonPhillips / dirtree
Last active December 11, 2015 11:09
I left the terribad language comments in to demonstrate that dirtree is a half-brained attempt to improve how I use dir() when I code python. I'm saving it because I want to improve it a little as a hobby, and remind myself to keep looking for good alternatives to using dir()
import string
#It irks me greatly how my dir is just as useless as dir right now. sasuke it all away.
def _dirt_recurse(module, verbose=False, file=False, tab_width=0):
list = dir(module)
if file:
# TODO: put that shit in a file
pass
else:
@ColtonPhillips
ColtonPhillips / AssetGenerator.py
Created February 5, 2013 16:35
Kyle Pulver's Asset Generator
##################################################################
# Asset Generator (assetGenerator.py)
# Kyle Pulver
# @kylepulver
# http://kpulv.com
# 2013 / 2 / 3
# Version 1.0.0
#
# Put this file in your AS3 Project root.
#
@ColtonPhillips
ColtonPhillips / AddSystemPaths.ps1
Created April 28, 2013 21:20
A top secret powershell script to add paths to the system environment variables, hopefully.
function AddSystemPaths([array] $PathsToAdd) {
$VerifiedPathsToAdd = ""
foreach ($Path in $PathsToAdd) {
if ($Env:Path -like "*$Path*") {
echo " Path to $Path already added"
}
else {
$VerifiedPathsToAdd += ";$Path";echo " Path to $Path needs to be added"
@ColtonPhillips
ColtonPhillips / choose_weighted.py
Created March 10, 2014 02:24
Given an array of elements which are composed of a tuple of a string label and integer weight, chooses one randomly while factoring in the relative weightings, and returns the label.
from bisect import bisect
from random import random
def weighted_choice(choices):
values, weights = zip(*choices)
total = 0
cum_weights = []
for w in weights:
total += w
cum_weights.append(total)
guess = random () * total
@ColtonPhillips
ColtonPhillips / file_system.sql
Created March 10, 2014 05:11
An attempt at a simple sql problem for a job application
#--#
#--# Database structure for Pretio
#--#
DROP TABLE IF EXISTS Folders;
DROP TABLE IF EXISTS Files;
DROP TABLE IF EXISTS Users;
DROP TABLE IF EXISTS Contents;
CREATE TABLE Users (
userid Integer AUTO_INCREMENT,
from itertools import chain, product
from re import match, findall
import pprint
pp = pprint.PrettyPrinter(indent=4)
GRAMMAR = '''
<sentence> ::= <noun phrase=""> <verb phrase="">
<noun> ::= "boy " | "troll " | "moon " | "telescope "
<transitive verb=""> ::= "hits " | "sees "
import random
def rstr(length=5, special_chars=True, numbers=True, upper_case=True):
chars = string.ascii_lowercase
chars += string.ascii_uppercase if upper_case else ''
chars += string.digits if numbers else ''
chars += string.punctuation if special_chars else ''
return ''.join(random.choice(chars) for i in range(length))
@ColtonPhillips
ColtonPhillips / goog.py
Created July 6, 2014 06:38
What if you could turn an arbitrary text into a google search?
#TODO: what about a string with < or > ? what about with </a> ? etc
#https://www.google.ca/#q=hat+%22stand+man+'dog'+%22
# hat "stand man 'dog' "
my_string = "hat \"stand man 'dog' \""
print("String:")
print(my_string)
google_string = my_string.replace('"',"%22").replace(" ","%20")
print("Google String:")