Skip to content

Instantly share code, notes, and snippets.

View tormaroe's full-sized avatar
💭
Doing some Go and then som JavaScript at the moment

Torbjørn Marø tormaroe

💭
Doing some Go and then som JavaScript at the moment
View GitHub Profile
@tormaroe
tormaroe / roman-calc.lisp
Created January 29, 2016 23:37
Add roman numerals in Common Lisp
(defun mapcn (chars nums string)
(loop as char across string
as i = (position char chars)
collect (and i (nth i nums))))
(defun parse-roman (R)
(loop with nums = (mapcn "IVXLCDM" '(1 5 10 50 100 500 1000) R)
as (A B) on nums if A sum (if (and B (< A B)) (- A) A)))
(defun +roman (&rest rx)
@tormaroe
tormaroe / foo.lisp
Last active March 23, 2016 23:38
CL Redis DOB metrics test data
(ql:quickload :cl-redis)
(redis:connect :port 7777)
(red:select 9)
(defvar *start* 201603231200)
(defvar *end* 201603231259)
(defvar *bu-names* '(
@tormaroe
tormaroe / fpl.lisp
Created May 17, 2016 21:06
Fantasy Premiere League fetch players
(defun fetch-and-spit-player (idx)
(let ((path (format nil "C:\\temp\\fpl\\~A.json" idx)))
(with-open-file (fs path :direction :output
:if-exists :overwrite
:if-does-not-exist :create)
(format t "Output: ~A~%" path)
(format fs (flexi-streams:octets-to-string
(drakma:http-request
(format nil "http://fantasy.premierleague.com/web/api/elements/~A/" idx))
:external-format :UTF-8)))))
@tormaroe
tormaroe / maze1.lisp
Last active March 12, 2017 09:39
Maze experiments with common lisp and processing.js, part I (garbled)
(dolist (x '(:hunchentoot :cl-who :parenscript :cl-fad))
(ql:quickload x))
(defpackage "EXPERIMENTS"
(:use "COMMON-LISP" "HUNCHENTOOT" "CL-WHO" "PARENSCRIPT" "CL-FAD"))
(in-package "EXPERIMENTS")
@tormaroe
tormaroe / euler1.apl
Last active December 12, 2019 09:22
Project Euler problem #1 solved in APL
⍝ This is my very first APL program,
⍝ made from scratch using an APL primer at
⍝ http://aplwiki.com/LearnApl/BuiltInFunctions
⍝ Evaluated using http://tryapl.org/
⍝ Yields the sum of all multiples of 3 or 5 below 1000.
n←⍳999⋄a←+/n×0=3|n⋄b←+/n×0=5|n⋄c←+/n×0=15|n⋄a+b-c
⍝ Second version using a function definition..
f←{+/⍺×0=⍵|⍺}⋄n←⍳999⋄a←n f 3⋄b←n f 5⋄c←n f 15⋄a+b-c
@tormaroe
tormaroe / mazeChapter2.go
Created January 10, 2019 20:56
This Go program is a re-implementation of the Ruby code found in Chapter 2 of the book Mazes for Programmers by Jamis Buck.
// Copyright (c) 2019 Torbjørn Marø
//
// This Go program is a re-implementation of the Ruby code found
// in Chapter 2 of the book Mazes for Programmers by Jamis Buck.
// The source contains:
// - General purpose Grid implementation
// - Grid to string function (ASCII maze)
// - Grid to PNG function (using gg package)
// - Binary Tree maze generation algorithm
// - Sidewinder maze generation algorithm
@tormaroe
tormaroe / recursively.cs
Last active February 13, 2019 14:33
Example code C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace RosettaRecursiveDirectory
{
class Program
{
static IEnumerable<FileInfo> TraverseDirectory(string rootPath, Func<FileInfo, bool> pattern)
@tormaroe
tormaroe / distribution.py
Created February 13, 2019 14:34
Example code Python
import sys, os
from collections import Counter
def dodir(path):
global h
for name in os.listdir(path):
p = os.path.join(path, name)
if os.path.islink(p):
@tormaroe
tormaroe / polymor.py
Created February 13, 2019 14:36
Example code Python 2
class Point(object):
def __init__(self, x=0.0, y=0.0):
self.x = x
self.y = y
def __repr__(self):
return '<Point 0x%x x: %f y: %f>' % (id(self), self.x, self.y)
class Circle(object):
def __init__(self, center=None, radius=1.0):
self.center = center or Point()
@tormaroe
tormaroe / wrap.js
Created February 13, 2019 14:37
Example code JS
function wrap (text, limit) {
if (text.length > limit) {
// find the last space within limit
var edge = text.slice(0, limit).lastIndexOf(' ');
if (edge > 0) {
var line = text.slice(0, edge);
var remainder = text.slice(edge + 1);
return line + '\n' + wrap(remainder, limit);
}
}