Skip to content

Instantly share code, notes, and snippets.

View johnloy's full-sized avatar

John Loy johnloy

View GitHub Profile
@millenomi
millenomi / gourl.sh
Created January 14, 2011 16:23
This is a wrapper around the 'curl' command-line tool that adds a few useful features.
#!/bin/bash
if [ "$#" == "0" ]; then
echo "usage: $0 [CURL FLAGS|--json FILE|--https|--dry-run]* URL" >&2
echo "You can set the BASE_URL environment variable; if you do, all relative URLs will be have the BASE_URL appended in front of them. (Note that this appends blindly the two strings together, doing no resolution work.)" >&2
exit 1
fi
args=("$@")
verbatim_args=()
@ttscoff
ttscoff / Quix commands for domain navigation
Created February 9, 2011 01:46
Bookmarklets for moving up or skipping to top levels of a domain, in [Quix format](http://quixapp.com/help/syntax/)
> See <http://quixapp.com/help/syntax/> for more info on Quix syntax and usage
up javascript:(function(){window.location=document.location.href.replace(/\/$/,'').split('/').slice(0,-1).join('/')+"/";})(); Move up one level in the sites directory structure
top javascript:(function(){window.location=document.location.protocol+"//"+document.location.host;})(); Jump to top level of the current site
@jcsrb
jcsrb / gist:1081548
Created July 13, 2011 23:05
get avatar from google profiles, facebook, gravatar, twitter, tumblr
function get_avatar_from_service(service, userid, size) {
// this return the url that redirects to the according user image/avatar/profile picture
// implemented services: google profiles, facebook, gravatar, twitter, tumblr, default fallback
// for google use get_avatar_from_service('google', profile-name or user-id , size-in-px )
// for facebook use get_avatar_from_service('facebook', vanity url or user-id , size-in-px or size-as-word )
// for gravatar use get_avatar_from_service('gravatar', md5 hash email@adress, size-in-px )
// for twitter use get_avatar_from_service('twitter', username, size-in-px or size-as-word )
// for tumblr use get_avatar_from_service('tumblr', blog-url, size-in-px )
// everything else will go to the fallback
// google and gravatar scale the avatar to any site, others will guided to the next best version
@fatihacet
fatihacet / pubsub-simple.js
Created October 15, 2011 22:02
Simple PubSub implementation with JavaScript - taken from Addy Osmani's design patterns book -
var pubsub = {};
(function(q) {
var topics = {}, subUid = -1;
q.subscribe = function(topic, func) {
if (!topics[topic]) {
topics[topic] = [];
}
var token = (++subUid).toString();
topics[topic].push({
token: token,
@jafstar
jafstar / adobe.html
Created August 19, 2012 15:44
HTML5 Image Progress Events
<html>
<head>
<script>
var request;
var progressBar;
function loadImage(imageURI)
{
request = new XMLHttpRequest();
@rahearn
rahearn / gist:3868151
Created October 10, 2012 20:18
Recovery steps for messed up rebase
Recovering from a botched rebase:
1) mess up a rebase
2) `git reflog` and find the last commit before the rebase started
3) `git reset --hard <<that commit>>`
4) rebase again and try not to mess up this time
@lanqy
lanqy / bytesToSize.js
Created March 19, 2013 03:05
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@h2non
h2non / copyFiles.js
Created March 21, 2013 16:01
Simple Node.js recursivily copy/rename files with specific pattern
/**
* Simple Node.js recursivily copy/rename files with specific pattern
* @license WTFPL
* @usage $ node copyFiles.js
*/
var fs = require('fs'),
config;
// config options
config = {
@ctanis
ctanis / man.sh
Created April 3, 2013 13:11
open man pages in Preview.app (caches generated pdfs in ~/.manpath)
#!/bin/sh
#Based on this Mac OS X Hint:
#http://hints.macworld.com/article.php?story=20110511111211385
#Modified for input of multiple commands to seperate .PS files
CACHE=~/.mancache
mkdir -p $CACHE
COMMANDS="$@"
for f in $COMMANDS
do
/**
* Simple node.js style script loader for modern browsers
**/
function loadScript(src, cb) {
var script = document.createElement('script');
script.async = true;
script.src = src;
script.onerror = function() {
cb(new Error("Failed to load" + src));