Skip to content

Instantly share code, notes, and snippets.

@mostlygeek
mostlygeek / blog.md
Created May 18, 2012 14:50 — forked from groundwater/blog.md
Why Method Overloading Sucks in Scala

Introduction

Method overloading sucks in Scala because it detracts from your flexibility. An implicit conversion is a feature of Scala that let's the compiler look up how to convert objects between types at compile time.

Let's say I define a method with the following signature:

def doSomething( action: Action )

Somewhere else in the code I write:

@mostlygeek
mostlygeek / blah.scala
Created August 6, 2012 18:17
Some Scala
bstract class Prize {
def * (num: Int): List[Prize] = {
if (num == 0) Nil
else {
import collection.mutable.ListBuffer
val l = new ListBuffer[Prize]
for (i <- 1 to num)
l += this
l.toList
}
@mostlygeek
mostlygeek / hsl-canvas-test.js
Last active December 10, 2015 13:08
HSL color rotation demo with canvas. Demo at: http://jsfiddle.net/mostlygeek/sM7DR/32/
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame =
window[vendors[x] + 'CancelAnimationFrame'] || window[vendors[x] + 'CancelRequestAnimationFrame'];
}
if (!window.requestAnimationFrame) window.requestAnimationFrame = function(callback, element) {
@mostlygeek
mostlygeek / iframe-messaging.js
Created January 3, 2013 08:19
Playing around with creating an iframe, and then adding content into it and being able to send messages back/forth to it. demo at: http://jsfiddle.net/mostlygeek/P7jqp/
/*
Was watching this talk: http://www.youtube.com/watch?v=y4lBEZTThvg
about iframes and JS ... so this will create a new iframe, inject new
HTML content into it and send it messages through the window.location.hash every second
*/
(function() {
el = document.getElementById('foo');
iframe = document.createElement('iframe');
iframe.src = "about:blank";
Actor = (function() {
var my,own,internal,state = 0;
return {
onMessage: function(msg) {
if (msg == "inc") { my = my + 1 }
// ...
}
}
@mostlygeek
mostlygeek / turing.sed
Created February 20, 2013 08:02
sed is turing complete...
#! /bin/sed -f
#
# turing.sed -- emulate a Turing machine
#
# Christophe Blaess <[email protected]>
# http://perso.club-internet.fr/ccb/
# See text file for information about Turing Machine script.
# Read all the instructions, and add a final newline.
@mostlygeek
mostlygeek / file-list.txt
Created March 7, 2013 07:39
Wrote this little bash script to go though a directory of PNG files and find the smallest width/height for a DOM element that fits any image in a set. The set of images is made up of a "close", "open" and "stroke" image sprites.
t01-close.png
t01-open.png
t01-stroke.png
t02-close.png
t02-open.png
t02-stroke.png
t03-close.png
t03-open.png
t03-stroke.png
t04-close.png
@mostlygeek
mostlygeek / rename-files.sh
Created March 12, 2013 19:35
This gist is a collection of random things i've needed to do on the command line. Usually it is moving files around or scripting commands to run over a set of files.
#
# Source, a directory full of files like: t01-open.png, t02-open.png, etc.
# Output, rename the files so t01-open.png turns into t00-open.png (start at zero instead of 1)
# loop through all the numbers ...
for i in {1..20}
do
# turn 1, 2, 3, 4... into 01, 02, 03, 04
f=$(echo $i | awk '{printf "%02s", $1}')
@mostlygeek
mostlygeek / .tmux.conf
Last active December 15, 2015 08:59
.tmux.conf
# fix for broken pbcopy in tmux
# see: http://superuser.com/questions/231130/unable-to-use-pbcopy-while-in-tmux-session
set-option -g default-command "reattach-to-user-namespace -l bash"
unbind C-b
set -g prefix C-a
# allow mouse navigation (on mac) between panes
bind -n M-Left select-pane -L
@mostlygeek
mostlygeek / start.sh
Created April 10, 2013 05:44
MongoDB shell starter (osx) dev env.
#!/bin/sh
BASE=$(dirname $0)
cd $BASE
./bin/mongod \
--noprealloc \
--cpu \
--dbpath $BASE