Skip to content

Instantly share code, notes, and snippets.

View matthisk's full-sized avatar

Matthisk Heimensen matthisk

View GitHub Profile
@matthisk
matthisk / args.sh
Last active December 19, 2015 05:29
This bash script checks if the correct amount of arguments are supplied
#!/bin/bash
# Read arguments
# Author: Matthisk Heimensen
NO_ARGS=0
E_OPTERROR=85
if [ $# -eq "$NO_ARGS" ]; then # Script invoked with no command-line args
echo "Usage: `basename $0` options (-upfh)"
exit $E_OPTERROR # Exit and explain usage
@matthisk
matthisk / root.sh
Created July 1, 2013 22:09
Check if the script is running as the root user
ROOT_UID=0; # Only users with $UID 0 have root privileges
E_NOTROOT=87; # Non-root exit error
# Run as root
if [ "$UID" -ne "$ROOT_UID" ]; then
echo "Must be root to run this script."
exit $E_NOTROOT;
fi
@matthisk
matthisk / .gitignore
Created July 4, 2013 12:50
Global generalized git ignore file
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
@matthisk
matthisk / duplicates.sql
Created August 15, 2013 14:03
Find duplicates in a table
SELECT myColumn, count( myColumn ) AS myCount
FROM myTable
GROUP BY myColumn
HAVING myCount >1
ORDER BY myCount
@matthisk
matthisk / bash_profile
Created October 29, 2013 09:53
Export a PS1 in the form: user at hostname in workdir (on git-branch/git-tag)
parse_git_branch () {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
parse_git_tag () {
git describe --tags 2> /dev/null
}
parse_git_branch_or_tag() {
local OUT="$(parse_git_branch)"
@matthisk
matthisk / stream-js-promises.js
Last active October 28, 2015 16:25
stream-js example: Promises
var client = stream.connect('API_KEY', 'API_SECRET'),
user1 = client.feed('user','1');
user1.follow('user', '2')
.then(function(body) {
return user1.get({ limit: 1 });
})
.then(function(body) {
console.log(body);
})
@matthisk
matthisk / stream-js-add-to-many.js
Last active October 28, 2015 16:25
Stream JS example: Add to many
var activity = {'actor': 'User:1', 'verb': 'tweet', 'object': 'Tweet:1'};
var feeds = ['flat:1','flat:2','aggregated:3'];
client.addToMany(activity, feeds)
.then(function(body) { /* fulfillment handler */ })
.catch(function(error) { /* rejection handler */ });
@matthisk
matthisk / stream-js-follow-many.js
Last active October 28, 2015 16:25
Stream JS example: Follow many
var follows = [
{'source': 'flat:1', 'target': 'user:1'},
{'source': 'flat:1', 'target': 'user:2'},
{'source': 'flat:1', 'target': 'user:3'}
];
client.followMany(follows)
.then(function(body) { /* fulfillment handler */ })
.catch(function(error) { /* rejection handler */ });
@matthisk
matthisk / stream-js-activity-copy-limit.js
Created October 28, 2015 15:08
Stream JS example: Activity copy limit
// Don't copy over history
user1.follow('user', '2', { limit: 0 });
// Copy over a maximum of 300 activities
user1.follow('user', '3', { limit: 300 });
@matthisk
matthisk / stream-js-expire-tokens.js
Created October 28, 2015 15:22
Stream JS example: Expire tokens
var client = stream.connect('API_KEY', 'API_SECRET', 'APP_ID', { expireTokens: true });