Skip to content

Instantly share code, notes, and snippets.

View jhedev's full-sized avatar

Joel Hermanns jhedev

View GitHub Profile

Keybase proof

I hereby claim:

  • I am jhedev on github.
  • I am joelhermanns (https://keybase.io/joelhermanns) on keybase.
  • I have a public key ASDd_xFQBcq0HMJ7wbtppli0t-7hlK5ygJJrkevIiEIKXQo

To claim this, I am signing this object:

@jhedev
jhedev / multiples.hs
Last active August 29, 2015 14:22
multiples
module Main where
import Data.List
mult :: Int
mult = sum $ nub [i*x | x <- [3,5], i <- [1..(1000 -1)`div` x]]
main :: IO ()
main = print mult
@jhedev
jhedev / problem4.hs
Created May 29, 2015 11:23
Problem4
problem4 :: [Int] -> Int
problem4 = read . foldl1 (++) . map show . sortBy f
f:: Int -> Int -> Ordering
f x y | v1 == v2 = EQ
| v1 < v2 = GT
| v1 > v2 = LT
where
v1 = concatInt x y
v2 = concatInt y x
@jhedev
jhedev / data.hs
Created January 9, 2015 18:40
Experimentations with conduit and data analysis (inspired by http://twdkz.wordpress.com/2013/05/31/data-analysis-with-monoids/)
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE FlexibleContexts #-}
import Control.Applicative
import Control.Monad.Trans.Resource
import Control.Monad.IO.Class
import qualified Data.ByteString.Char8 as BSC
import Data.Conduit
import qualified Data.Conduit.Combinators as C
import qualified Data.Conduit.List as CL
@jhedev
jhedev / keyboard_interrupt_decorator.py
Created July 9, 2014 09:18
Decorator to add a KeyboardInterrupt handler to a function
#!/usr/bin/env python3.3
# -*- coding: utf-8 -*-
import time
def interrupt_decorator(handler):
def decorator(fun):
def wrapper(*args, **kwargs):
try:
fun(*args, **kwargs)
@jhedev
jhedev / primes
Created June 21, 2014 11:55
Python primes
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import itertools
def gen(i):
while True:
yield i
i = i + 1
def primes(gen):
@jhedev
jhedev / unicode_print.py
Created May 29, 2014 14:14
Print fancy unicode characters
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
start = 0x0001F300
while start < 0x1F58E:
print(hex(start), chr(start))
start+=1
@jhedev
jhedev / hash function
Last active August 29, 2015 14:01
Hash function in haskell
sum $ map (\(a,b) -> a*b `mod` 103) $ map (\(a,b) -> ((256^(7-a)) `mod` 103,b)) $ zip [1..] $ map (`mod` 103) $ map ord "string"
# Taken from https://github.com/HIPERFIT/L0Language/blob/master/git-hooks/pre-commit
fail() {
echo "Aborting commit due to verification errors."
echo "If you disagree, use git commit --no-verify."
exit 1
}
hlintable() {
! egrep -q '{-# LANGUAGE.*QuasiQuotes' $1
@jhedev
jhedev / Footline
Created December 11, 2013 22:31
Shows how to add frame numbers in footline in LaTeX Beamer class
\setbeamertemplate{footline}{
\leavevmode%
\hbox{%
\begin{beamercolorbox}[wd=.4\paperwidth,ht=2.25ex,dp=1ex,center]{author in head/foot}%
\usebeamerfont{author in head/foot}\insertshortauthor
\end{beamercolorbox}%
\begin{beamercolorbox}[wd=.6\paperwidth,ht=2.25ex,dp=1ex,center]{title in head/foot}%
\usebeamerfont{title in head/foot}\insertshorttitle\hspace*{3em}
\insertframenumber{} \hspace*{1ex}
\end{beamercolorbox}}%