Skip to content

Instantly share code, notes, and snippets.

View CodyKochmann's full-sized avatar

Cody Kochmann CodyKochmann

  • Severn, MD
View GitHub Profile
@CodyKochmann
CodyKochmann / link_extractor.py
Last active April 27, 2017 02:35
Python based link extractor
@CodyKochmann
CodyKochmann / timestamp.py
Last active July 23, 2016 19:59
timestamp.py
def timestamp(human_readable=False):
# Generates a unix timestamp and a human readable timestamp if passed True
# by: Cody Kochmann
from calendar import timegm
from datetime import datetime
if human_readable:
return(datetime.now())
else:
return(timegm(datetime.now().utctimetuple()))
@CodyKochmann
CodyKochmann / split_all_strings.py
Last active August 7, 2016 04:46
splits all strings in a list with the splitter and adds them back (really helpful in certain search algorithms)
def split_all_strings(input_array, splitter):
# splits all strings in a list with the splitter and adds them back
# by: Cody Kochmann
if isinstance(input_array, basestring):
# patch to accept input_array in string form
input_array = [input_array]
result = []
for i in input_array:
for x in i.split(split_char):
result.append(x)
@CodyKochmann
CodyKochmann / downloader.py
Last active August 29, 2015 14:20
Python downloader for url to output path if duplicate file with optional duplicate renaming.
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]
@CodyKochmann
CodyKochmann / curl.coffee
Last active March 27, 2022 16:24
grep (actually curl) equivalent (http requester) for javascript
curl = (theUrl) ->
xmlHttp = null
xmlHttp = new XMLHttpRequest
xmlHttp.open 'GET', theUrl, false
xmlHttp.send null
xmlHttp.responseText
@CodyKochmann
CodyKochmann / script_path.py
Created May 7, 2015 23:10
Python snippet to get the full path of the script containing the snippet. (good for finding differently positioned workspaces)
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)
@CodyKochmann
CodyKochmann / ensure_dir.py
Last active August 29, 2015 14:20
python script to ensure there is a directory of that name in that path
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] != "/":
@CodyKochmann
CodyKochmann / manual_adblock.js
Created May 8, 2015 02:17
bookmarklet that covers the screen with a touch interphase that can be used to delete
(function() {
// covers the screen with a touch interphase that can be used to delete
// elements in the way. This is purposed to be a manual type of adblock
// author: Cody Kochmann
var div = document.createElement("div");
div.id = 'page_cleaner544';
div.innerHTML = "<div id='click_remover' style='width:" + window.outerWidth.toString() + "px; height:" + window.outerHeight.toString() + "px; background : rgba(50,50,50,0.1); position:fixed; z-index:2147483646; top:0; left:0;'></div>";
div.innerHTML += "<style>#close_cleaner{position:fixed;height:auto;padding:0.15in 0;width:2in;bottom:0.5in;left:0.5in;background:rgba(250,250,250,0.85);-webkit-touch-callout: none;-webkit-user-select: none;-khtml-user-select: none;-moz-user-select: none;-ms-user-select: none;user-select: none;color:rgba(50,50,50,0.65);text-align:center;z-index:2147483647;}</style><p id='close_cleaner'>Done</p>";
document.body.appendChild(div);
var click_remover = document.getElementById('click_remover');
@CodyKochmann
CodyKochmann / app_cpu_throttle.py
Created May 8, 2015 02:18
shell script that uses cpulimit to slow down a selfish app (does require cpulimit to be installed)
#!/usr/bin/env python
# shell script that uses cpulimit to slow down a selfish app
import os, sys, time
if "-stop" in " ".join(sys.argv):
print "stopping all limiters."
os.system('killall cpulimit')
target_app = raw_input("What app would you like to limit?\n")
@CodyKochmann
CodyKochmann / check_if_link.py
Created May 8, 2015 02:20
python snippet to check or verify if the input string is a link.