Skip to content

Instantly share code, notes, and snippets.

/**
* 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
@michaelficarra
michaelficarra / definite-integral.hs
Created February 11, 2013 22:09
definite integral function using left Riemann sum estimation
lRiemann fn a b n
| b == a = 0
| b < a = lRiemann fn b a n
| n <= 0 = undefined
| otherwise =
let width = (b - a) / n in
let xs = init [a, a + width .. b] in
let areas = map (computeArea fn width) xs in
sum areas
where
@michaelficarra
michaelficarra / .vimrc
Created January 30, 2013 21:48
CPSA syntax highlighting for vim; based on scheme.vim
" CPSA
au BufRead,BufNewFile *.cpsa set ft=cpsa