Skip to content

Instantly share code, notes, and snippets.

View leftaroundabout's full-sized avatar

Justus Sagemüller leftaroundabout

  • KTH Royal Institute of Technology
  • Stockholm
View GitHub Profile
@leftaroundabout
leftaroundabout / Enum.hs
Created April 1, 2012 23:22 — forked from depp/Enum.hs
Demonstration of how incorrect (Enum x, Enum y) => Enum (x, y) instance can be used for Enum a => Enum (a,a)
{-# LANGUAGE FlexibleInstances #-}
-- See http://stackoverflow.com/questions/9967790/instance-in-haskell
instance (Enum a) => Enum (a, a) where
fromEnum (x,y) =
k^2 + 2*j + if permuted then 1 else 0
where
k = max (fromEnum x) (fromEnum y)
j = min (fromEnum x) (fromEnum y)
@leftaroundabout
leftaroundabout / hs-golf-turca.hs
Last active December 16, 2015 23:59
Tiny piano – Rondo Alla Turca
import Control.Parallel
main = mapM_ (\(d,s)->(\p->p>>p>>p>>p).putChar.toEnum.round.(+d).(*62).min 2.abs$s+1).zip(dθ 1).lim.rev.hgp 9. render 9e6 (\_->0) . Sequence[]
$[mT%8.1,t2%16.1,t3(∡7)%8,t4%8,t5%16,t3(∡7)%8,mT%8.1,t2%16.1,t3(tev arp8)%8,cdT%99] >>= \e->[e,e]
mM=Sequence[][2-^8,1-^8,0-^8,1-^8,3-^4]
cM=Sequence[][7-^20,8-^20,9.^4,Sequence[(7,0),(6,1)](map((∡2).(.^4))[6,5,6])%0.75]
cMv=Sequence[][10-^2,8.^4,9.^4,hom(.^4)[[24,5],[23,8,12],[22,4],[21,6,9],[22,3],[19,5,8],[20,4],[18,6,9],[17]]#7&(-14)%2.5,tr 2%0.4,1-^9,2-^12,1-^1]%4.5
⋎(Sequence[][6-^4,lp(8.^4∡3)%(3/4),sil%2,lp(5.^4∡3)%h,lp(5.^4∡2)%h,1-^1∡7]&(-14)#7#4%5)
mMa f=Sequence[][(1-3*f).^4,lp(5.^4∡(-2-f))%0.75,mMa f%1.5,mMa(f*2)%h,mMa f%1]#7
@leftaroundabout
leftaroundabout / PiMelody.hs
Last active January 2, 2023 00:54
An automatic accompaniment generator for infinite melodies, applied to a simple mapping of the decimal digits of π to an A–harmonic-minor scale.
module PiMelody where
import Data.List
data MelodyNote = Gs | A | B | C' | D' | E' | F' | Gs' | A' | B'
deriving (Eq, Show, Enum)
type Melody = [MelodyNote] -- Assume simple all-quavers rythm.
piMelody :: Melody
@leftaroundabout
leftaroundabout / ghc-pkg_list
Created July 20, 2014 09:36
My `ghc-pkg list` as of now.
/usr/local/haskell/lib/ghc-7.8.2/package.conf.d:
Cabal-1.18.1.3
array-0.5.0.0
base-4.7.0.0
bin-package-db-0.0.0.0
binary-0.7.1.0
rts-1.0
bytestring-0.10.4.0
containers-0.5.5.1
deepseq-1.3.0.2
@leftaroundabout
leftaroundabout / diagrams-gtk-example.hs
Created October 9, 2014 14:29
Simple example of rendering diagrams to a GTK window. Being an updated version of https://groups.google.com/forum/#!topic/diagrams-discuss/IWSGyN--AlM
{-# LANGUAGE NoMonomorphismRestriction #-}
{- | A first example of drawing diagrams from within GTK. This
program draws a Koch snowflake with the depth controllable
via a GTK widget.
-}
module Main where
import Graphics.UI.Gtk
import Diagrams.Prelude
@leftaroundabout
leftaroundabout / edit-html-cb
Created May 31, 2015 15:48
Edit a gtk-clipboard “in-place”.
#!/usr/bin/env python
import gtk
import chardet
import os
import getopt
import subprocess
dtype = 'text/html'
htmlclip = gtk.Clipboard().wait_for_contents(dtype).data
encoding = chardet.detect(htmlclip)['encoding']
@leftaroundabout
leftaroundabout / 31-edo.scl
Created July 8, 2015 21:57
The Huygens tuning 31-edo, specified by a Scala .scl file
!
31
!
38.70967741935481
77.41935483870962
116.12903225806443
154.83870967741925
193.54838709677406
232.25806451612885
TreeInsert.$wtreeInsert =
\ (@ a_arS)
(w_sYW :: GHC.Classes.Ord a_arS)
(w1_sYX :: a_arS)
(w2_sYY :: TreeInsert.Tree a_arS) ->
case w2_sYY of _ [Occ=Dead] {
TreeInsert.EmptyTree ->
(# w1_sYX,
TreeInsert.EmptyTree @ a_arS,
TreeInsert.EmptyTree @ a_arS #);
@leftaroundabout
leftaroundabout / git-tmp-commit.py
Created March 22, 2016 13:11
Better git stash
#!/usr/bin/env python2
import subprocess
import sys
import datetime
import re
if __name__ == "__main__":
t = datetime.datetime.now()
branchn = subprocess.check_output([ 'git'
@leftaroundabout
leftaroundabout / downloadfail.ipynb
Created July 17, 2016 20:22
Linker error when using download in IHaskell
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.