Skip to content

Instantly share code, notes, and snippets.

Konrad kgadek

Block or report user

Report or block kgadek

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kgadek
kgadek / gist:1119119
Last active Sep 26, 2015
Clojure: 99 bottles (II)
View gist:1119119
(ns org.gadek.fun.bottles)
(defn bottle-cnt [stock]
(str (if (zero? stock) "No more" stock)
" bottle" (when (not (= 1 stock)) "s")
" of beer"))
(defn verses [& [stock prev]]
(lazy-seq (let [stock (or stock 0) ; start from 0
prev (or prev (bottle-cnt 99)) ; even earlier -- 99 bottles
@kgadek
kgadek / gist:1124869
Last active Sep 26, 2015
JavaScript: ascii-art parser (Windmobile reports presenter)
View gist:1124869
// Ta tabela jest rozumiana przez JS -- wszystkie zmiany wprowadzać tutaj.
// | from | to | employees | seta | premia | kanał | prezencja | prefix | agregacja |
// |---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------|
var flds = [ dateFromField , dateToField, includeWorkersCb, setaType , forPremiaCb , accChannel , presence , prefix , agreg ];
var r2fl ={//|---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------+---------------|
'R0' : " | | x | | | | | | ",
'R1a' : " x | x | x | | | x | x |
@kgadek
kgadek / gist:2921556
Last active Oct 6, 2015
Erlang: extract *.ini file from *.tgx package and parse it in 12 LOC
View gist:2921556
parse_ini(Filename) ->
Str = string:tokens(os:cmd(["tar JxOf ", Filename, " settings.conf"]), "\n"),
parse_ini(Str, default, []).
parse_ini([], _Group, Res) -> Res;
parse_ini([Head|Tail], Group, Res) ->
[F|R] = Str = string:strip(Head),
case F of
$# -> parse_ini(Tail, Group, Res);
$[ -> parse_ini(Tail, string:strip(R, both, $]), Res);
_ -> [K|V] = string:tokens(Str, "="),
@kgadek
kgadek / gist:3216960
Last active Oct 7, 2015
Makefile: for Literate Haskell, Markdown/LaTeX mixed style
View gist:3216960
# sauce of original Makefile magic:
# http://passingcuriosity.com/2008/literate-haskell-with-markdown-syntax-hightlighting/
# modified by kgadek
# Ok, so I found Markdown+Bird style to be nice BUT editors have problems with Haskell code (indenting & stuff) when
# each line starts with ">".
# On the other hand LaTeX style is ok but LaTeX is often too powerful - distracts me all the time from actual code.
# But don't worry, I'm (nearly) an Engineer. Solution:
# Write Markdown style, enclose code with \begin{code}..\end{code} block and use small sed script to convert it to Markdown+Bird.
@kgadek
kgadek / FunSetSuite.scala
Created Oct 5, 2012
Scala: bughunting in assignment from Coursera's course
View FunSetSuite.scala
package funsets
import org.scalatest.FunSuite
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
/**
* This class is a test suite for the methods in object FunSets. To run
* the test suite, you can either:
@kgadek
kgadek / gist:4760294
Created Feb 12, 2013
Monads somewhat explained w/ dense example. Read more: http://readlists.com/0bca8296 . Kudos to: bartoszmilewski.com .
View gist:4760294
import Control.Monad
data StackCalc a = StackCalc { runStackCalc :: [Int] -> ([Int], a) }
instance Monad StackCalc where
return x = StackCalc aux
where aux stack = (stack, x)
f >>= e = StackCalc aux
where aux stack = let (newstack, newval) = runStackCalc f stack
@kgadek
kgadek / h.hs
Created Mar 21, 2013
(Poorly written) Haskell programme to find out 20 most common words in text
View h.hs
import Text.ParserCombinators.Parsec hiding (spaces)
import System.Environment
import Data.List (foldl')
import qualified Data.Map.Strict as M
main = interact getWords
getWords input =
case parse parseWords "words parser" input of
@kgadek
kgadek / python.py
Created Mar 21, 2013
Python programme to find out 20 most common words in text
View python.py
#!/usr/bin/env python3.2
import re
from operator import itemgetter
word2num = {}
num2word = {}
with open('potop.txt', mode='r', encoding='utf-8') as potop:
for line in potop:
@kgadek
kgadek / gist:5213110
Created Mar 21, 2013
Haskell vs Python
View gist:5213110
## Task: get 20 most common words in given text
## Input: http://home.agh.edu.pl/~dorosz/pjn/lab-01/potop.txt
## take a note this is in ISO-8859-2/CRLF. I converted it to UTF-8/LF:
## $ iconv -f ISO-8859-2 -t UTF-8 potop.txt > potop.tmp
## $ tr -d '\r' < potop.tmp > potop.txt
## Haskell: https://gist.github.com/kgadek/5213089
## uses Parsec
View gist:5218420
extend amber.DriverMsg {
// DriverMsg.type = DriverMsg.MsgType.PING / DriverMsg.MsgType.PONG
optional KeepaliveMsg keepaliveMsg = 10;
}
message Keepalive {
optional uint32 time = 1; // epoch! czas wysłania
}
You can’t perform that action at this time.