Skip to content

Instantly share code, notes, and snippets.

@epicallan
epicallan / Cont.hs
Created September 2, 2019 14:11 — forked from evansb/Cont.hs
Continuation Passing Style in Haskell
{-# LANGUAGE InstanceSigs #-}
import Control.Applicative
import Control.Monad
import Control.Monad.Trans.Writer
-- Here is a direct style pythagoras function
-- There are two noticeable things in the function body.
-- 1. Evaluation order of x * x vs y * y is unknown/implicit.
-- 2. We don't care what happens to the final value (implicit continuation).
pyth :: (Floating a) => a -> a -> a
-- | simple generic implementation
simpleHttp :: (MonadThrow m, HttpNetwork m User) => Id -> m ()
simpleHttp = error "do me..."
-- | Implemenation from well-typed article
simpleHttp
:: (MonadThrow m, Throws HTTPException, Throws DBException, HttpNetwork m User)
=> Id -> m ()
simpleHttp = error "do me..."
-- | example of monadic effectful code that can throw multiple errors
simpleHttp
:: forall m . (ThrowsMany m '[ HTTPException, DBException ], HttpNetwork m User)
=> Id -> m User
simpleHttp userId = do
user <- getHttp userId
case uId user of
x | x == userId -> pure user
| x == "Null" -> throwChecked DBException
| otherwise -> throwChecked HTTPException
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE TypeFamilies #-}
module Checked where
import Data.Kind (Type, Constraint)
import Control.Exception.Safe
{-
This is an extended take and exploration on implementing Checked exemptions in haskell
@epicallan
epicallan / timestamp.hs
Created August 7, 2019 07:03 — forked from parsonsmatt/timestamp.hs
How long is your Template Haskell taking to run?
timestamp :: String -> Q a -> Q a
timestamp name action = do
start <- runIO getCurrentTime
runIO $ putStrLn $ "Starting " <> name <> ": " <> show start
a <- action
end <- runIO getCurrentTime
runIO $ do
putStrLn $ "Ending " <> name <> ": " <> show end
putStrLn $ "Elapased " <> name <> ": " <> show (diffUTCTime end start)
pure a
@epicallan
epicallan / _FP reading lists.md
Created July 4, 2019 16:49 — forked from danidiaz/_FP reading lists.md
assorted reading lists

A series of reading lists mostly related to functional programming.

@epicallan
epicallan / History|-5a6d6a43|entries.json
Last active November 15, 2022 15:16
Visual Studio Code Settings Sync Gist
{"version":1,"resource":"file:///Users/allan/apps/30-seconds/src/components/FrontPage/index.tsx","entries":[{"id":"m0FV.tsx","timestamp":1649923532589},{"id":"XzZD.tsx","timestamp":1649924691362},{"id":"5ZaR.tsx","source":"undoRedo.source","timestamp":1649924725895},{"id":"mlTF.tsx","timestamp":1649924995849},{"id":"9t2x.tsx","timestamp":1649925163927},{"id":"NwOV.tsx","timestamp":1649925174270}]}
@epicallan
epicallan / index.html
Created May 20, 2017 14:15 — forked from nolanlawson/index.html
IndexedDB with Web Workers
<html>
<body>
<span id="output"></span>
</body>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="main.js"></script>
</html>
@epicallan
epicallan / wordpress-change-domain-migration.sql
Created April 11, 2017 08:12 — forked from chuckreynolds/wordpress-change-domain-migration.sql
Use this SQL script when changing domains on a WordPress site. Whether you’re moving from an old domain to a new domain or you’re changing from a development domain to a production domain this will work. __STEP1: always backup your database. __STEP2: change the ‘oldsite.com’ and ‘newsite.com’ variables to your own. __STEP3: make sure your databa…
SET @oldsite='http://oldsite.com';
SET @newsite='http://newsite.com';
UPDATE wp_options SET option_value = replace(option_value, @oldsite, @newsite) WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET post_content = replace(post_content, @oldsite, @newsite);
UPDATE wp_links SET link_url = replace(link_url, @oldsite, @newsite);
UPDATE wp_postmeta SET meta_value = replace(meta_value, @oldsite, @newsite);
/* only uncomment next line if you want all your current posts to post to RSS again as new */
#UPDATE wp_posts SET guid = replace(guid, @oldsite, @newsite);
@epicallan
epicallan / csv2sqlite
Created April 7, 2017 05:25
csv2sqlite
#!/usr/bin/env python
#
# A simple Python script to convert csv files to sqlite (with type guessing)
#
# @author: Rufus Pollock
# Placed in the Public Domain
# Bug fixes by Simon Heimlicher <[email protected]> marked by `shz:'
from __future__ import print_function