Skip to content

Instantly share code, notes, and snippets.

View vaibhavsagar's full-sized avatar
🕺
🪩

Vaibhav Sagar vaibhavsagar

🕺
🪩
View GitHub Profile
@chrisdone
chrisdone / FieldTH.hs
Last active February 13, 2017 22:17
$(lens 'foo) -- handy one-off lens maker for record fields
{-# LANGUAGE TemplateHaskell #-}
-- | For when you have a record that doesn't have lenses derived for
-- it and you need a lens, just use @$(lens 'thefield)@ and away you go.
module Control.Lens.FieldTH where
import Language.Haskell.TH
lens :: Name -> Q Exp
lens name = do
[|\f r ->
fmap
$(lamE
@ndmitchell
ndmitchell / policies.md
Created June 12, 2017 20:55
Friendly contribution policies

This is intended as a reply to https://ro-che.info/articles/2017-06-12-friendly-contributing-policies, but I don't really want it to be a blog post (it's not the right level for my blog), and that blog doesn't have comments, and I don't want to mis-express myself in 120 characters or whatever. So here goes a gist :)

Firstly, as to the talk, the context was read around the project, and figure out if it will suit you. I am deliberately quoting haskell-src-exts out of context, and deliberately not saying where either quote came from. I appreciate the full policy is much more welcoming than that one snippet would imply.

However, when I wanted to find an unfriendly contributing policy, I immediately thought of haskell-src-exts. I do genuinely find the document, as a whole, quite unwelcoming. I appreciate that languages sound different to native speakers, and it didn't stop me contributing, but it did give me pause. Whether a document is friendly or not is a feeling, and so by explaining why I have that feeling

@aaronlevin
aaronlevin / minimal-http.hs
Last active June 27, 2017 16:37
Minimal Haskell HTTP server written on top of warp via the Web Application Interface (no frameworks)
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Network.Wai (pathInfo, Request, requestMethod, Response, responseLBS, ResponseReceived)
import Network.Wai.Handler.Warp (run)
import Network.HTTP.Types (status200, status401)
-- note: type Application = Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
application :: Request -> (Response -> IO ResponseReceived) -> IO ResponseReceived
@Profpatsch
Profpatsch / jq
Last active August 17, 2017 03:30
jq replacement (‽)
#!/usr/bin/env bash
if [[ -z "$1" ]]; then
echo "No filter given, abort"
exit 1
fi
tmp=$(mktemp -d)
jq="$tmp/jq"
@thumphries
thumphries / Getting.hs
Created October 4, 2017 12:38
Simulating first-class patterns by combining prisms into `Getting First`
{-# LANGUAGE TemplateHaskell #-}
module Lens where
import Control.Lens
import Data.Monoid (First, (<>))
data FooBar =
Foo (Either Int Bool)
| Bar (Maybe Bool)
@chrisdone
chrisdone / Drawing.hs
Last active October 7, 2017 09:12
Drawing language: first attempt
{-# LANGUAGE OverloadedStrings #-}
{-# OPTIONS_GHC -Wall #-}
-- Set your font to a monospace font which makes this character the same as the line-height: │
--
-- Otherwise, you'll see an ugly gap between connected lines if the
-- line-height of the font is high.
--
-- Example fonts:
--

The original code (~7.2s on my laptop).

import System.Random
import System.CPUTime

rainfall :: [Int] -> Int
rainfall xs = sum (zipWith (-) mins xs)
@VictorTaelin
VictorTaelin / binary_addition.md
Last active November 30, 2017 13:22
Binary addition on the abstract algorithm!

This is a term that performs modulo 32 addition on two 32-bit binary numbers efficiently on the abstract algorithm.

On this example, I compute 279739872 + 496122620 = 775862492.

binSize= 32
binZero= (binSize r.a.b.c.(a r) a.b.c.c)
binSucc= (binSize r.x.a.b.c.(x b x.(a (r x)) c) a.a)
binFold= x.a.b.c.(binSize r.x.(x x.f.(a (f x)) x.f.(b (f x)) f.c r) a.c x)
binToNat= (binSize r.n.x.(x x.f.(f x) x.f.(add n (f x)) f.0 (r (mul 2 n))) n.x.0 1)
@mpickering
mpickering / Instructions.md
Last active August 11, 2018 09:42
Using head.hackage

How to test your package with ghc-8.6.1

  1. Setup the binary cache -
cachix use mpickering

For only GHC

@frasertweedale
frasertweedale / Newton.hs
Last active March 2, 2019 14:59
Newton's method (Haskell)
{-# LANGUAGE RankNTypes #-}
import Numeric.Natural (Natural)
import Numeric.AD (diff)
newtonRoot
:: (Floating a, Ord a)
=> Natural -- ^ iterations
-> a -- ^ epsilon
-> a -- ^ starting guess