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
def download_file(url, output_path="./", verbose=False, allow_duplicates=False, f_name=''): | |
# downloads a given url to the output_path with duplicate checking options | |
# by: Cody Kochmann | |
from urllib2 import urlopen | |
from os import listdir | |
def v_print(s): | |
if(verbose): | |
print(s) | |
if f_name == '': | |
f_name = url.split('/')[-1] |
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
def script_path(include_name=False): | |
# returns the full path of the script containing this snippet | |
# by: Cody Kochmann | |
from os import path | |
full_path = path.realpath(__file__) | |
if include_name: | |
return(full_path) | |
else: | |
full_path = "/".join( full_path.split("/")[0:-1] ) + "/" | |
return(full_path) |
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
def ensure_dir(dir_name,parent_dir,verbose=False): | |
# ensures there is a directory of that name in that path | |
# by: Cody Kochmann | |
# ex: trash_dir=ensure_dir("trash", script_dir) | |
def v_log(s): | |
if(verbose): | |
print(s) | |
from os import listdir, path, mkdir | |
dir_name=dir_name.replace("/", "") | |
if parent_dir[-1] != "/": |
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
import subprocess | |
def getClipboardData(): | |
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE) | |
retcode = p.wait() | |
data = p.stdout.read() | |
return data | |
def setClipboardData(data): | |
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE) |
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
def current_dir(): | |
# returns a unix current directory | |
# By: Cody Kochmann | |
from os import path | |
return(path.dirname(path.realpath(__file__))) |
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
function remove_spaces(s){ | |
// removes spaces from a string | |
// by: Cody Kochmann | |
return(s.split(" ").join("")); | |
} |
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
var generate_active_width = function(dom_id,min_inches,flexing_percentage,max_inches){ | |
// pre-renders media specific rules for a div in order to keep it a constant width without needing to | |
// worry about the stability of "margin:0 auto" in certain situations. | |
// by: Cody Kochmann | |
var inject_css = function(a) { | |
var b = document.createElement("style"); | |
b.innerHTML = a; | |
b.type = "text/css"; | |
document.getElementsByTagName("head")[0].appendChild(b) | |
} |
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
def findall(search_field,search): | |
# searches a string for a substring and returns an array of indexes | |
# by: Cody Kochmann | |
tmp_field = search_field.split(search) | |
if len(tmp_field) == 1: | |
return(False) | |
output = [] | |
tmp_string = "" | |
for i in range(len(tmp_field)): | |
tmp_string += tmp_field.pop(0) |
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
def get_complete_string(s,start,end): | |
# returns a substring starting with start and ending with end | |
# By: Cody Kochmann | |
unique="~~~~the~obvious~way~to~do~it~~~~" | |
return(start+s.replace(start, unique).replace(end, unique).split(unique)[1]+end) |
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
def random_string(length=32,upper=True,lower=True,digits=True): | |
# Generates a random string with selectable characters | |
# By: Cody Kochmann | |
from random import choice | |
chars = "" | |
if upper: | |
chars+="QWERTYUIOPASDFGHJKLZXCVBNM" | |
if lower: | |
chars+="qwertyuiopasdfghjklzxcvbnm" | |
if digits: |
OlderNewer