Skip to content

Instantly share code, notes, and snippets.

View amoilanen's full-sized avatar
💭
"Simplicity is prerequisite for reliability." Edsger W. Dijkstra

Anton Moilanen amoilanen

💭
"Simplicity is prerequisite for reliability." Edsger W. Dijkstra
View GitHub Profile
@amoilanen
amoilanen / cd_grabber.rb
Created December 11, 2011 19:39
CD grabber written in Ruby, can fetch track information from Internet
#
# CD Grabber. A simple Ruby script that simplifies converting your music to MP3 provided that you
# have Lame http://lame.sourceforge.net/ installed.
#
# Copyright (c) 2011 Anton Ivanov anton.al.ivanov(no spam)gmail.com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
@amoilanen
amoilanen / cljunit.clj
Created January 8, 2012 19:25
Port to Clojure of a simple unit testing framework from "Practical Common Lisp"
;Port of a simple unit testing framework from the "Practical Common Lisp" book to Clojure
;http://www.gigamonkeys.com/book/practical-building-a-unit-test-framework.html
(ns cljunit-testing
(:require clojure.contrib.string))
(defn function-names-from-stacktrace
"Returns a sequence of names of the user defined functions
obtained from the current Java stack trace"
[stackTrace]
(let [functionNames (map #(. %1 getClassName) stackTrace)]
@amoilanen
amoilanen / tail_recursion_optimization.js
Created February 5, 2012 16:39
Tail recursion optimization in JavaScript
var lib = {
R: {}
};
(function(host) {
function conj(element, arr, index) {
var arrCopy = arr.slice(index || 0);
arrCopy.unshift(element);
return arrCopy;
@amoilanen
amoilanen / array_splice.html
Created March 11, 2012 19:30
Implementation of Array.prototype.splice
<!DOCTYPE html>
<html>
<head>
<title>Array.splice Implementation</title>
<link rel="stylesheet" type="text/css" href="http://github.com/jquery/qunit/raw/master/qunit/qunit.css" />
<script type="text/javascript" src="http://github.com/jquery/qunit/raw/master/qunit/qunit.js"></script>
<script type="text/javascript">
if (!Array.prototype.splice2) {
Array.prototype.splice2 = function(index, howmany) {
if (index < 0) {
@amoilanen
amoilanen / color_selector.html
Created April 22, 2012 13:44
Color Selector Tool
<!-- Hosted at http://pastehtml.com/view/bvmdpxu1r.html -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Color Tool</title>
<style type="text/css">
.colors-container {
width: 400px;
height: 200px;
padding: 16px;
border: 1px solid;
@amoilanen
amoilanen / Monte_Carlo_method.html
Created May 4, 2012 15:17
Demo of Monte-Carlo method for computing an area of a figure.
<!-- Hosted at http://pastehtml.com/view/bwy9fiv68.html -->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Monte-Carlo Method</title>
<style type="text/css">
.figure-container {
background-color: gray;
margin-bottom: 16px;
}
.figure {
@amoilanen
amoilanen / keplers_laws.html
Created June 2, 2012 13:59
Demo of Kepler's Laws of Planetary Motion
<!-- Hosted version http://pastehtml.com/view/c06ceb3bi.html -->
<html>
<header>
<style type="text/css">
canvas {
background-color: black;
border-radius: 4px;
}
.drawing-area {
display: inline-block;
@amoilanen
amoilanen / mixup_page_animation.js
Created July 10, 2012 17:16
Simple animation for a web page, some of the elements are mixed up and re-positioned randomly at a fixed time interval.
//URL for a bookmarklet in a browser:
//javascript:var script = document.createElement("script"); script.src="https://raw.github.com/gist/3084823/6d8c6643e41092d09fa80c0db5234adbea7f94ea/mixup_page_animation.js"; document.body.appendChild(script);void(0);
(function(win) {
var elements = document.querySelectorAll("img, div");
setInterval(function() {
for (var i = 0; i < elements.length; i++) {
elements[i].style.position = "fixed";
elements[i].style.top = Math.floor(Math.random() * win.innerHeight).toString() + "px";
@amoilanen
amoilanen / fifteen_puzzle.html
Created July 16, 2012 20:30
Fifteen puzzle with native HTML5 drag-and-drop http://en.wikipedia.org/wiki/Fifteen_puzzle
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- Hosted at http://pastehtml.com/view/c50vk1exq.html -->
<head>
<meta charset="UTF-8">
<title>15 puzzle</title>
<style type="text/css">
.field {
width: 80%;
height: 80%;
max-width: 500px;
@amoilanen
amoilanen / memoize.js
Created September 14, 2012 16:33
JavaScript Memoization Library
//2012 Anton Ivanov anton.al.ivanov@gmail.com
//JavaScript memoization http://en.wikipedia.org/wiki/Memoization
(function (host) {
function memoize(func, host, hash) {
//By default memoize a function on the window object
var host = host || window,
hash = hash || {},
original = host[func];
//Only functions can be memoized