Skip to content

Instantly share code, notes, and snippets.

View sgronblo's full-sized avatar
🆒
Focusing

Sam Grönblom sgronblo

🆒
Focusing
  • Reaktor Japan
  • Tokyo
View GitHub Profile
@sgronblo
sgronblo / Roman.hs
Last active January 7, 2024 18:23
Roman numeral parser in Haskell using Parsec
View Roman.hs
#!/usr/bin/env stack
-- stack --resolver lts-7.9 --install-ghc script --package QuickCheck --package either --package parsec
module Roman where
import Control.Applicative hiding ((<|>))
import Data.Either.Combinators
import Text.Parsec.Prim
import Text.Parsec.Combinator
import Text.Parsec.Error
@sgronblo
sgronblo / 2017-01-captcha.hs
Last active December 2, 2017 16:11
Advent of Code 2017 01 Captchas in Haskell
View 2017-01-captcha.hs
#!/usr/bin/env stack
-- stack --resolver lts-9.14 script --package array
{-# LANGUAGE ScopedTypeVariables #-}
import System.Environment
import Data.Array.IArray
captchaPairs :: (IArray a e, Ix i, Num i) => a i e -> ((i, i) -> i) -> [(e, e)]
captchaPairs es getPairIndex =
@sgronblo
sgronblo / snake.elm
Created March 29, 2016 07:31
Snake game in Elm
View snake.elm
import Color
import Debug
import Effects exposing (..)
import Graphics.Collage exposing (..)
import Graphics.Element exposing (..)
import Html exposing (div, Html)
import Keyboard exposing (..)
import Random
import StartApp
import Text
@sgronblo
sgronblo / kanji_to_number.rb
Created June 19, 2012 06:55 — forked from Kimtaro/kanji_to_number.rb
Convert Kanji numerical to roman numerical
View kanji_to_number.rb
# Encoding: UTF-8
module KanjiToNumber
MULTIPLIERS = {'十' => 10, '百' => 100, '千' => 1000, '万' => 10000}
NUM_FOR_NUM = {'壱' => 1, '一' => 1, '1' => 1,
'弐' => 2, '二' => 2, '2' => 2,
'参' => 3, '三' => 3, '3' => 3,
'四' => 4, '4' => 4,
'五' => 5, '5' => 5,
'六' => 6, '6' => 6,
@sgronblo
sgronblo / gist:2469091
Created April 23, 2012 06:21
Multi column/row update with a single query for mysql
View gist:2469091
UPDATE table
SET col1 = CASE id
WHEN id1 THEN id1_v1,
WHEN id2 THEN id2_v1
END
col2 = CASE id
WHEN id1 THEN id1_v2,
WHEN id2 THEN id2_v2
END
WHERE id IN (id1, id2)
@sgronblo
sgronblo / indentation.rb
Created February 27, 2012 07:12
Indented puts Ruby Module, just include and go. You can also change the indentation size.
View indentation.rb
class IndentedPutser
attr_accessor :level
def initialize(size)
@level = 0
@size = size
end
def indent
self.level += 1
@sgronblo
sgronblo / rvm 1.8.6 make.log
Created November 15, 2011 16:52
rvm install 1.8.6 failure
View rvm 1.8.6 make.log
[2011-11-16 01:35:03] make
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c array.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c bignum.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c class.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c compar.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c dir.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c dln.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c enum.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c error.c
gcc -g -O2 -fPIC -DRUBY_EXPORT -D_GNU_SOURCE=1 -I. -I. -c eval.c