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 extract_links(url): | |
# extracts all links from a URL and returns them as a list | |
# by: Cody Kochmann | |
def curl(link): | |
from urllib2 import urlopen | |
response = urlopen(link) | |
return(response.read()) | |
def check_if_link(s,req_http=True): | |
# Checks at the input is a legitimate link. |
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 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())) |
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 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) |
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
curl = (theUrl) -> | |
xmlHttp = null | |
xmlHttp = new XMLHttpRequest | |
xmlHttp.open 'GET', theUrl, false | |
xmlHttp.send null | |
xmlHttp.responseText | |
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
(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'); |
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
#!/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") |
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 check_if_link(s,req_http=True): | |
# Checks if the input is a link. | |
allowed_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=%" | |
if req_http and "http" not in s: | |
return(False) | |
if "://" in s: | |
for i in s: | |
if i not in allowed_chars: | |
return(False) | |
return(True) |
OlderNewer