Skip to content

Instantly share code, notes, and snippets.

View zeusdeux's full-sized avatar
👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em

Mudit zeusdeux

👾
i wear my sunglasses at night so i can — so i can justify the money spent on 'em
View GitHub Profile
@zeusdeux
zeusdeux / googleHurdleHack.js
Created October 6, 2012 23:04
A google hurdle hack that lets you get a time of 0.1s
/**************************************************************
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;
@zeusdeux
zeusdeux / Conversion: RGB to Hex and vice versa
Last active December 12, 2015 00:59
This gist adds two methods HexToRGB() and RGBToHex() to String and Array prototypes in JavaScript.
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));
@zeusdeux
zeusdeux / toAndFromBase62ToInt.js
Last active December 15, 2015 08:19
This gist has two methods that convert between integer and its base 62 equivalent.
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");
/* 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 */
@zeusdeux
zeusdeux / things.js
Created May 12, 2014 15:24
Things I see in production code
//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));
@zeusdeux
zeusdeux / compose.js
Last active December 25, 2019 04:04
Functional programming toolkit for javascript
//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) {
@zeusdeux
zeusdeux / Circle.js
Last active August 29, 2015 14:02
Playing with Object.observe ( try it in Canary here -> http://experiments.muditameta.com/objectObserve )
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;
@zeusdeux
zeusdeux / animated-mobile-nav.html
Last active August 29, 2015 14:03
Animation mobile nav menu button. View it on Chrome, here: http://chaicode-3lads.rhcloud.com/1iV/1
<html>
<head>
<style>
.menu-icon {
padding: 5px;
width: 30px;
height: 30px;
cursor: pointer;
text-align: center;
}
@zeusdeux
zeusdeux / sigh.js
Last active August 29, 2015 14:04
Event loop peculiarities
(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);
@zeusdeux
zeusdeux / Naive URL extraction algo
Last active August 29, 2015 14:06
Naive URL extraction (only english supported)
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 '.'