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 / chrome_watcher.py
Created May 8, 2015 02:22
shell script to collect the links visited on Google Chrome on OSX
#!/usr/bin/env python
# shell script to collect the links visited on Google Chrome
# by: Cody Kochmann
import os, time
def current_links():
try:
chrome_link=os.popen("""osascript -e 'tell application "Google Chrome" to return URL of active tab of front window'""").read().split("\n")[0]
return chrome_link
@CodyKochmann
CodyKochmann / clipboard.py
Created May 8, 2015 02:23
python functions that give clipboard access to the script
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)
@CodyKochmann
CodyKochmann / current_dir.py
Created May 8, 2015 02:25
returns the current directory on any unix system
def current_dir():
# returns a unix current directory
# By: Cody Kochmann
from os import path
return(path.dirname(path.realpath(__file__)))
@CodyKochmann
CodyKochmann / disk_usage.py
Created May 8, 2015 02:26
shell or python script for getting stats on the primary disk
#!/usr/bin/env python
# shell script for getting stats on the primary disk
# example data available = ['/dev/disk0s2', '328Gi', '315Gi', '13Gi', '97%', '82518570', '3418928', '96%', '/\n']
import os
disk = os.popen("df -h | grep '/dev/disk0s2'").read().split(' ')
for i in list(disk):
if len(i) is 0:
@CodyKochmann
CodyKochmann / gen_fingerprint.coffee
Last active June 22, 2016 15:29
Generates a unique fingerprint in javascript alone.
gen_fingerprint = ->
# in reference to: http://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace /[xy]/g, (c) ->
r = Math.random() * 16 | 0
v = if c == 'x' then r else r & 0x3 | 0x8
v.toString 16
@CodyKochmann
CodyKochmann / load_css.coffee
Last active March 3, 2016 21:14
loads a stylesheet into the page head
load_style=(css)->
l = document.createElement('style')
l.innerHTML = css
l.type = 'text/css'
document.getElementsByTagName('head')[0].appendChild(l)
return
load_css=(url)->
l = document.createElement('link')
l.src = url
@CodyKochmann
CodyKochmann / myIP.js
Created May 13, 2015 12:10
returns the users ip address in javascript
function myIP() {
// returns the users ip address
// ref link: http://stackoverflow.com/questions/391979/get-client-ip-using-just-javascript
if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET","http://api.hostip.info/get_html.php",false);
xmlhttp.send();
hostipInfo = xmlhttp.responseText.split("\n");
@CodyKochmann
CodyKochmann / remove_spaces.js
Created May 13, 2015 12:14
Removes all spaces from a string in javascript.
function remove_spaces(s){
// removes spaces from a string
// by: Cody Kochmann
return(s.split(" ").join(""));
}
@CodyKochmann
CodyKochmann / b64.coffee
Last active December 23, 2019 13:55
small base64 object for easy encoding/decoding with b64.e() and b64.d()
class b64
constructor:()->@
e:(a)-> window.btoa unescape(encodeURIComponent(a))
d:(a)-> decodeURIComponent escape(window.atob(a))
eval:(a)-> eval decodeURIComponent(escape(window.atob(a)))
b64 = new b64
@CodyKochmann
CodyKochmann / generate_active_width.js
Created May 13, 2015 17:02
pre-renders media specific rules for a div in order to keep it a constant width without needing to worry about margin:0 auto
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)
}