Skip to content

Instantly share code, notes, and snippets.

View adamcbrewer's full-sized avatar

Adam Brewer adamcbrewer

View GitHub Profile
@adamcbrewer
adamcbrewer / Default (OSX).sublime-keymap
Last active October 9, 2015 07:57
ST: Sublime Text Preferences
[
{ "keys": ["alt+super+shift+f"], "command": "show_panel", "args": {"panel": "find_in_files"} },
{ "keys": ["super+shift+f"], "command": "search_in_project" }, // requires SearchInProject to be enabled
{ "keys": ["super+k","super+m"], "command": "toggle_minimap" },
{ "keys": ["super+k", "super+t"], "command": "title_case" },
{
"keys": ["super+alt+left"],
"command": "set_layout",
"args": {
"cols": [0.0, 0.33, 1.0],
@adamcbrewer
adamcbrewer / throttle.sh
Created October 11, 2012 07:55 — forked from apinstein/ipfw bandwidth throttle.sh
SH: ipfw bandwidth throttling
#!/bin/sh
#
# Use ipfw to throttle bandwidth.
# usage:
# ./throttle.sh # Throttle at default (60KB/s)
# ./throttle.sh 5 # Throttle at custom speed (5KB/s)
# ./throttle.sh off # Turn throttling off
# flush rules
ipfw del pipe 1
@adamcbrewer
adamcbrewer / facebook.scrollTop.js
Created October 25, 2012 15:58
FB: Canvas - Scroll To Top
// Function for returning the user to any 'y' position in a Facebook app/tab. Uses jQuery animate, otherwise gracefully falls-back without it.
// Source[1]: http://stackoverflow.com/questions/7193425/how-do-you-animate-fb-canvas-scrollto
// Source[2]: https://developers.facebook.com/docs/reference/javascript/FB.Canvas.scrollTo/
var scrollY = function (y) {
if (window.jQuery) {
FB.Canvas.getPageInfo (function (pageInfo) {
$({ y: pageInfo.scrollTop })
.animate({
y: y
@adamcbrewer
adamcbrewer / jq.konami.js
Created November 4, 2012 16:14
JS: Konami Code
// Konami code with jQuery.
// Source: http://paulirish.com/2009/cornify-easter-egg-with-jquery/
var kkeys = [],
konami = "38,38,40,40,37,39,37,39,66,65";
$(document).keydown(function(evt) {
kkeys.push( evt.keyCode );
if ( kkeys.toString().indexOf( konami ) >= 0 ){
$(document).unbind('keydown',arguments.callee);
@adamcbrewer
adamcbrewer / entities.json
Created October 12, 2015 11:32
JSON: HTML Entity Reference
{
"ascii": [
{
"character": " ",
"entityName": " ",
"entityNumber": " ",
"description": "Space"
},
{
"character": "!",
@adamcbrewer
adamcbrewer / rAF.js
Created December 3, 2012 08:46 — forked from paulirish/rAF.js
JS: requestAnimationFrame polyfill
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller
// fixes from Paul Irish and Tino Zijdel
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
@adamcbrewer
adamcbrewer / extend.js
Created February 20, 2013 10:30
JS: Extending/merging one object with another.
/**
* An extend function to merge some default arguments
* with those passed in from the user.
*
* @param {object} obj The default settings
* @param {object} extObj Arguments from the user
* @return {object} A merged object
*
*/
var extend = function (obj, extObj) {
@adamcbrewer
adamcbrewer / ga-tracker.js
Last active December 14, 2015 01:09 — forked from stugoo/event-tracker-modernizr.js
JS: GA tracker with support for Modernizr tests
/**
* A Google Analytics event tracking proxy.
*
* This lobal allows us to do tests for the instantiation of _gaq
* and also allows us easier debugging in a test environment.
*
* Hat-tip to @stugoo for most the self-invoked function features!
*
*/
window.track = function (args) {
@adamcbrewer
adamcbrewer / nl2br.js
Created March 20, 2013 11:33
JS: Newline to <br>
/**
* Converts newline characters to HTML <br /> elements
*
* @author Adam Brewer - @adamcbrewer - adamcbrewer.com
*
* Usage: "String goes\n\rhere".nl2br();
*
*/
String.prototype.nl2br = function () {
return this.replace(/(\r\n|\n|\r)/gm, "<br />");
@adamcbrewer
adamcbrewer / stripProtocols.js
Created March 20, 2013 11:38
JS: Strip protocols
/**
* Strips protocols off strings.
* Usefull for ensuring a consistent base where user input is involved.
*
* Matches:
* http://
* https://
* ftp://
* mailto:
* www.