Skip to content

Instantly share code, notes, and snippets.

@michaelficarra
michaelficarra / set.prototype.map.js
Last active August 29, 2015 14:10
ES6 Set.prototype.map issue
var set = new Set([0, 1]),
f = function(x) { return 1 / x; },
g = function(x) { return x ? -0 : x; };
set.map(g); // Set{0}
set.map(g).map(f); // Set{1/0}
set.map(function(x){ return f(g(x)); }); // Set{1/0, -1/0}
@michaelficarra
michaelficarra / monads.js
Last active August 29, 2015 14:07 — forked from pselle/monads.js
function Container(val) {
this.val = val
}
// Functor's `fmap` in Haskell
Container.prototype.map = function(f) {
return new Container(f(this.val));
};
// Monad's `>>=` (pronounced bind) in Haskell
/**
* Proof of concept ESLint rule for warning about potential
* XSS vulnerabilities caused by mixing innerHTML/text node
* property access.
*
* More here: http://benv.ca/2012/10/2/you-are-probably-misusing-DOM-text-methods/
*/
'use strict';
var WARNING_MSG =
@michaelficarra
michaelficarra / matasano.hs
Created October 17, 2013 21:38
matasano crypto class notes/assignments
import Data.Char
import Data.Word
import Data.Bits
import Data.List
import Data.Maybe
import qualified Data.ByteString as B
import Codec.Crypto.AES
repeatedKeyXor = do
import Data.List (unfoldr)
import Data.Tuple (swap)
import System.IO (hSetBuffering, stdout, BufferMode(..))
placeValues base = reverse . unfoldr (\x -> if x == 0 then Nothing else Just $ swap $ divMod x base)
persistencePath base x = if x < base then [x] else x : (persistencePath base $ product $ placeValues base x)
persistence base n = length (persistencePath base n) - 1
lowestNumberSuchThat f = head $ dropWhile (not . f) [0..]
main = do
masksOfLength x = iterate (\y -> map (True:) y ++ map (False:) y) [[]] !! x
@michaelficarra
michaelficarra / github-screenshots.user.js
Last active December 19, 2015 00:49
make a github repo presentable for screenshots
// ==UserScript==
// @name Github Screenshots
// @description make a github repo presentable for screenshots
// @match https://github.com/*
// @version 0.0.1
// ==/UserScript==
function hide (node) {
node.style.display = 'none';
}
@michaelficarra
michaelficarra / index.html
Created May 18, 2013 14:32
example password strength meter using lowe/zxcvbn
<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
.meter {
width: 300px;
height: 50px;
border: 1px solid #666;
position: relative;
@michaelficarra
michaelficarra / levels.coffee
Last active December 17, 2015 00:49
identifier-only scope colouring levels
fs = require 'fs'
esprima = require 'esprima'
escope = require 'escope'
eslevels = require 'eslevels'
js = (fs.readFileSync './input.js').toString()
ast = esprima.parse js, {range: yes}
scopes = (escope.analyze ast).scopes
@michaelficarra
michaelficarra / gist:4945178
Created February 13, 2013 15:00
diagrams to keep my head straight while parsing infix binary operators
A && B || C && D
(A && B) || (C && D)
||
/ \
/ \
&& &&
/ \ / \
A B C D