Skip to content

Instantly share code, notes, and snippets.

View erewok's full-sized avatar

Erik erewok

View GitHub Profile
@erewok
erewok / Spammer.hs
Last active August 29, 2015 14:03
Haskell: Pulling IP Addresses from Django Tracebacks
module Main where
import Control.Applicative
import Data.List
import System.Environment
data IpAddress = IpAddress String
deriving (Show, Eq, Ord)
data IpTree = Leaf
@erewok
erewok / py3-test-server.py
Last active August 29, 2015 14:04
Python3 Test Server Implementation
"""Python3 Test Server
Test server implementation: any get/post request returns all variables
and headers or a JSON fixture. Requests for JSON fixtures must include a
"json_response" header with file-location value, or a _final_ query parameter
of "json_response=file_loc.json". The test-server will attempt to open the
file requested and serve that as a json response. If it cannot find the file,
it raises an exception.
This has been designed so that it is easy to test API-request and processing.
#!/usr/local/bin/python3
from random import choice, randint
import sys
all_letters = "abcdefghijklmnñopqrstuvwxyz"
vowels = "aeiouy"
suffix = "bertos"
consonants = list(filter(lambda x: x not in vowels, all_letters))
@erewok
erewok / taco_shop_name.hs
Created August 2, 2014 23:35
Taco Shop Namer in Haskell
-- run to find out your taco shop name
import System.Random
import Control.Monad.State.Lazy
all_let :: [Char]
all_let = ['a'..'z']
vowels :: [Char]
vowels = "aeiouy"
@erewok
erewok / json_utils.py
Last active August 29, 2015 14:05
Dealing with Nested Json
from functools import wraps
def qfind(json_dict, key):
"""Return generator of dicts filtered from `json_dict` that contain `key`.
Recursive method for finding nested dictionaries anywhere in a dictionary
given a key which may or may not be in the dictionary.
This function actually returns the `parent` dictionary that contains a
particular key. Consider the following example::
@erewok
erewok / Main.hs
Last active November 10, 2015 03:37
Moving Average Test: Uses Conduits
{-# LANGUAGE MultiWayIf #-}
module Main where
import Control.Monad.IO.Class (liftIO)
import Data.Conduit (($$), (=$=), (=$)
, Conduit, Sink, Source
, await, yield)
import qualified Data.Conduit.List as CL
import Data.Sequence
@erewok
erewok / Adders.hs
Created March 2, 2016 23:27
Working to implement binary adders in Haskell
module Adders (
Binary(..)
, halfAdder
, adder
) where
import Data.Monoid
data Binary = Zero
| One
@erewok
erewok / Api.hs
Last active July 7, 2018 20:08
Haskell Servant Persistent Example
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE OverloadedStrings #-}
module Api where
import Control.Monad.Reader (ReaderT, runReaderT)
import Control.Monad.Trans.Either (EitherT)
import Data.Int (Int64)
import Servant
@erewok
erewok / install_stack.sh
Created April 25, 2017 05:10
install stack for travis
set -o errexit -o verbose
if test -f "$HOME/.local/bin/stack"
then
echo 'Stack is already installed.'
else
echo "Installing Stack for $TRAVIS_OS_NAME..."
URL="https://www.stackage.org/stack/$TRAVIS_OS_NAME-x86_64"
curl --location "$URL" > stack.tar.gz
gunzip stack.tar.gz
@erewok
erewok / servant_custom_error.hs
Last active April 28, 2017 14:51
Custom Error as JSON from inside Handler
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
module Api.Post
(
PostApi