Skip to content

Instantly share code, notes, and snippets.

View jaspervdj's full-sized avatar
🧀
eating cheese

Jasper Van der Jeugt jaspervdj

🧀
eating cheese
View GitHub Profile
@jaspervdj
jaspervdj / list-vs-non-empty.hs
Created April 3, 2019 07:37
Is List or NonEmpty "simpler"? Neither.
--------------------------------------------------------------------------------
-- Is List or NonEmpty "simpler"? Neither:
type NonEmpty a = Fix (Compose ((,) a) Maybe)
type List a = Fix (Compose Maybe ((,) a))
--------------------------------------------------------------------------------
newtype Fix f = Fix {unFix :: f (Fix f)}
@jaspervdj
jaspervdj / cat-image.hs
Created August 25, 2018 12:16
Display an image in the terminal using w3mimagedisplay
import Control.Monad (unless)
import qualified System.Directory as Directory
import System.Environment (getArgs)
import qualified System.Process as Process
import Text.Read (readMaybe)
newtype W3mImageDisplay = W3mImageDisplay FilePath deriving (Show)
findW3mImageDisplay :: IO W3mImageDisplay
findW3mImageDisplay = do
@jaspervdj
jaspervdj / ruby-lexing.rb
Created February 11, 2017 05:18
ruby lexer is a cool guy eh
def test01
a = 32
b = 2
i = 2
a /b/i
end
def test02
def a(x)
x
@jaspervdj
jaspervdj / client.hs
Created October 28, 2013 15:05
Haskel WebSockets client using SSL
--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Main
( main
) where
--------------------------------------------------------------------------------
import Control.Concurrent (forkIO)
import Control.Monad (forever, unless)
@jaspervdj
jaspervdj / resources.hs
Created October 1, 2013 13:36
Close resources in Haskell in a more-or-less safe way.
import Control.Monad (unless)
import Data.IORef
data Resource = Resource
{ resourceName :: String
, resourceClosed :: IORef Bool
}
mkResource :: String -> IO Resource
mkResource name = do
@jaspervdj
jaspervdj / log.txt
Created February 19, 2013 14:37
Dissassembly of hashable_siphash24_sse2:
Dump of assembler code for function hashable_siphash24_sse2:
0x088ed150 <hashable_siphash24_sse2+0>: push %ebp
0x088ed151 <hashable_siphash24_sse2+1>: xor %eax,%eax
0x088ed153 <hashable_siphash24_sse2+3>: mov %esp,%ebp
0x088ed155 <hashable_siphash24_sse2+5>: and $0xfffffff0,%esp
0x088ed158 <hashable_siphash24_sse2+8>: push %ebx
0x088ed159 <hashable_siphash24_sse2+9>: sub $0x2c,%esp
0x088ed15c <hashable_siphash24_sse2+12>: mov 0x1c(%ebp),%ebx
0x088ed15f <hashable_siphash24_sse2+15>: movq 0x8(%ebp),%xmm2
0x088ed164 <hashable_siphash24_sse2+20>: movq 0x10(%ebp),%xmm1
@jaspervdj
jaspervdj / gist:3774509
Created September 24, 2012 05:58
Firefly on windows: cabal snippet
...
Library
...
If(os(windows))
Include-dirs:
../SDL-1.2.15/include
../SDL_mixer-1.2.12
@jaspervdj
jaspervdj / connect-four.hs
Created August 2, 2012 16:05
Simple Haskell AI for the classic connect four game
--------------------------------------------------------------------------------
import Data.List (foldl', maximumBy)
import Data.Map (Map)
import qualified Data.Map as M
import Data.Maybe (catMaybes, fromMaybe, listToMaybe)
import Data.Ord (comparing)
--------------------------------------------------------------------------------
data Player = X | O
@jaspervdj
jaspervdj / remove-duplicates.rb
Created June 29, 2012 09:18
Remove all file duplicates in a directory, based on file content
#!/usr/bin/ruby
require 'digest'
require 'fileutils'
entries = Dir.entries('.').select { |x| File.file? x }
hashes = {}
entries.each do |entry|
hash = Digest::MD5.file(entry).to_s
@jaspervdj
jaspervdj / ruby-hashes-insertion-order.rb
Created June 5, 2012 17:25
Ruby's Hashes' ordering vs. referential transparency
hash1 = {:foo => 1, :bar => 2}
hash2 = {:bar => 2, :foo => 1}
# #to_s is probably a bad example, but I like
# it when x == y implies that f x == f y
puts hash1 == hash2
puts hash1.to_s == hash2.to_s