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 / make.rb
Created March 28, 2013 06:16
A small script to parse a text file and produce output for Wordle.
# Encoding: UTF-8
Encoding.default_external = "UTF-8"
require 'benchmark'
BLACKLIST = %w(på og er om fra med i to det å
ditt til ved fra for av en din
du at vi har vil nå det som dere
kan vår så)
@tormaroe
tormaroe / Logalert.rb
Last active August 16, 2018 20:08
A very simple DSL for monitoring log files that I'm working on.
require './parser'
require './nodes_eval'
class Runtime
def initialize
@file = "test.log"
end
def loglines
@lines = File.readlines(@file)
@lines.each_with_index do |line, index|
@tormaroe
tormaroe / preformat.rb
Last active December 10, 2015 05:18
Small script that modifies the content of the clipboard by HTML encoding dangerous characters and wraps i in a <pre>-tag. Used when blogging source code.
=begin
TO INSTALL DEPENDENCIES
-----------------------
gem install ffi <-- For Windows users
gem install clipboard
=end
HTML_CODES = {
"&" => "&amp;",
">" => "&gt;",
@tormaroe
tormaroe / euler1_dialect.r
Created December 19, 2011 13:14
A dialecting/DSL sample in Rebol
REBOL [
Title: "Euler1 dialecting example"
Author: "Torbjørn Marø"
Home: http://blog.kjempekjekt.com
Date: 19-Dec-2011
Purpose: {
This script demonstrates how to use the built in parse
functionality of Rebol to create an internal DSL.
This particular DSL lets you create sums that are the
@tormaroe
tormaroe / betterave.rb
Created December 13, 2011 14:42
Betterave interpreter
#!/usr/bin/ruby
#
# Betterave -- Programmation fonctionnelle obscure
#
class Source
attr_reader :index, :stuff
def initialize(stuff)
@tormaroe
tormaroe / mywebapp_stats.rb
Created September 20, 2011 18:15
A logfile stats aggregator hack
unless ARGV.length == 2
raise <<EOF
Usage: mywebapp_stats.rb folder filepattern
Example: mywebapp_stats.rb . AccountWeb.log*
EOF
end
@tormaroe
tormaroe / Form1.cs
Created July 4, 2011 16:00
Oscilloscope user control (WinForms)
// JUST A TEST FORM WITH TWO SCOPE CONTROLS AND SOME RANDOM DATA
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Threading.Tasks;
class Stack_calc(object):
'''Stack calulator'''
def __init__(self):
self.item = []
self.calculate =
{'+' : lambda: self.item.append(self.item.pop() + self.item.pop()),
'-' : lambda: self.item.append(self.item.pop() - self.item.pop()),
'*' : lambda: self.item.append(self.item.pop() * self.item.pop()),
'/' : lambda: self.item.append(self.item.pop() / self.item.pop())}
@tormaroe
tormaroe / formatting.clj
Created April 7, 2011 19:09
This script produces some samples of how to use formatting
;; This script will generate a formatting demo
;; Call it with a filename to dump demo to file
(ns demo.formatting
(:use [clojure.contrib.duck-streams :only [with-out-writer]]
[clojure.string :only [join]])
(:import java.util.Date))
(defn print-demo-code [fmt & args]
(printf "%-50s ;=> %s%n"
@tormaroe
tormaroe / SI-prefix.clj
Created April 3, 2011 17:40
A test-driven implementation of conversion of numbers to and from SI-prefix in Clojure
(ns si_prefix.core
(:use clojure.test
clojure.contrib.generic.math-functions))
(def factors
(zipmap [:y :z :a :f :p :n :u :m :k :M :G :T :P :E :Z :Y]
(map (partial pow 1000)
(filter (complement zero?)
(range -8 9)))))