This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/************************************************************** | |
Author: Mudit Ameta | |
Date : 9Aug12 | |
Link : http://experiments.muditameta.com/googleHurdleHack/ | |
***************************************************************/ | |
(function () { | |
var game = document.getElementById('hplogo'); | |
var leftDown = document.createEvent("Event"); | |
leftDown.initEvent("keydown", true, true); | |
leftDown.keyCode = 37; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String.prototype.hexToRGB = function(){ | |
if (this[0] === "#" && this.length === 7){ | |
return String.prototype.hexToRGB.call(this.slice(1)); | |
} | |
if (!/^[a-fA-F\d]{6}$/.test(this) || this.length > 6){ | |
throw new SyntaxError("String is not a valid hex number"); | |
} | |
var str = "("; | |
for (var i=0; i<=this.length-2; i+=2){ | |
str+=(parseInt(this.substr(i,2),16)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function toBase62(number, arr){ | |
var list = [0,1,2,3,4,5,6,7,8,9,'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']; | |
if(!arguments.length) | |
throw new SyntaxError("toBase62: Invalid syntax. Use toBase62(number[, Array])"); | |
number = parseInt(arguments[0], 10); | |
if(isNaN(number)) | |
throw new TypeError("toBase62: First parameter needs to be a valid integer number"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* curry method */ | |
Function.prototype.curry = function() { | |
var f = this, args = [].slice.call(arguments,0); | |
return function(){ | |
return f.apply(this, args.concat([].slice.call(arguments,0))); | |
}; | |
}; | |
/* uncurryThis method */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//not sending hex values as strings to parseInt/Float | |
//This is not equal to parseInt("0xff", 16) | |
//It's actually equal to parseInt(255, 16) | |
parseInt(0xff, 16); | |
//coercing to string and the parsing back (WHY?! T_T) | |
var val = 10+""; | |
fn(parseInt(val,10)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//this function composes functions like in Haskell (and most other functional languages) | |
//the final composed function can accept parameters dictated by the chain it creates | |
//you can pass it a list of functions and it shall apply them from RIGHT to LEFT (right associativeness?) | |
//eg., c0(fn1, fn2, fn3)(10) => return fn1(fn2(fn3(10))); | |
// out<---<----<----<=10 | |
function c0(f, g) { | |
var last; | |
if (!arguments.length) return; | |
if (arguments.length === 1) return f; | |
if (arguments.length === 2) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Circle(r){ | |
var self = this; | |
var notifier = Object.getNotifier(this); | |
Object.defineProperty(this, "radius", { | |
get: function(){ | |
return r; | |
}, | |
set: function(newR){ | |
if (r === newR) | |
return; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function(){ | |
var dudeEvent = new CustomEvent('dude'); | |
var body = document.querySelector('body'); | |
body.addEventListener('dude', function(){ | |
console.log('dude listener'); | |
console.log('alerting') | |
alert('wat'); | |
}); | |
function a(){ | |
body.dispatchEvent(dudeEvent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1) Starts with http, https? Cool. Take the whole string (assuming it's good after http|https). Stop | |
2) Contains http, https? Cool. Splice string from index of 'http' ('h' to be more precise) to end of string. Stop. | |
3) Split on '.'. foldr over the array by trying to split ever element over anything that isnt an alphabet or number. Ignore 1st element of every subsplit if the subsplit returns an array of length greater than 1. After this pass, join whole array using '.' |
OlderNewer