Skip to content

Instantly share code, notes, and snippets.

(use-modules (artanis server epoll)
(artanis utils)
(ice-9 rdelim)
(ice-9 match)
(ice-9 suspendable-ports)
(ice-9 control))
(install-suspendable-ports!)
(define (call-with-sigint x y) (%call-with-sigint x y))
@NalaGinrut
NalaGinrut / lru.scm
Created January 14, 2017 14:30
Simple LRU implementation in Scheme
(define (make-lru size)
(define cnt 0)
(define fl '())
(define ht (make-hash-table))
(define (refresh-fl i)
(set! fl (cons i (filter (lambda (x) (not (= x i))) fl))))
(lambda (cmd . i/v)
(case cmd
((get)
(refresh-fl (car i/v))
@NalaGinrut
NalaGinrut / clp.scm
Last active November 9, 2015 11:13
Auto prover of Combinatory Logic
(use-modules (ice-9 match))
(define (cl str)
(define (parser s)
(let lp((i 0) (ret '()))
(cond
((= i (string-length s))
(map (lambda (x)
(if (char? x) (string->symbol (string x)) x))
(reverse ret)))
@NalaGinrut
NalaGinrut / pong.scm
Last active May 24, 2024 07:06
tiny Actor-model
;;==============Tiny framework of Actor-model=========================
(use-modules (ice-9 control) (ice-9 match) (ice-9 q))
(define *mailbox* (make-hash-table))
(define *task-queue* (make-q))
(define (gen-pid n) (gensym (format #f "actor-~a-" n)))
(define-syntax-rule (! pid msg)
(let ((mq (hashq-ref *mailbox* pid)))
(if mq
#!/usr/bin/env guile
!#
(use-modules (ice-9 rdelim)
(ice-9 ftw)
(ice-9 futures)
(srfi srfi-1))
(define get-string-all (@ (rnrs io ports) get-string-all))
(define G (ash 1 30))
(define M (ash 1 20))
@NalaGinrut
NalaGinrut / morse.scm
Created September 22, 2014 08:47
Morse coding
(use-modules (ice-9 rdelim))(define morse '((#\a ".-")(#\b "-...")(#\c "-.-.")(#\d "-..")(#\e ".")(#\f "..-.")(#\g "--.")(#\h "....")(#\i "..")(#\j ".---")(#\k "-.-")(#\l ".-..")(#\m "--")(\
#\n "-.")(#\o "---")(#\p ".--.")(#\q "--.-")(#\r ".-.")(#\s "...")(#\t "-")(#\u "..-")(#\v "...-")(#\w ".--")(#\x "-.--")(#\y "-.--")(#\z "--..")))(for-each (lambda (x) (if (char-alphabetic\
? x)(display (car (assoc-ref morse x))))(display " "))(string->list (string-downcase (read-line (current-input-port)))))(newline)
@NalaGinrut
NalaGinrut / 0_reuse_code.js
Created July 3, 2014 03:08
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@NalaGinrut
NalaGinrut / lexer.scm
Last active August 29, 2015 14:02
string lexer
(use-modules (ice-9 rdelim) (rnrs))
(define (k f init val pred)
(if (pred val)
init
(call-with-values (lambda () (f init val))
(lambda (lst rst) (k f lst rst pred)))))
(define (lexer str delimiters)
(define (-> c)
@NalaGinrut
NalaGinrut / ts.py
Created April 24, 2014 09:17
timestamp watermark
#!/usr/bin/python
from PIL import Image, ImageDraw
import time, os, sys
ori, des = sys.argv[1:]
im = Image.open(ori)
draw = ImageDraw.Draw(im)
textPadding = 5
@NalaGinrut
NalaGinrut / multi-assign.scm
Created April 17, 2014 10:08
A macro for multi assign
(define-syntax sets!
(syntax-rules ()
((_ (var) (val))
(set! var val))
((_ (var vars* ...) (val vals* ...))
(let ((var0 val))
(sets! (vars* ...) (vals* ...))
(set! var var0)))))