Skip to content

Instantly share code, notes, and snippets.

@turanct
turanct / game-of-life.scm
Last active October 28, 2021 16:56
Super simple Conway's game of life in scheme
(define create-coord
(lambda (x y)
(list x y)))
(define get-x
(lambda (coord)
(car coord)))
(define get-y
(lambda (coord)
@turanct
turanct / hangman.scm
Last active March 10, 2021 02:02
The Hangman game in Guile Scheme (lisp)
#!/usr/bin/env guile -s
!#
(use-modules
(srfi srfi-1)
(ice-9 rdelim))
(define words-path "words.txt")
(define random-word-from-file
@turanct
turanct / REPLinatweet.php
Created October 7, 2014 06:24
a PHP REPL in a tweet
<?php
while(1){echo"> ";$i=rtrim(stream_get_line(STDIN,512,PHP_EOL),';');try{@eval('print_r('.$i.');');}catch(Exception$e){print_r($e);}echo"\n";}
@turanct
turanct / Main.hs
Created July 3, 2017 13:45
Query Parser
import Text.ParserCombinators.Parsec
data Query = And Query Query
| Or Query Query
| Not Query
| Statement String deriving (Show)
andParser = do
arg1 <- statementParser
string " AND "
@turanct
turanct / Main.hs
Last active January 11, 2017 08:25
Haskell Coffee Run
import Shop
main = do
contents <- getContents
let
inventory1 = inventoryFromFile contents
shop1 = Shop "Simon Says" inventory1
putStrLn $ show shop1
@turanct
turanct / gist:4541603
Last active December 11, 2015 03:58 — forked from anonymous/gist:4541082
/tc 00:00:14:00 00:00:17:11
De Amerikaanse overheid
bedreigde Zweden met ernstige maatregelen.
/tc 00:00:17:16 00:00:20:06
-tenzij file sharing sites, zoals
de Pirate Bay, neergehaald werden.
/tc 00:00:23:13 00:00:28:04
De rechtszaak tegen de oprichters van
@turanct
turanct / mapreduce.scm
Created May 14, 2015 20:21
Monoids for map/reduce in scheme
(use-modules (srfi srfi-1) (ice-9 threads))
;; some funtions to generate page content
(define page-contents (list "foo" "bar" "baz" "qux"))
(define generate-page
(lambda (contents times)
(cond
((eq? 0 times) '())
(else (append contents (generate-page contents (- times 1)))))))
@turanct
turanct / run.php
Last active August 29, 2015 14:19
Monoids for map/reduce
<?php
require_once __DIR__ . '/util.php';
require_once __DIR__ . '/wordcount.php';
/**
* Create a document, containing 100 pages of 1000 times "foo bar baz qux"
*/
$page = str_repeat("foo bar baz qux\n", 1000);
$document = array_fill(0, 100, $page);
@turanct
turanct / higher-order.php
Last active August 29, 2015 14:18
Monoids for validation
<?php
function partial($function, ...$arguments)
{
return function() use ($function, $arguments) {
$fullArguments = array_merge($arguments, func_get_args());
return call_user_func_array($function, $fullArguments);
};
}
@turanct
turanct / list-functions-folds.scm
Last active August 29, 2015 14:15
Folds are awesome abstractions over recursive function calls
; As seen in my previous gist about lisp list-functions
; (https://gist.github.com/turanct/e84be7f355e255c2c1b5)
; all list functions can be created relatively easy from
; a few function calls, using recursive functions.
; As the pattern for those functions is almost always the same,
; that can be abstracted out. The way we do this is using folds.
;
; Folds take a function, an initial value (or carry), and a
; list, and they use the function to combine the carry with the
; next element of the list. When the fold iterated over the