Skip to content

Instantly share code, notes, and snippets.

View danidiaz's full-sized avatar

Daniel Díaz Carrete danidiaz

View GitHub Profile
@CMCDragonkai
CMCDragonkai / snoclist.hs
Last active August 3, 2023 16:47
Haskell: SnocList - just a list with its head up its ass
{-# TypeOperators #-}
data SnocList a = Lin | SnocList a :> a
listToSnocList :: [a] -> SnocList a
listToSnocList [] = Lin
listToSnocList (x : xs) = listToSnocList xs :> x
snocListToList :: SnocList a -> [a]
snocListToList Lin = []
@aaronlevin
aaronlevin / proxy-aeson.hs
Created February 17, 2015 17:36
Use `Data.Reflection` to deserialized type-encoded json strings into `Proxy`
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
module Main where
import Control.Monad
import Data.Aeson
import qualified Data.Aeson as A
@nkpart
nkpart / Err.hs
Last active August 20, 2022 01:20
Lens, Prisms, and Errors.
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE TemplateHaskell #-}
{-# OPTIONS_GHC -fwarn-missing-methods #-}
module Err where
import Control.Lens
import Control.Monad.Error
import Control.Monad.Error.Lens
-- Here is a fairly typical situation, where we have low level errors in certain
@puffnfresh
puffnfresh / reornament.idr
Last active September 15, 2018 21:20
Algebraic Ornaments!
module reornament
-- Idris translation of Agda code:
-- https://gist.github.com/gallais/e507832abc6c91ac7cb9
-- Which follows Conor McBride's Ornaments paper:
-- https://personal.cis.strath.ac.uk/conor.mcbride/pub/OAAO/Ornament.pdf
ListAlg : Type -> Type -> Type
ListAlg A B = (B, A -> B -> B)
#! /bin/bash
# http://linuxcommand.org/wss0150.php
function error_exit
{
echo "$1" 1>&2
exit 1
}
# http://unix.stackexchange.com/questions/70859/why-doesnt-sudo-su-in-a-shell-script-run-the-rest-of-the-script-as-root
@tel
tel / T.hs
Last active August 29, 2015 14:06
Transducers with explicit local state
{-# LANGUAGE GADTs, RankNTypes #-}
import Control.Applicative
import Control.Category
import Data.List (foldl')
import Data.Profunctor
import Prelude hiding ((.), id)
-- | Explicit state-passing Moore machine
data Moore i o where
@zeroows
zeroows / CORSFilter.java
Last active October 4, 2022 11:44
To enable CORS support in Spring MVC 4 - Access-Control-Allow-Origin
package com.alkhodiry.mb.rest.filters;
import java.io.IOException;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
@evancz
evancz / Haskell-Style-Guide.md
Last active March 23, 2023 15:27
A style guide for Elm tools

Haskell Style Guide for Elm

Goal: a consistent style throughout all Elm projects that is easy to read and produces clean diffs to make debugging easier. This means valuing regularity and simplicity over cleverness.

Line Length

Keep it under 80 characters. Going over is not the end of the world, but consider refactoring before you decide a line really must be longer.

Variables

#! /bin/bash
# http://linuxcommand.org/wss0150.php
function error_exit
{
echo "$1" 1>&2
exit 1
}
if [ `whoami` = root ]; then
@danidiaz
danidiaz / dokerx11.sh
Last active October 17, 2015 06:46
Docker & X11 shenanigans
docker run centos yum install -y xorg-x11-xauth xeyes
docker ps -l
docker commit zzzzzzzzzz centos:xeyes
docker run -v $HOME:/hosthome:ro -e XAUTHORITY=/hosthome/.Xauthority -e DISPLAY=$DISPLAY centos cat /hosthome/.Xauthority
docker run -v $HOME:/hosthome:ro -e XAUTHORITY=/hosthome/.Xauthority -e DISPLAY=$(echo $DISPLAY | sed "s/^.*:/$(hostname -i):/") centos:xeyes xeyes