Skip to content

Instantly share code, notes, and snippets.

View brianyang's full-sized avatar

Brian Yang brianyang

View GitHub Profile
javascript: function autoFollowBugWorkaround() {
if (followid === 7) {
followid = 0
} else {
followid++
}
$('.appFollow').eq(followid).mousedown()
}
function autoFollow() {
@brianyang
brianyang / postMessage.js
Created April 22, 2014 19:58
post messages between iframes
// child
window.addEventListener("message", function(e) {
alert(e.data)
}, false);
// parent
window.addEventListener("message", function(e) {
e.source.postMessage(e.data, '*');
@brianyang
brianyang / pre-commit
Created January 20, 2014 19:41
pre-commit hook to run jshint
#!/bin/sh
files=$(git diff --cached --name-only --diff-filter=ACM | grep ".js$")
if [ "$files" = "" ]; then
exit 0
fi
pass=true
echo "\nValidating JavaScript:\n"
/* Extend the Underscore object with the following methods */
// Rate limit ensures a function is never called more than every [rate]ms
// Unlike underscore's _.throttle function, function calls are queued so that
// requests are never lost and simply deferred until some other time
//
// Parameters
// * func - function to rate limit
// * rate - minimum time to wait between function calls
// * async - if async is true, we won't wait (rate) for the function to complete before queueing the next request
var baseUrl = window.location.hostname, mobile = Modernizr.mq("only screen and ( max-device-width: 568px )"), largeScreen = Modernizr.mq("only screen and ( min-device-width: 1200px )"), prevSc = 0, loaded = !1, hasFlash = !1;
try {
var fo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
fo && (hasFlash = !0)
} catch (e$$12) {
void 0 != navigator.mimeTypes["application/x-shockwave-flash"] && (hasFlash = !0)
}
function cl() {
var c = document.getElementsByTagName("body")[0];
c.className += " loaded";
example web app OAuth flow
1. Redirect users to request GitHub access (public key)
GET https://github.com/login/oauth/authorize
2. GitHub redirects back to your site
* Exchange this for an access token: (private key)
POST https://github.com/login/oauth/access_token
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl https://npmjs.org/install.sh | sh
Parse.initialize("LbGtGcj94CuXDLUzSYo4tCUX7qKrBq8AXy2F6lF3", "P8NkRtbeGe7a7BgbCRBsMEbZgmo7zN3vlhmQW3sk");
var InputObj = Parse.Object.extend("InputObj");
var inputObj = new InputObj();
var saveToParse = function(inputVal){
inputObj.save({input: inputVal}, {
success: function(object) {
console.log("saved data to parse.com");
}
});
@brianyang
brianyang / module-pattern.js
Created April 15, 2013 22:32
module pattern
var MODULE = (function(){
// define variable in closure
var module = {}
module.UI = function(){
alert('invoked module.UI')
}
module.behavior = function(){
alert('invoked module.behavior')
}
return module
<?php
/**
* The Header for our theme.
*
* Displays all of the <head> section and everything up till <div id="main">
*
* @package WordPress
* @subpackage Twenty_Twelve
* @since Twenty Twelve 1.0
*/