Skip to content

Instantly share code, notes, and snippets.

View brock's full-sized avatar
😎

Brock Angelo brock

😎
View GitHub Profile
@brock
brock / bootstrap
Last active September 25, 2015 18:02
Bootstrap for Hackathon-Starter
#!/bin/bash
# Bootstrap script for Hackathon-Starter
# https://gist.github.com/brock/aaf06123686a09d92e86
# usage: bootstrap projectname
# instructions:
# make executable: chmod +x bootstrap
# copy this file into a directory in your PATH (typically ~/bin)
if [ ! $1 ]; then
@brock
brock / pg_extract.sh
Last active April 22, 2024 11:00
Extract all databases (or one by name) from a sql file created by pg_dumpall
#!/bin/bash
# extract all postgres databases from a sql file created by pg_dumpall
# this script outputs one .sql file for each database in the original .sql file
# unless you pass the name of a database in the dump
if [ $# -lt 1 ]
then
echo "Usage: $0 <postgresql sql dump> [dbname]" >&2
exit 1
fi
@brock
brock / postgres_extract.sh
Created July 20, 2015 21:02
Extract a single database from a the pg_dumpall archive
#!/bin/bash
START=0
END=0
if [ $# -ne 2 ]
then
echo "Usage: $0 <postgresql sql dump> <db_name>" >&2
exit 1
fi
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Usage: $0 <postgresql sql dump> <db_name>" >&2
exit 1
fi
db_file=$1
db_name=$2
#!/usr/bin/env node
// Simply publish a message to a direct exchange.
sys = require('sys');
amqp = require('./amqp');
inspect = sys.inspect;
puts = sys.puts;
connection = amqp.createConnection();
@brock
brock / a.md
Last active August 29, 2015 14:18
The Button

The Button

Data analysis on how long until the button runs out.

Reddit unleashed the button this week and it has quickly become my all-time favorite April Fools campaign. The rules are simple, click the button (or don't) so long as your reddit account was created before April 1, 2015. Smart, they've effectively limited their pool of potential users, and guaranteed that this experiment won't go on forever. Clicking the button resets a 60 second timer.

Since this was started, the timer hasn't ever gotten below 30 seconds, to my knowledge.


Let's look at what might have been:

  • 1,638,409 Number of registered users as of April 1, 2015
@brock
brock / button.js
Created April 1, 2015 17:57
reddit button js
try {
jQuery.cookie = function(e, t, n) {
if (arguments.length > 1 && String(t) !== "[object Object]") {
n = jQuery.extend({}, n);
if (t === null || t === undefined)
n.expires = -1;
if (typeof n.expires == "number") {
var r = n.expires, i = n.expires = new Date;
i.setDate(i.getDate() + r)
}
@brock
brock / mcd.md
Created March 27, 2015 01:37
mcd needs to be a shell built-in function

mcd

I see this code used in so many README files and I always scratch my head...

mkdir myAppName
cd myAppName

This is perhaps the simplest possible function you can write in bash, and should be a built-in function:

@brock
brock / modulesize.sh
Last active September 7, 2017 15:25
ModuleSize - shows the percentage of storage your node_modules are taking up
#!/bin/bash
ALL=$(du -s | awk '{print $1}');
NODEMODULES=$(find . -type d -depth 1 -name node_modules | xargs du -s | awk '{print $1}' | awk '{sum+=$1} END {print sum}');
DECIMAL=$(awk "BEGIN {printf \"%.2f\", $NODEMODULES/$ALL}")
PERCENT=$(echo "$DECIMAL*100" | bc)
echo "node_modules are using $PERCENT% of space in the current directory."

[exec_sh] mLast updated: 2015-01-18

Searching for Files

###Find images in a directory that don't have a DateTimeOriginal###

exiftool -filename -filemodifydate -createdate -r -if '(not $datetimeoriginal) and $filetype eq "JPEG"' .

###Output photos that don't have datetimeoriginal to a CSV### Note this can take a long time if you have a lot of jpgs