Skip to content

Instantly share code, notes, and snippets.

@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.
Actor = (function() {
var my,own,internal,state = 0;
return {
onMessage: function(msg) {
if (msg == "inc") { my = my + 1 }
// ...
}
}
@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";
@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 / 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 / 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 / application.scala
Created April 1, 2012 23:54
Controller from Play 2.0 Chatroom Sample App
object Application extends Controller {
/**
* Just display the home page.
*/
def index = Action { implicit request =>
Ok(views.html.index())
}
/**
@mostlygeek
mostlygeek / recipe.rb
Created January 30, 2012 19:50 — forked from poobury/recipe.rb
S3 File Resource for Chef
# Source accepts http/https or the protocol region:// with the host as the bucket
# access_key_id and secret_access_key are just that
# Note resource name has changed from s3_file to s3_aware_remote_file
# for the eu-west-1 region:
s3_aware_remote_file "/var/bulk/the_file.tar.gz" do
source "s3-eu-west-1://your.bucket/the_file.tar.gz"
access_key_id your_key
secret_access_key your_secret
owner "root"
@mostlygeek
mostlygeek / demo.rb
Created January 24, 2012 21:29
Chef ruby_block and dynamic resource creation
ruby_block "sync_build_from_s3" do
action :nothing
block do
# latest_file contains path to the latest.txt, which lists files to sync
file = File.new(latest_file, "r");
run_context = Chef::RunContext.new(node, {})
#
# Create the directory to hold the new build files
#
@mostlygeek
mostlygeek / gist:1154271
Created August 18, 2011 15:11
Script kiddies hitting the prod server...
/a1b2c3d4e5f6g7h8i9/nonexistentfile.php
/ads/adxmlrpc.php
/Ads/adxmlrpc.php
/adserver/adxmlrpc.php
/adxmlrpc.php
/b2evo/xmlsrv/xmlrpc.php
/b2/xmlsrv/xmlrpc.php
/blogs/xmlrpc.php
/blogs/xmlsrv/xmlrpc.php
/blogtest/xmlsrv/xmlrpc.php