Skip to content

Instantly share code, notes, and snippets.

@cmattoon
cmattoon / whatever.sh
Created January 12, 2016 01:08
Misc commands
# git rm all those temp files from your new repo
# Did you forget to add a .gitignore?
find . -name '*~' | xargs git rm -f
@cmattoon
cmattoon / example.amd.js
Created January 12, 2016 21:07
Require.js By Example
/**
* Example Asynchronous Module Definition (AMD)
*
*
*/
define(['jquery', 'console'], function($, console) {
"use strict";
var my_private_var = 'This value is private';
function my_private_method() {
@cmattoon
cmattoon / docker-cleanup.sh
Created February 2, 2016 14:42
Docker Cleanup
#!/bin/bash
docker rm $(docker ps --no-trunc -aq)
docker rmi $(docker images -q --filter "dangling=true")
@cmattoon
cmattoon / slidegenerator.php
Last active February 25, 2016 01:48
slides.php
<?php
/**
* Reads a directory and outputs an <img> tag for each *.jpg
* file it finds.
*/
$slides = array_map(function($fname) {
$src = "img/slides/anatomy/" . basename($fname);
return "<img src=\"{$src}\" class=\"slide\">";
}, array_filter(scandir($dir), function($path) {
return (bool)(strpos($path, '.jpg'));
@cmattoon
cmattoon / keybase.md
Created March 7, 2016 14:00
keybase.md

Keybase proof

I hereby claim:

  • I am cmattoon on github.
  • I am cmattoon (https://keybase.io/cmattoon) on keybase.
  • I have a public key whose fingerprint is ED86 EBAE C5E7 6272 F3EB 2897 2645 4202 36A6 F479

To claim this, I am signing this object:

@cmattoon
cmattoon / termproc.py
Last active April 22, 2016 20:17
Terminal Procedures Downloader
#!/usr/bin/env python
import re, os, sys, errno, requests, urllib2
from bs4 import BeautifulSoup
from PyPDF2 import PdfFileMerger, PdfFileReader
DOWNLOAD_PATH = "pdf"
IFR = False
def mkdir_p(path):
#!/usr/bin/env python
"""
Convert argv[1] from list (array) to dict (object)
"""
import sys, json
OUTFILE = 'test-output.json'
with open(sys.argv[1]) as fd:
data = json.loads(fd.read())
@cmattoon
cmattoon / hosts.go
Last active December 10, 2016 15:49
package main
import (
"os"
"io/ioutil"
"strings"
"sort"
)
// Because this doesn't exist?
# Display all log entries for each MAC address
cat /var/log/api-fetcher.log | grep 'Sending Group SMS for'
# Get a list of MAC addresses only
cat /var/log/api-fetcher.log | grep 'Sending Group SMS for' | cut -d' ' -f 9
# Get a list of unique MAC addresses
cat /var/log/api-fetcher.log | grep 'Sending Group SMS for' | cut -d' ' -f 9 | uniq
@cmattoon
cmattoon / python_sloc.sh
Created May 23, 2017 02:04
Python SLOC
#!/bin/bash
# pip install metrics
find . -name '*.py' \|
xargs metrics -q --format csv -f \|
cut -d',' -f 6 \|
tail -n +4 \|
paste -sd+ - \|
sed s'/.$//' \|
bc