Skip to content

Instantly share code, notes, and snippets.

import Control.Applicative ((<*>))
import Control.Parallel (par)
class Comonad w where
extend :: (w a -> b) -> w a -> w b
duplicate :: w a -> w (w a)
extract :: w a -> a
-- if monads are monoids on functions which produce side effects,
--
@michaelficarra
michaelficarra / getGlobal.js
Last active June 2, 2016 16:16
get the global object as reliably as possible
var getGlobal = (function(g) {
if (g == null) {
if (typeof System !== 'undefined' && System != null && System.global != null && System.global.System === System) g = System.global;
else if (typeof self !== 'undefined' && self != null && self.self === self) g = self;
else if (typeof window !== 'undefined' && window != null && window.window === window) g = window;
else if (typeof global !== 'undefined' && global != null && global.global === global) g = global;
}
return function() { return g; };
}(this));
@michaelficarra
michaelficarra / qsort.coffee
Created May 1, 2012 00:50
CoffeeScript quicksort
qsort = (list) ->
return list if list.length <= 1
pivotPoint = medianOfThree list
pivot = list[pivotPoint]
list.splice pivotPoint, 1, []
[left, right] = partition list, (e) -> e < pivot
[(qsort left)..., pivot, (qsort right)...]
medianOfThree = (list) ->
return 0 if list.length < 3
@michaelficarra
michaelficarra / rt.js
Last active February 1, 2016 01:47
Rotten Tomatoes ratings exfiltrator
console.log(JSON.stringify([].map.call(document.querySelectorAll('.content_body .media-body'), function(ratingEl){
return {
title: ratingEl.childNodes[3].childNodes[1].textContent,
year: parseInt(ratingEl.childNodes[3].childNodes[2].textContent.slice(1, -1), 10),
rt_link: ratingEl.childNodes[3].childNodes[1].href,
rating: 20 * ratingEl.childNodes[5].querySelectorAll('.glyphicon-star').length + (/½/.test(ratingEl.childNodes[5].textContent) ? 10 : 0),
};
}).sort(function(a, b){ return a.title > b.title ? 1 : -1; })));
$ eshost host --list
┌──────────────┬─────────┬──────────────────────────────────────────────────┬──────┐
│ name │ type │ path │ args │
├──────────────┼─────────┼──────────────────────────────────────────────────┼──────┤
│ nashorn │ nashorn │ /usr/java/jdk1.8.0_66/bin/jjs │ │
├──────────────┼─────────┼──────────────────────────────────────────────────┼──────┤
│ v8 │ d8 │ /usr/bin/d8 │ │
├──────────────┼─────────┼──────────────────────────────────────────────────┼──────┤
│ jsc │ jsc │ /usr/bin/jsc │ │
├──────────────┼─────────┼──────────────────────────────────────────────────┼──────┤
(function () {
var g, h;
function x() { f = ""; /* var-scoped f gets value "" */ }
function y() { g = f; /* g gets value of var-scoped f */ }
{
/* var-scoped f is undefined, let-scoped f is a function */
h = f; /* h gets value of let-scoped f, a function */
f = 1; /* let-scoped f gets value 1 */
x();
y();
@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';
}