Skip to content

Instantly share code, notes, and snippets.

View brock's full-sized avatar
😎

Brock Angelo brock

😎
View GitHub Profile
@brock
brock / lock.scpt
Created January 19, 2015 16:46
AppleScripts to lock and unlock a macbook
tell application "System Events"
tell security preferences
set require password to wake to true
end tell
end tell
activate application "ScreenSaverEngine"
@brock
brock / open-new-applications.scpt
Created January 22, 2015 03:33
Open new Applications in OSX
on adding folder items to this_folder after receiving this_item
tell application "Finder"
open this_item
end tell
end adding folder items to
@brock
brock / export-iphotos.scpt
Created January 23, 2015 00:49
Export all photos in iPhoto. You are prompted for the directory they will be copied into. The original files are copied, and they get copied into individual folders for each date.
set destination to quoted form of POSIX path of (choose folder with prompt "Select the folder to create sub-folders and export photos")
tell application "iPhoto"
set tc to count photos
repeat with i from 1 to tc
try
tell photo i to my copyPhoto(date, image path, original path, title, destination)
end try
end repeat
end tell

[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

@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."
@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 / 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 / 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
#!/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();
#!/bin/sh
if [ $# -ne 2 ]
then
echo "Usage: $0 <postgresql sql dump> <db_name>" >&2
exit 1
fi
db_file=$1
db_name=$2