Skip to content

Instantly share code, notes, and snippets.

@mrkgnao
mrkgnao / ghostscript-pdf-crop.sh
Created October 8, 2018 16:32
Crop pdfs with GhostScript
#!/usr/bin/env bash
set -euo pipefail
origdir=$(pwd)
tmpdir=$(mktemp -d)
echo "tmpdir: $tmpdir"
read -r width height < <(pdfinfo $1 | grep "Page size:" | sed 's/[a-zA-Z: ]*\([0-9]\+\)[x ]*\([0-9]\+\).*/\1 \2/')
npages=$(pdfinfo $1 | grep "Pages:" | sed 's/Pages: \+\([0-9]\+\).*/\1/')
echo "page count: $npages"
echo "(width, height) = ($width, $height)"
@mrkgnao
mrkgnao / spacemacs-tikz-preview.el
Last active January 23, 2024 20:51
TikZ preview in Emacs
;; In Spacemacs, this sets up:
;; - LaTeX previews (in \(...\) or \[...\]) with `, T x`
;; - TikZ preview (inside #+BEGIN_LaTeX ... #+END_LaTeX blocks) with C-c C-c
;;
;; All previews and exports use AMS Euler, which I like, and a suitable text
;; font to go with it.
;;
;; Other libraries (xy and so on) should also work if you add them to the
;; org-latex-packages-alist lines below.
;;
@mrkgnao
mrkgnao / IosevkaConfigGen.hs
Last active November 8, 2022 18:28
Render Iosevka ligatures to Private Use Area glyphs, for Emacs
{-# LANGUAGE RecordWildCards, Arrows #-}
import Numeric
import Data.Char
import Control.Monad
import Data.Monoid ((<>))
import Data.List (nub, sort, reverse)
data RepeatBounds = RB
@mrkgnao
mrkgnao / Neural.idr
Last active July 30, 2022 15:00
A quick Idris implementation of @mstksg's "dependent Haskell" neural networks
module Main
import Data.Vect
-- %hide transpose
dot : Num a => Vect n a -> Vect n a -> a
dot va vb = foldr (+) 0 $ zipWith (*) va vb
Matrix : (rows : Nat) -> (cols : Nat) -> Type -> Type
@mrkgnao
mrkgnao / futures.rs
Created March 1, 2020 15:06
oh so this is how futures work, huh
use futures::prelude::*;
use futures::task::{Context, Poll};
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use tokio::time;
enum Noise {
PollMe,
WakeMe,
}
@mrkgnao
mrkgnao / ClientMain.hs
Created November 12, 2019 17:23
modified isomorphic miso example for dmjio
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
module Main where
import qualified Common
import Data.Proxy ( Proxy(..) )
import Control.Lens ( (^.), (+=), (-=), (.=), makeLenses )
import qualified Servant.API as S
import Servant.API ( (:<|>)(..) )
@mrkgnao
mrkgnao / Eftee.hs
Last active September 23, 2019 15:43
An "optimized" version of ElvishJerricco's free arrow type
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
@mrkgnao
mrkgnao / Liege.hs
Last active August 27, 2019 18:11
Servant handled using free monads of coproducts of functors :)
{-# LANGUAGE ApplicativeDo #-}
{-# LANGUAGE ConstrainedClassMethods #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE IncoherentInstances #-}
{-# LANGUAGE InstanceSigs #-}
@mrkgnao
mrkgnao / MiniTodo.md
Last active October 19, 2018 21:38
A stripped-down Todo app in Reflex with lots of comments from Learn Reflex

MiniTodo

A heavily-commented, partly modified version of the stripped-down Reflex todo list from reflex-examples.

{-# LANGUAGE RecursiveDo, OverloadedLists, ScopedTypeVariables, OverloadedStrings  #-}

{-
 - A heavily-commented, partly modified version of the stripped-down Reflex todo list from reflex-examples
 -}
@mrkgnao
mrkgnao / Fmap.hs
Created March 13, 2018 08:36
@ekmett's iterated fmap
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Fmap where
import Control.Category ((<<<), (>>>))
import Prelude hiding (map)
type Reader = (->)