Skip to content

Instantly share code, notes, and snippets.

Avatar

Cody Kochmann CodyKochmann

  • Severn, MD
View GitHub Profile
@CodyKochmann
CodyKochmann / link_extractor.py
Last active Apr 27, 2017
Python based link extractor
View link_extractor.py
View 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 Aug 7, 2016
splits all strings in a list with the splitter and adds them back (really helpful in certain search algorithms)
View split_all_strings.py
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 Aug 29, 2015
Python downloader for url to output path if duplicate file with optional duplicate renaming.
View downloader.py
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 Mar 27, 2022
grep (actually curl) equivalent (http requester) for javascript
View curl.coffee
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
Python snippet to get the full path of the script containing the snippet. (good for finding differently positioned workspaces)
View script_path.py
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 Aug 29, 2015
python script to ensure there is a directory of that name in that path
View ensure_dir.py
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
bookmarklet that covers the screen with a touch interphase that can be used to delete
View manual_adblock.js
(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
shell script that uses cpulimit to slow down a selfish app (does require cpulimit to be installed)
View app_cpu_throttle.py
#!/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
python snippet to check or verify if the input string is a link.
View check_if_link.py