Skip to content

Instantly share code, notes, and snippets.

import Control.Applicative
import Data.Attoparsec
import Data.IORef
import System.IO.Unsafe
------------------------------------------------------------------------------
wouldSucceed :: Parser a -> Parser Bool
wouldSucceed p = do
result <- return $! unsafePerformIO (newIORef False)
(do
@duairc
duairc / fonts.css
Created February 15, 2014 02:26
Given the name of a font family, generate webfonts + a CSS file on a Linux system
#!/bin/sh
clean () {
perl -pe 's/(\([si]\)\s*)+//' | tr '"' ' ' | awk '{$1=""; print $0}' | xargs echo
}
subset () {
python /usr/share/googlefontdirectory-tools/tools/subset/subset.py --subset=latin+latin-ext+greek+greek-ext+cyrillic+cyrillic-ext --nmr --null --roundtrip --script "$1" "$2"
}
@duairc
duairc / table-rows.scss
Last active August 29, 2015 14:06
SCSS selectors for the first and last row of a table
// http://www.w3.org/TR/html5/tabular-data.html#the-table-element
@mixin first-row() {
& >,
> thead >,
> tbody:first-child >,
> caption:first-child + tbody >,
> caption:first-child ~ colgroup + tbody >,
> colgroup:first-child + tbody >,
> colgroup:first-child ~ colgroup + tbody >,
class Method
def memoize!(time = nil)
name = self.name
owner = self.owner
method = self.to_proc
self.unbind
owner.send(:define_method, name) do |*args, &block|
@results ||= {}
if !@time || (time && @time + time < Time.now)
result = method.call(*args, &block)
{-# LANGUAGE RankNTypes #-}
import Control.Lens hiding (lens)
import qualified Control.Lens as L (lens)
import Data.Bifunctor
import Data.Functor.Alt
------------------------------------------------------------------------------
split
@duairc
duairc / net.nix
Last active January 18, 2025 10:45
IP address arithmetic and validation in Nix
{ lib ? null, ... }:
let
net = {
ip = {
# add :: (ip | mac | integer) -> ip -> ip
#
# Examples:
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE NoStarIsType #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}