Skip to content

Instantly share code, notes, and snippets.

@chazcheadle
chazcheadle / up
Created April 17, 2014 11:35
Bash
# Go up directory tree X number of directories
function up() {
COUNTER="$@";
# default $COUNTER to 1 if it isn't already set
if [[ -z $COUNTER ]]; then
COUNTER=1
fi
# make sure $COUNTER is a number
if [ $COUNTER -eq $COUNTER 2> /dev/null ]; then
nwd="`pwd`" # Set new working directory (nwd) to current directory
[[ -s ~/.bashrc ]] && source ~/.bashrc
source ~/git-completion.bash
@chazcheadle
chazcheadle / freerun.ino
Created August 18, 2014 17:47
65C02 - Free Run
/* Project 65
*
* Bootstrap test
*
* From: coronax - http://coronax.wordpress.com/2012/11/11/running-in-circles/
*/
const int clock_pin = 3;
const int num_pins = 8;
/* address bus pins hooked to high byte of address bus */
@chazcheadle
chazcheadle / promise.ng.js
Last active August 29, 2015 14:10
AngularJS - Promise
/**
* This is a factory promise that uses $http
*/
.factory('myFactory', ['$http', '$q', function($http, $q) {
var getData = function() {
var deferred = $q.defer();
$http({method:"GET", url:"/index.php", cache: false})
.success(function(data, status, headers, config) {
date = formatDate(headers('Date'), 4);
deferred.resolve(date);
@chazcheadle
chazcheadle / resource.factory.ng.js
Created November 21, 2014 15:36
Angular - $resource factory
.factory('myFactory', ['$resource', function ($resource) {
return $resource('FEED_URL', {
callback: 'JSON_CALLBACK',
// URL parameter
form: 'json'
}, {
get: {
// Used to get resources from other domains and namespace multiple calls
method: 'JSONP',
// These are the ?<PARAM=VALUE>&... queries
@chazcheadle
chazcheadle / ccurl
Created March 24, 2015 19:47
Curl content cache busting with timestamp parameter
#!/bin/bash
if [[ $1 == *"?"* ]]
then
q='&'
else
q='?'
fi
cmd='curl '$1$q'timestamp='`date +%s`;
exec $cmd;
@chazcheadle
chazcheadle / mpx_data.json
Last active August 29, 2015 14:25
MPX data processing with Python
{
"entries": [
{
"title": "Fiscal cliffhanger: GOP going against public sentiment?",
"description": "MSNBC’s Thomas Roberts talks with Rep. Diane Black, R-Tenn., and the political power panel--Karen Tumulty of the Washington Post, Democratic strategist Karen Finney, and Republican strategist Robert Traynham--about fiscal cliff talks.",
"added": 1354862683000
},
{
"title": "The impact of changing demographics in the south",
"description": "MSNBC’s Thomas Roberts talks with Atlanta Mayor Kasim Reed and the Rev. C.L. Bryant about the changing demographics in the south and how it could impact future elections.",
@chazcheadle
chazcheadle / wordpattern.py
Created January 10, 2016 15:36
Get word pattern
#!/bin/python
word = 'odysseus'
wordpattern = []
alphabet = {'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'j':0,'k':0,'l':0,'m':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}
def getWordPattern(word):
word.lower()
unique = 0
occurances = []
@chazcheadle
chazcheadle / letterfrequency.py
Last active January 10, 2016 20:57
Get frequency of letters in a given body of text
#!/bin/python
text = \
'''Sing in me, Muse, and through me tell the story
of that man skilled in all ways of contending,
the wanderer, harried for years on end,
after he plundered the stronghold
on the proud height of Troy.
He saw the townlands
@chazcheadle
chazcheadle / trithemius-cipher-table.html
Last active January 14, 2016 21:27
Trithemius progressive key cipher table in D3
<html>
<head>
<title>Trithemius progressive key cipher table</title>
<meta charset="utf-8">
<script src="http://d3js.org/d3.v3.min.js"></script>
<style type="text/css">
table {
border-collapse: collapse;
border: 2px black solid;
}