Skip to content

Instantly share code, notes, and snippets.

View alexpeits's full-sized avatar

Alex Peitsinis alexpeits

View GitHub Profile
@aspiwack
aspiwack / lhs2tex-mode.el
Created November 19, 2020 13:08
An Emacs configuration to colour Haskell code blocks in lhs2tex
;; I wrote a bit of Emacs configuration (which can be added to your
;; init.el) so that an lhs2tex file can be syntax-highlighted as a
;; Latex file but the Haskell code is highlighted as Haskell code. In
;; fact it's a little more than this, as the code blocks are
;; interpreted with the haskell-mode, so you can use your haskell
;; commands there.
;;
;; I don't recommend opening all `.lhs' file in this mode, as they
;; don't need to be Latex files. Literate Haskell is really agnostic
;; about its surrounding language.
@domenkozar
domenkozar / README.md
Created June 23, 2020 08:18
Haskell + GitHub Actions + Cachix
{-# LANGUAGE DeriveFunctor, DeriveFoldable, DeriveTraversable, TypeFamilies, TemplateHaskell #-}
import Data.Functor.Foldable
import Data.Functor.Foldable.TH
import Data.Functor.Compose
-- Example type
data Exp
= IntValue Int
| Sum Exp Exp
@arianvp
arianvp / example.sh
Last active March 5, 2023 10:34
Declaratively manage packages without NixOS or home-manager
# add your package set to your existing environment (together with the things you installed imperatively)
$ nix-env -i -f ./packages.nix
# More declarative: _replace_ your environment with _exactly_ what is in ./packages.nix
$ nix-env --set -f ./packages.nix
# Show previous versions
$ nix-env --list-generations
# Rollback
$ nix-env --rollback
@chrisdone
chrisdone / 0_Named.hs
Last active November 9, 2019 10:31
Simplified Ghost of Departed proofs
-- | Our main engine for naming a value, then we can prove properties about a named value.
{-# LANGUAGE ExistentialQuantification #-} -- Used for SomeNamed.
{-# LANGUAGE PatternSynonyms #-} -- Used for the Name pattern.
{-# LANGUAGE ViewPatterns #-} -- Used for the Name pattern.
{-# LANGUAGE RankNTypes #-} -- Used for withName.
module Named ( Named, pattern Name, forgetName, withName, someNamed, SomeNamed(..) ) where
-- | Give a generated type-level name to any value.
@sjoerdvisscher
sjoerdvisscher / moorelens.hs
Last active December 5, 2019 09:24
Moore machines as lenses
{-# LANGUAGE ScopedTypeVariables, RankNTypes #-}
import Control.Lens -- from `lens`
import Control.Monad.State.Lazy
moore :: MonadState s m => Lens s s b a -> Traversal as bs a b -> as -> m bs
moore l trav = trav (\a -> l <<.= a)
runMoore :: Lens s s b a -> s -> [a] -> [b]
runMoore l s fa = evalState (moore l traverse fa) s
@purcell
purcell / taskqueues.sql
Last active March 19, 2021 08:35
Easy task queues using PostgreSQL
-- Let's say you have a table full of work:
CREATE TABLE tasks (
id UUID PRIMARY KEY NOT NULL DEFAULT gen_random_uuid(),
status TEXT NOT NULL DEFAULT 'pending',
payload JSON NOT NULL, -- or just have meaningful columns!
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);
@i-am-tom
i-am-tom / Main.hs
Last active June 27, 2019 14:07
Using Higgledy to create parser fallbacks.
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Main where
import Control.Applicative (Alternative (..))
@phadej
phadej / SysF.hs
Last active June 16, 2019 21:11
Someone asked whether you can model SystemF(omega) in Haskell. I think you can.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
require 'cgi'
require 'active_support'
def verify_and_decrypt_session_cookie(cookie, secret_key_base = Rails.application.secret_key_base)
config = Rails.application.config
cookie = CGI::unescape(cookie)
salt = config.action_dispatch.authenticated_encrypted_cookie_salt
encrypted_cookie_cipher = config.action_dispatch.encrypted_cookie_cipher || 'aes-256-gcm'
# serializer = ActiveSupport::MessageEncryptor::NullSerializer # use this line if you don't know your serializer
serializer = ActionDispatch::Cookies::JsonSerializer