Skip to content

Instantly share code, notes, and snippets.

@wasamasa
wasamasa / traffic-lights.el
Created March 30, 2016 07:54
Finite state machine
(defun traffic-lights ()
(let ((state 'red))
(while t
(cond
((eq state 'red)
(message "Red")
(sleep-for 1)
(setq state 'red+yellow))
((eq state 'red+yellow)
(message "Red+Yellow")
@wasamasa
wasamasa / emacsrepl.el
Last active May 19, 2021 06:22
emacsrepl++
;; https://github.com/antirez/linenoise
;; console_codes(4)
(defvar column-start "\e[0G")
(defvar delete-to-end "\e[0K")
(defvar retreat-cursor "\e[%sD")
(defvar advance-cursor "\e[%sC")
(defvar clear-screen "\e[H\e[2J")
(defun read-byte ()
@wasamasa
wasamasa / helloworld.el
Last active December 26, 2022 18:53
Lisp obfuscation
(message (mapconcat 'char-to-string (list
(*(+(*)(*))(+(*)(*))(+(*)(*))(+(*)(*)(*))(+(*)(*)(*)))(+(+(*)(*)(*))(*(+(*)(*))(+(*(+(*)(*))(+(*)(*)))(+(*)(*)(*)))(+(*(+(*)(*))(+(*)(*)))(+;;
(* )(*) (*)))) )(*(+( *)(*))(+(* )(*))(+(*)(* )(*))(+(*) (*)(*) )(+(*)(* )(*)))(* (+(*)(*) )(+(*)(*)) (+(*)(*) (*
)) (+(* )(*)(* ))(+(*)(*) (*)))(+(+( *)(*)(*))( *(+( *)(*))(+ (* )( *))(+( *)(* )(*))( +(*) (*)(*) )(+(*)(*)( *))) )(*(+( *)
(* ))(+(* )(*))( +(*)(*))(+ (*)(*))(+( *)(* )))(*(+( *) (* )(*))( +(+( *)(*)) (*(+(*)( *)(*))(+(* )(*) (*))(+ (*
)( *)(* )))))( *(+(*)(*)( *))(+(*)(* (+(*)(*))( +(*) (*))(+(* )( *) (*))(+ (*)( *)(*)) )) )(*(+(*) (*))(+(*)( *)(* ))(+(+(*)(
*) (*)) (*(+(* )(*))( +(*)(* ))(+(*)( *))(+(*)(*)) )) )(*(+(*)(* ))(+(*)( *))( +(*)(* )(*))( +(*)(*)( *)
)(+(*)(*)(*)))(*(+(*)(*))(+(*)(*))(+(+(*)(*))(+(*)(*)(*)))(+(+(*)(*))(+(*)(*)(*))))(*(+(*)(*)(*))(+(+(*)(*))(*(+(*)(*)(*))(+
@wasamasa
wasamasa / cat.cljs
Last active March 7, 2016 21:27
node.cljs
(do
(js/require "process")
(.setEncoding js/process.stdin "utf8")
(.on js/process.stdin "data"
(fn [data]
(.write js/process.stdout data))))
@wasamasa
wasamasa / break-continue.el
Last active May 3, 2020 15:46
break, continue
(dotimes (i 10)
(catch 'continue
(when (zerop (% i 2))
(throw 'continue t))
(message "%s" i)))
(let ((i 0))
(catch 'break
(while t
(catch 'continue
@wasamasa
wasamasa / my-define-keys.el
Created February 18, 2016 20:22
my-define-keys
(defun my-partition (n list)
(let (result)
(while list
(let ((i 0)
chunk)
(while (< i n)
(push (pop list) chunk)
(setq i (1+ i)))
(push (nreverse chunk) result)))
(nreverse result)))
@wasamasa
wasamasa / rotate-modeline.el
Last active February 17, 2016 13:45
Modeline scroller (suggested by @josteink on #emacs)
(defun rotate-modeline ()
(interactive)
(let ((original-mode-line-format mode-line-format)
(mode-line (format-mode-line mode-line-format))
(interval 0.1))
(unwind-protect
(while (not (input-pending-p))
(setq mode-line (concat (substring mode-line 1)
(substring mode-line 0 1))
mode-line-format mode-line)
@wasamasa
wasamasa / hl-tab.el
Created February 4, 2016 19:15
Helping out viccuad on #emacs
(defface hl-tab-line
'((((type graphic)) :strike-through t)
(((type tty)) :underline t))
"Tab line")
(defun hl-tab-fontify (beg end)
(let ((bol (save-excursion (goto-char beg) (line-beginning-position)))
(eol (save-excursion (goto-char end) (line-end-position))))
(save-excursion
(goto-char bol)
@wasamasa
wasamasa / ccl-benchmark.el
Created January 23, 2016 10:05
Fun with CCL
;; taken from http://www.myrkraverk.com/blog/2014/11/the-convoluted-logic-of-rot13-in-ccl/
(define-ccl-program my-ccl-rot13
'(1
((loop
(read r0)
;; The convoluted logic of rot13 in CCL.
(if (r0 >= 110) ; n
(if (r0 <= 122) ; z
((r0 -= 13))) ;; If we are between n-z
(if (r0 >= 97) ; a
@wasamasa
wasamasa / pocorgtfo.el
Last active November 20, 2015 21:06
PoCorGTFO PRNG
;; Taken from PoCorGTFO 0x01
;; Original:
;; function millis() {return Date.now();}
;; function flip_coin() {n=0; then = millis()+1; while(millis()<=then) {n=!n;} return n;}
;; function get_fair_bit() {while(1) {a=flip_coin(); if(a!=flip_coin()) {return(a);}}}
;; function get_random_byte() {n=0; bits=8; while(bits--){n<<1; n|=get_fair_bit();} return n;}
(defun prng--milliseconds ()
(floor (* (float-time) 1000)))