Skip to content

Instantly share code, notes, and snippets.

View JamesMGreene's full-sized avatar

James M. Greene JamesMGreene

View GitHub Profile
@jlongster
jlongster / gist:3881008
Created October 12, 2012 19:28
js destructuring macro
// Note: there are bugs in hygienic renaming, so this doesn't work all the time yet.
macro varr {
case [$var (,) ...] = $expr => {
var i = 0;
var arr = $expr;
$(var $var = arr[i++];) ...
}
@valueof
valueof / notabs.js
Created October 13, 2012 18:12
A reporter that discards all warnings about mixed tabs and errors
/**
* notabs.js
*
* A reporter that discards all warnings about mixed tabs and errors.
* This file was based on our default reporter so output is the same.
*
* Usage:
* jshint myfile.js --reporter=notabs.js
*/
@domenic
domenic / promises.md
Last active March 31, 2024 14:07
You're Missing the Point of Promises

This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.

You're Missing the Point of Promises

Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:

getTweetsFor("domenic", function (err, results) {
 // the rest of your code goes here.
@dunkfordyce
dunkfordyce / gist:4065345
Created November 13, 2012 11:38
Convert single line comments in javascript to console.log statements with esprima/falafel/javascript
var falafel = require('falafel');
var src = require('fs').readFileSync(process.argv[2]).toString();
var output = falafel(src, {comment: true}, function (node) {
if (node.type === 'Line') {
node.update('console.log("COMMENT:' + node.value + '");');
}
});
console.log(output);
@unscriptable
unscriptable / AMD-factory-with-require.js
Created November 20, 2012 15:11
Simple AMD/node boilerplate. These aren't quite "normal" AMD and aren't "pure" CJS, but work in AMD loaders and node-like environments (like RingoJS).
// Typical AMD factory that returns a value, but uses an r-value (sync) require(),
// rather than a long, awkward dependency list.
// You cannot use module.exports or exports to declare the module:
(function (define){
define(function (require) {
"use strict";
var mod = require('pkb/modA');
return {
@JamesMGreene
JamesMGreene / globalErrorHandlerHookup.js
Created November 29, 2012 21:52
jQuery event handlers to prevent logging after the window goes crazy! =)
(function($, window, undefined) {
// WARNING! Set this as you see fit
var suppressUnhandledErrors = true;
var okToLogErrors = true;
var isOnline = true;
var offlineErrorQueue = [];
var logError = function(err) {
@getify
getify / 1.md
Created November 30, 2012 12:04
rethink how javascript "inheritance" ACTUALLY works...

JavaScript does not have "inheritance" or "prototypal inheritance" or "classes" or any of that jazz... what you've been told, and how you've been taught about it, are a misunderstanding... all this nonsense about constructor functions and new and such... that's all hogwash... well, it's all unnecessary effort, at best.

"Instead... only try to realize the truth... there is no spoon."

What JavaScript does have is "behavior delegation"... and object linking through the "prototype chain"... you merely link two instances of objects together, say Foo and Baz, and say that Baz "delegates" to Foo for any behavior that Baz doesn't own itself but that Foo does own. And thus, any object b (aka, "b is an instance of Baz" in the more confusing terminology) which is linked to Baz, delegates first to Baz, and then to Foo, for behavior.

That's it. Seriously. And function constructors and new and all that stuff, everything you've read before about OO in JS, they're just distractions that lea

@vitallium
vitallium / fix_compile_vs2012
Created December 4, 2012 06:46
[PhantomJS] Patch for compiling using VS2012
diff --git a/src/qt/mkspecs/win32-msvc2010/qmake.conf b/src/qt/mkspecs/win32-msvc2010/qmake.conf
index 036c522..ea2ddb0 100644
--- a/src/qt/mkspecs/win32-msvc2010/qmake.conf
+++ b/src/qt/mkspecs/win32-msvc2010/qmake.conf
@@ -9,7 +9,7 @@ TEMPLATE = app
CONFIG += qt warn_on release incremental flat link_prl precompile_header autogen_precompile_source copy_dir_files debug_and_release debug_and_release_target embed_manifest_dll embed_manifest_exe
QT += core gui
DEFINES += UNICODE WIN32 QT_LARGEFILE_SUPPORT
-QMAKE_COMPILER_DEFINES += _MSC_VER=1600 WIN32
+QMAKE_COMPILER_DEFINES += _MSC_VER=1700 WIN32
anonymous
anonymous / dict-ie.js
Created December 28, 2012 07:12
old IE shim for creating empty dict objects
// pre-ES5 IE version
var dict = (function() {
var PROPERTY_KEYS = [
"hasOwnProperty",
"isPrototypeOf",
"propertyIsEnumerable"
"valueOf",
"toString",
"toLocaleString",
"constructor"
javascript:(function(e,a,g,h,f,c,b,d)%7Bif(!(f=e.jQuery)%7C%7Cg%3Ef.fn.jquery%7C%7Ch(f))%7Bc=a.createElement(%22script%22);c.type=%22text/javascript%22;c.src=%22http://ajax.googleapis.com/ajax/libs/jquery/%22+g+%22/jquery.min.js%22;c.onload=c.onreadystatechange=function()%7Bif(!b&&(!(d=this.readyState)%7C%7Cd==%22loaded%22%7C%7Cd==%22complete%22))%7Bh((f=e.jQuery).noConflict(1),b=1);f(c).remove()%7D%7D;a.documentElement.childNodes%5B0%5D.appendChild(c)%7D%7D)(window,document,%221.3.2%22,function($,L)%7B$('%23header,%20.pagehead,%20.breadcrumb,%20.commit,%20.meta,%20%23footer,%20%23footer-push,%20.wiki-actions,%20%23last-edit,%20.actions,%20.header').remove();%20$('%23files,%20.file').css(%7B%22background%22:%22none%22,%20%22border%22:%22none%22%7D);%20$('link').removeAttr('media');%7D);