Skip to content

Instantly share code, notes, and snippets.

@cowboy
cowboy / reminder.js
Created September 3, 2014 15:36
JavaScript: don't forget about indirect eval, kiddos
(function(){ console.log( eval('this') ); }.call({a:1}))
// Object {a: 1}
(function(){ console.log( (0,eval)('this') ); }.call({a:1}))
// Window {top: Window, window: Window, location: Location, external: Object, chrome: Object…}
@cowboy
cowboy / 1.usage.js
Created August 20, 2014 18:11
Lazy binding of "this" for inherited JavaScript instance methods
// Let's assume we've got a situation where there's going to be a lot of
// binding, eg. doSomethingWith(myThing.getProp.bind(myThing)); and we want
// to simplify app code by reducing the number of times .bind(myThing) gets
// called.
var myThing = new Thing("Test");
myThing.getProp() // "Test"
myThing.getProp.call(null) // "Test"
myThing.setProp("Another Test");
@cowboy
cowboy / awesome.js
Created August 12, 2014 15:18
this code from amazon.com's source is... well, just... what web development is all about
document.write = (function(write){
var override = function() {
if(document.readyState !== "loading") { // document has finished loading - we want to intercept this call to document.write
if (window.ueLogError) {
try {
throw new Error("`document.write` called after page load on the gateway.");
}
catch(e) {
ueLogError(e, { logLevel : 'ERROR', attribution: 'gw-third-party-js' });
}
@cowboy
cowboy / HoxHudTweakData.lua
Last active August 29, 2015 14:04
My Steam\steamapps\common\PAYDAY 2\HoxHud\HoxHudTweakData.lua file
--[[
This is the configuration file for HoxHud. Please be careful editing values as you can cause the game to crash upon loading if a value is made invalid
We recommend colorpicker.com if you want to choose a color to use. The game also has some predefined colors and they are used here purely for brevity.
Only the following Colors are defined explicitly:
Color.red (FF0000), Color.green(00FF00), Color.blue (0000FF), Color.cyan (0000FF), Color.purple(FF00FF), Color.black (000000), Color.white (FFFFFF), Color.yellow (FFFF00)
]]--
HoxHudTweakData = class()
@cowboy
cowboy / leds-cycle.js
Created May 29, 2014 21:26
node.js + johnny-five @ jsconf 2014
var j5 = require('johnny-five');
var Leds = require('./leds').Leds;
var board = new j5.Board();
var delay = 20;
var leds;
board.on('ready', function() {
leds = new Leds(4, 13);
var button = new j5.Button(2);
@cowboy
cowboy / not-grunt-init.sh
Created May 7, 2014 21:01
Grunt: Look, I re-integrated grunt-init back into grunt. Here ya go, @rwaldron
# (Include this function in your .bashrc)
# If the first argument is "init" or begins with "init:", run grunt-init.
# Otherwise run grunt.
function grunt() {
if [[ "$1" =~ ^init: ]]; then
grunt-init "${1##init:}" "${@:2}"
elif [ "$1" == "init" ]; then
grunt-init "${@:2}"
else
@cowboy
cowboy / wat.js
Created April 25, 2014 19:52
why do i do this kind of thing
(function() {
var $=['_'].concat(Array(arguments.length-1),'return _');
var _=Function.apply(null,$);
$.forEach.call(arguments,function($,$$){_[$$]=$});
return $.map.bind.call($.map,_,_);
}(5,6,7,8))()
@cowboy
cowboy / AutoHotkey.ahk
Created April 17, 2014 02:06
AutoHotkey Misc
SoundPlay *64
; =============
; Edit & Reload
; =============
!^+F12::
Edit
Reload
return
@cowboy
cowboy / inception.js
Last active May 5, 2024 09:10
JavaScript: inception(inception);
function inception(f) {
try {
return 'recursion puts the "' + f.name + '" in "' + f(f) + '"';
} catch (e) {
return '';
}
}