Skip to content

Instantly share code, notes, and snippets.

View goloroden's full-sized avatar
💭
The best way to predict the future is to invent it.

Golo Roden goloroden

💭
The best way to predict the future is to invent it.
View GitHub Profile
(defparameter *is-logged-in* nil)
(defparameter *users* '((golo secret)
(jones anothersecret)))
(defun user-by-login (login)
(assoc login *users*))
(defun password-of (user)
(cadr user))
@goloroden
goloroden / lottery.lisp
Last active August 29, 2015 14:02
My first 'real' Lisp program…
(defun lottery ()
(flet ((shuffle (list)
(let ((len (length list)))
(loop repeat len
do
(rotatef
(nth (random len) list)
(nth (random len) list))
finally
(return list)))))
@goloroden
goloroden / app.js
Created October 15, 2014 07:57
Listen for data
'use strict';
var net = require('net');
net.createServer(function (socket) {
socket.resume();
socket.once('end', function () {
socket.removeAllListeners();
});
}).listen(3000);
@goloroden
goloroden / knockat.go
Created November 20, 2014 22:19
My first Go app
package main
import (
"net"
"os"
"time"
)
func main() {
host := os.Args[1] + ":" + os.Args[2]
npm info it worked if it ends with ok
npm verb cli [ 'node',
npm verb cli '/Users/golo/.nvm/versions/node/v0.12.0/bin/npm',
npm verb cli 'install',
npm verb cli 'myorg/myrepo',
npm verb cli '--loglevel=silly' ]
npm info using npm@2.5.1
npm info using node@v0.12.0
npm sill cache add args [ 'myorg/myrepo', null ]
npm verb cache add spec myorg/myrepo
@goloroden
goloroden / gist:0a758e6612980c105dab
Created April 6, 2015 12:58
"Rock, paper, scissors" in Lisp
(defun play (a b)
(cond ((equal a b) 'tie)
((or (and (equal a 'rock) (equal b 'scissors))
(and (equal a 'scissors) (equal b 'paper))
(and (equal a 'paper) (equal b 'rock))) '(first wins))
(t '(second wins))))
@goloroden
goloroden / gist:3400e4fc7a21417f4276
Last active August 29, 2015 14:19
Some card playing code…
(defun rank (card)
(car card))
(defun suit (card)
(cadr card))
(setf my-hand '((3 hearts)
(5 clubs)
(2 diamonds)
(4 diamonds)
@goloroden
goloroden / gist:d8a97f72b7608b8e9c62
Last active August 29, 2015 14:19
Some recursive functions
(defun anyoddp (l)
(cond ((null l) nil)
((oddp (car l)) t)
(t (anyoddp (cdr l)))))
(defun fact (n)
(cond ((zerop n) 1)
(t (* n (fact (1- n))))))
(defun laugh (n)
(defun cookie-monster ()
(format t "~&Give me cookie!!!")
(format t "~&Cookie? ")
(let ((x (read)))
(cond ((eq x 'cookie)
(format t "~&Thank you!...Munch munch munch...BURP"))
(t
(format t "~&No want ~S..." x)
(cookie-monster)))))
@goloroden
goloroden / gist:bb3204e721ac5af32c3a
Created April 19, 2015 19:16
Countdown with (do)
(defun launch (n)
(do ((cnt n (- cnt 1)))
((zerop cnt) (format t "Blast off!"))
(format t "~S..." cnt)))