Skip to content

Instantly share code, notes, and snippets.

View adamcbrewer's full-sized avatar

Adam Brewer adamcbrewer

View GitHub Profile
@adamcbrewer
adamcbrewer / clickEventType.js
Last active October 22, 2021 20:29
JS: Detect for supported 'touchstart' events.
/**
* Using default click events in touch-supported devices
* incurs a delay (in order to determine if the user is performing a gesture).
*
* Detecting for touchstart events using the foloowing, we can replace the default 'clicks'
* for touch events, making a snappier experience for mobile/touch devices.
* Use wisely as this could prevent some gestures from happening. If there are scrolling
* issues try swap out 'touchstart' for 'touchend'
*
*/
@adamcbrewer
adamcbrewer / getRotationDegrees.js
Created December 4, 2012 09:42
JS: CSS transform-martrix to rotation in degrees
/**
* Returns rotation in degrees when obtaining transform-styles using javascript
* http://stackoverflow.com/questions/8270612/get-element-moz-transformrotate-value-in-jquery
*/
function getRotationDegrees(obj) {
var matrix = obj.css("-webkit-transform") ||
obj.css("-moz-transform") ||
obj.css("-ms-transform") ||
obj.css("-o-transform") ||
obj.css("transform");
@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 / 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 / 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 / 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 / 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 / facebook.share.html
Last active October 8, 2015 23:27
Social: Custom sharing links
<a id="fb-share-popup" href="http://www.facebook.com/sharer.php?s=100&amp;p[title]=____&amp;p[url]=____&amp;p[summary]=____&amp;p[images][0]=____" target="_blank">share on Facebook</a>
<script>
// This will open our link in a new, small window in the middle of the browser
var p = {};
p.w = 700;
p.h = 400;
p.l = (screen.width/2)-(p.w/2);
p.t = (screen.height/2)-(p.h/2);
@adamcbrewer
adamcbrewer / async-script.js
Created July 3, 2012 09:58
JS: Deferred, asynchronous script loading
<script type="text/javascript">
// Add a script element as a child of the body
function downloadJSAtOnload() {
var script = document.createElement("script");
script.src = "script.js";
document.body.appendChild(script);
}
// Check for browser support of event handling capability
if (window.addEventListener) {
@adamcbrewer
adamcbrewer / custom_taxes_and_posts.php
Created March 14, 2012 18:06
WP: Custom Taxonomies And Post Types
<?php //http://codex.wordpress.org/Function_Reference/register_post_type#Example
/**
* Base-settings for adding additional features to an existing WP install
*
* Location: functions.php file
*
*
*
* It's best to play around with the setting below, but this
* basic structure allows for: