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 / README.md
Last active August 28, 2015 08:59 — forked from HenrikJoreteg/README.md
Minimalist routing in Redux

Why would you want to do this? Because you often don't need more. It's nice to not have to think about your "router" as this big special thing.

Instead, with this approch, your app's current pathname is just another piece of state, just like anything else.

This also means that when doing server-side rendering of a redux app, you can just do:

var app = require('your/redux/app')
var React = require('react')
@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 / 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 '.'
@zeusdeux
zeusdeux / objToArray.js
Last active August 29, 2015 14:08
Convert arbitrary js objects into an array of array of array and so on while keeping the keys close to their values
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function objToArray(obj){
if (!isObject(obj) || Array.isArray(obj)) throw new SyntaxError('Give me an object to work with plz. kthxbai.');
return output = Object.keys(obj).map(function(key){
var temp = [];
temp.push(key);
if (isObject(obj[key]) && !Array.isArray(obj[key])) temp.push(objToArray(obj[key]));
else temp.push(obj[key]);
@zeusdeux
zeusdeux / thunkify.js
Created December 22, 2014 13:19
Didjoo even thunk that woulda happnd?
function thunkify(fn) {
return function() {
return fn.apply(this, arguments);
}
}
@zeusdeux
zeusdeux / Boop.md
Last active August 29, 2015 14:17
Todo at hacker school

Stuff to work on at Hacker School

Broadly:

  • Interpreters
    • one for scheme as a gateway drug into the land of interpreters
    • one for my own interpreted language
  • Compilers
    • one for my own compiled language
  • Languages to move from play -> work
@zeusdeux
zeusdeux / Syntax
Last active August 29, 2015 14:18
RC LANG
// sugared fib is below
fib n
let one = 1
if n == 0
then
one
else
if n == 1
then
one