Skip to content

Instantly share code, notes, and snippets.

View konn's full-sized avatar
🏠
Working from home

Hiromi Ishii konn

🏠
Working from home
View GitHub Profile
@konn
konn / cacher.rs
Last active August 17, 2018 07:16
Generic Cacher without Clone
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::hash::Hash;
use std::ops::Fn;
struct Cacher<'a, T, A, B>
where
T: 'a + Fn(&A) -> B,
A: 'a,
B: 'a,
@konn
konn / Cell.hs
Created July 18, 2018 12:28
Akari (美術館) Solver using SAT solvers
{-# LANGUAGE DeriveAnyClass, DeriveDataTypeable, DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies, FlexibleInstances, MultiWayIf #-}
{-# LANGUAGE TypeFamilies #-}
module Cell where
import Control.Applicative (empty)
import Data.Typeable (Typeable)
import Data.Word
import Ersatz
import GHC.Generics (Generic)
@konn
konn / Cell.hs
Created July 18, 2018 12:28
Akari (美術館) Solver using SAT solvers
{-# LANGUAGE DeriveAnyClass, DeriveDataTypeable, DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies, FlexibleInstances, MultiWayIf #-}
{-# LANGUAGE TypeFamilies #-}
module Cell where
import Control.Applicative (empty)
import Data.Typeable (Typeable)
import Data.Word
import Ersatz
import GHC.Generics (Generic)
@konn
konn / Data.Aeson.Generic.DerivingVia.hs
Last active December 7, 2020 21:06
Type-driven safe derivation of ToJSON and FromJSON, using DerivingVia in GHC 8.6 and some type-level hacks
{-# LANGUAGE ConstraintKinds, DataKinds, DeriveGeneric, DerivingVia #-}
{-# LANGUAGE ExplicitNamespaces, FlexibleContexts, FlexibleInstances #-}
{-# LANGUAGE GADTs, GeneralizedNewtypeDeriving, MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds, ScopedTypeVariables, StandaloneDeriving #-}
{-# LANGUAGE TypeApplications, TypeFamilies, TypeInType, TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -Wall #-}
module Data.Aeson.Generic.DerivingVia
( StrFun(..), Setting(..), SumEncoding'(..), DefaultOptions, WithOptions(..)
, -- Utility type synonyms to save ticks (') before promoted data constructors
@konn
konn / nix-log.log
Created May 10, 2018 08:06
IHaskell compilation failure with Nix on macOS
these derivations will be built:
/nix/store/1kg1v5vy0drxyxq66dvvdwkn1304ifh9-qtwebkit-5.9.1.drv
/nix/store/ffja7pc88r4wyfk98pi9nk3yha9adblr-qtwebengine-5.10.1.drv
/nix/store/bzzbb1hrm0dz3rvndyi3mbbxqvyv3mai-python3.6-PyQt-5.10.drv
/nix/store/k8hyi5ys04x3zhskk7hm9sllxxbj4hmh-python3.6-qtconsole-4.3.1.drv
/nix/store/nba4gy75da88hd93gvlq4klq3chjya5m-python3.6-jupyter-1.0.0.drv
/nix/store/asds576kwc2x8zqprh598dvivhnna73b-python3-3.6.5-env.drv
/nix/store/jspp9rcrxh280wnb3l80f820n9hy94bf-ihaskell-console.drv
/nix/store/vas9ys522v10834ysxjb2pzxg4lzacdk-ihaskell-nbconvert.drv
/nix/store/w6hs5ji7dy7j82cw1rh2583ndpn3rgv0-ihaskell-notebook.drv
@konn
konn / disable-tap-to-click
Created April 27, 2018 10:11
Toggles Tap-to-Click with AppleScript (UI Scripting)
#!/usr/bin/env bash
osascript $HOME/usr/share/toggle-tap-to-click.scpt false
@konn
konn / FreeConstruction.hs
Created March 16, 2018 15:21
Free Monoids vs. Foldable and Traversable Functors
{-# LANGUAGE ConstraintKinds, DefaultSignatures, FlexibleContexts #-}
{-# LANGUAGE MonoLocalBinds, MultiParamTypeClasses #-}
{-# LANGUAGE NoMonomorphismRestriction, ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications, UndecidableSuperClasses #-}
{-# OPTIONS_GHC -Wall #-}
module FreeMonoid where
import Data.Constraint
import Data.Constraint.Forall
import Data.Monoid
import Data.Proxy
@konn
konn / intmap.saty
Created March 3, 2018 16:37
Naive Binary heap in SATySFi
% Naive (unbalanced) binary heap
module IntMap : sig
type 'a intmap
val singleton : int -> 'a -> 'a intmap
val empty : 'a intmap
val insert : int -> 'a -> 'a intmap -> 'a intmap
val lookup : int -> 'a intmap -> 'a option
end = struct
@konn
konn / crossref.saty
Created March 2, 2018 15:14
total page SATySFi
let hook = line-break false false (get-standard-context 0pt)
(hook-page-break (fun pbInfo _ -> (
numpages <- pbInfo#page-number
)))
in
let answer = page-break page pagecontf pagepartsf (bb-title +++ bb-toc +++ bb-main +++ hook)
in let () = register-cross-reference `pagecount` (arabic (!numpages))
in answer
locate_bin() {
if [ -n "$1" ]; then
list=$(type -ap "${1}")
if [ $? -eq 0 ]; then
echo "${list}" | head -n1 | awk -F"^${1} is " '{ print $NF }'
else
echo "No binary found: ${1}" 1>&2; return 1;
fi
else
echo "Please specify binary name" 1>&2; return 1;