Skip to content

Instantly share code, notes, and snippets.

berdario

Block or report user

Report or block berdario

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@berdario
berdario / dummyhttp.py
Created Dec 7, 2014
A toy HTTP server in pure Python3 I wrote in September 2013
View dummyhttp.py
#! /usr/bin/env python
import sys
import os
import locale
from collections import defaultdict
from socket import socket, AF_INET, SOCK_STREAM
from urllib.parse import urlparse
from contextlib import closing
from functools import wraps
@berdario
berdario / Transpose.java
Created Sep 3, 2018
Java type errors can be nasty
View Transpose.java
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 / fibs.hs
Created Sep 3, 2018
expansion of a recursive fibs impl
View fibs.hs
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 / obfuscate_curl.py
Created Aug 19, 2018
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
View obfuscate_curl.py
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)]
View spock.hs
#!/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
Javascript sum types performance test
View perf.js
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;
}
View bisect_tests.hs
#!/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)
View -
* Checking your package using psc-publish...
There is a problem with your package, which meant that it could not be
published.
Details:
Compile error:
View Example.hs
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
module Example where
import Control.Exception
import Control.Monad
import Control.Monad.Error.Class
View p1.py
#!/usr/bin/env python
import sys
import argparse
def mkvirtualenv_argparser():
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--python')
parser.add_argument('-i', action='append', dest='packages', help='Install \
a package after the environment is created. This option may be repeated.')
You can’t perform that action at this time.