Skip to content

Instantly share code, notes, and snippets.

View JustusAdam's full-sized avatar

Justus Adam JustusAdam

View GitHub Profile
@JustusAdam
JustusAdam / iterator_quantifiers.rs
Last active October 9, 2023 19:17
Monad-like quantifiers for Rust
/// Monadic quantifiers for Rust iterators.
///
/// Allows you to pseudo-monadically create a `bool` computation with iterators.
/// It exposes the iterator methods `any` and `all` as prefix bindings and also
/// enables pattern matching and guarding.
///
/// The macro expands a sequence of statements. All usual Rust statements are
/// supported and only the top-level statements are expanded with the special
/// syntax, not e.g. nested blocks.
///

Keybase proof

I hereby claim:

  • I am justusadam on github.
  • I am justusad (https://keybase.io/justusad) on keybase.
  • I have a public key ASDFvBohqMmxS4-GP7xXP3c7K2VSNY-TNjcKEDag4quf3wo

To claim this, I am signing this object:

@JustusAdam
JustusAdam / CopyAssets.hs
Created August 27, 2020 20:13
Copy data files from installed Haskell libraries
{-# LANGUAGE LambdaCase #-}
import System.Directory
import System.FilePath
import System.Process
import Data.List
import System.Environment
import GHC.Stack
import Control.Monad
import System.IO.Unsafe
interrupt_handler = lambda _: None
def foo():
global interrupt_handler
# also could be something like write to a channel, opened only locally in foo
def h(x):
print(x)
interrupt_handler = h
for i in bar():
class Ref:
sentinel = object()
def __init__(self):
self._val = self.sentinel
def set(self, val):
self._val = val
def get(self):
t = self._val
self._val = self.sentinel
return t
@JustusAdam
JustusAdam / lc.hs
Last active November 11, 2019 14:44
A simple line counting tool
{-# LANGUAGE NoImplicitPrelude, GADTs, FlexibleContexts #-}
import Control.Arrow ((***))
import qualified Data.Char as C
import qualified Data.HashMap.Strict as Map
import Data.List (partition)
import System.Directory
import System.FilePath
import Text.Printf
import Universum
@JustusAdam
JustusAdam / gen_ghci_conf.hs
Created August 3, 2018 12:07
I'm weird, so I made a haskell script to generate my ghci config.
#!stack runhaskell
import Data.Monoid
import Text.Printf
data ExtsHelper
= Prefixed String
[ExtsHelper]
| Values [String]
exts :: [ExtsHelper]
@JustusAdam
JustusAdam / GenPW.hs
Last active June 26, 2020 14:08
A simple('ish) and transparent password generator
-- A one-file Haskell password generator file.
--
-- has two generation methods
-- chars which works simply by generating random characters
-- dict which selects words from a dictionary.
--
-- The `dict` generation method needs `aspell` to be installed on the system (as
-- it uses the `aspell` wordlists). The language argument to the `dicts` method
-- must be a valid `aspell` language identifierm with the default being 'en'.
--
@JustusAdam
JustusAdam / PlistToYaml.hs
Last active May 17, 2017 20:40
Read a plist file and convert it into Yaml
-- Reads a plist file and converts it into Yaml
-- it might not support all plist elements
-- it supports 'dict', 'array', 'integer' and 'string'
-- dependencies:
-- - base
-- - aeson
-- - xml
-- - yaml
-- - unordered-containers
@JustusAdam
JustusAdam / Watch.hs
Last active April 19, 2017 14:56
Watch a shake project for changes and recompile on change
{-# LANGUAGE BangPatterns #-}
import Control.Concurrent
import Control.Monad
import Data.Foldable
import qualified Data.HashSet as HS
import System.Directory
import System.Environment
import System.FilePath
import System.FSNotify