Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / InTimeZone.hs
Last active Jul 30, 2020
I should put this somewhere
View InTimeZone.hs
module Main where
import Data.Time (TimeZone, ZonedTime, utcToZonedTime, zonedTimeToUTC)
import Data.Time.Format.ISO8601 (iso8601ParseM)
import System.Environment (getArgs)
inTimeZone :: TimeZone -> ZonedTime -> ZonedTime
inTimeZone timezone = utcToZonedTime timezone . zonedTimeToUTC
main :: IO ()
View IntervalSets.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# OPTIONS_GHC -Wall #-}
module IntervalSets where
import Control.Arrow ((&&&))
import Control.Monad (filterM)
import Control.Monad.State (evalState, get, modify)
import Control.Monad.Trans.State (StateT (StateT), evalStateT)
@bradparker
bradparker / styled.rb
Last active Jun 7, 2020
Sketch of ViewComponent::Styled API
View styled.rb
module ViewComponent
module Styled
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def styled(static = [], &block)
@static_styles = static
@dynamic_styles = block
@bradparker
bradparker / index.html
Last active Mar 31, 2020
WebCrypto based SRP
View index.html
<!DOCTYPE html>
<html>
<head>
<title>SRP</title>
<meta charset="utf8" />
</head>
<body>
<script type="module">
import { modPow } from "https://unpkg.com/bigint-mod-arith@1.3.1/src/main.js";
View SKI.hs
{-# LANGUAGE RankNTypes #-}
-- Prelude> :set -XTypeApplications
-- Prelude> :t id
-- id :: a -> a
-- Prelude> :t const
-- const :: a -> b -> a
-- Prelude> :t (<*>) @((->) _)
-- (<*>) @((->) _) :: (w -> a -> b) -> (w -> a) -> w -> b
@bradparker
bradparker / Networking.hs
Last active Dec 8, 2019
Low-level Networking in Haskell (largely C so far)
View Networking.hs
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall #-}
module Main where
@bradparker
bradparker / iterate.js
Last active Nov 1, 2019
Flattening nested iterators ... for use with weird DynamoDB scan API
View iterate.js
const testItems = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
const limit = 2;
const getBatch = (cursor = null) => {
const currentCursor = cursor || 0;
const nextPotentialCursor = currentCursor + limit;
const nextCursor = nextPotentialCursor > 10 ? null : nextPotentialCursor;
return new Promise(resolve =>
setTimeout(() => resolve({
@bradparker
bradparker / Ind.hs
Created Jul 28, 2019
Trying to figure out B. Milewski's slide from Lambda Jam 2019
View Ind.hs
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeApplications #-}
{-# OPTIONS_GHC -Wall #-}
@bradparker
bradparker / Refined.ts
Last active Jul 25, 2019
Refinement type-y kinda things
View Refined.ts
interface Refinement<A> {
tag: string;
value: A;
}
interface Refined<A, R> {
value: A;
refinement: R;
}
View Bits.hs
import Control.Monad.State
import Data.Traversable
import Data.Tuple
toByteBits :: Integral n => n -> [n]
toByteBits =
evalState (for [1..8] (\_ -> state (\s -> swap (divMod s 2))))
main = do
print $ toByteBits 1
You can’t perform that action at this time.