Skip to content

Instantly share code, notes, and snippets.

import scala.actors._
import scala.actors.Actor._
val helloActor = actor {
receive {
case nextActor : Actor => {
println("Hello Actor linked to " + nextActor)
while(true) {
receive {
case message : String => {
@adbrowne
adbrowne / .vimrc
Created April 30, 2011 11:42
Install vim plugins for scala
" Based on example from here: http://stackoverflow.com/questions/3626203/text-editor-for-scala
set nocompatible "Not vi compativle (Vim is king)
""""""""""""""""""""""""""""""""""
" Syntax and indent
""""""""""""""""""""""""""""""""""
syntax on " Turn on syntax highligthing
set showmatch "Show matching bracets when text indicator is over them
colorscheme delek
@adbrowne
adbrowne / Expr.scala
Created May 24, 2011 13:22
Pattern Matching
abstract class Expr
case class Var(name: String) extends Expr
case class Number(num: Double) extends Expr
case class UnOp(operator: String, arg: Expr) extends Expr
case class BinOp(operator: String, left: Expr, right: Expr) extends Expr
class Plus(left: Expr, right: Expr) extends BinOp("+", left, right)
def simplifyTop(expr: Expr): Expr = expr match {
case UnOp("-", UnOp("-", e)) => e
case BinOp("+", e, Number(0)) => e
case BinOp("*", e, Number(1)) => e
import Data.Char
import System.Random
main = do
randomGen <- newStdGen
let getR = getRandom randomGen
contents <- getContents
outputStory . (generateStory 10 getR) $ contents
putStrLn ""
@adbrowne
adbrowne / LazyBadges.hs
Created February 21, 2012 11:56
Haskell HaXml Sample of Lazily Reading XML file (in this case badges file from stackoverflow data dump)
import Text.XML.HaXml.ParseLazy as PL
import Text.XML.HaXml
import Text.XML.HaXml.Posn
import System.IO
main = do
inh <- openFile "badges.xml" ReadMode
hSetEncoding inh utf8_bom
inpStr <- hGetContents inh
let (Document _ _ root _) = PL.xmlParse "badges.xml" inpStr
@adbrowne
adbrowne / CassetteConfiguration.cs
Created March 17, 2012 02:01
Configuring Cassette to work with a CDN
var staticDomain = ConfigurationManager.AppSettings["StaticDomain"];
settings.UrlModifier = new StaticDomainUrlModifier(settings.UrlModifier, staticDomain);
@adbrowne
adbrowne / ConstantsGenerator.cs
Created March 18, 2012 03:05
Replacing variables in javascript files with Cassette IAssetTransformer
public class ConstantsGenerator : IAssetTransformer
{
private const char ConstantStartToken = '#';
private const char OpeningBraceToken = '{';
private const char ClosingBraceToken = '}';
private readonly Dictionary<string, string> values;
public ConstantsGenerator(Dictionary<string, string> values)
{
this.values = values;
@adbrowne
adbrowne / SampleViewModel.coffee
Created July 31, 2012 06:20
Sample CoffeeScript ViewModel for KnockoutJS
class SampleViewModel
constructor: (values) ->
this.title = ko.observable()
this.description = ko.observable()
this.isPrivate = ko.observable()
this.status = ko.observable "Active"
this.showApproveReject = ko.computed => @isActive()
this.statusUrl = ko.observable()
this.privacyUrl = ko.observable()
_.extend(this, Backbone.Events)
@adbrowne
adbrowne / gist:5519816
Last active December 17, 2015 00:19
SICP Exercise 1.3
(define (sum-of-squares a b)
(+ (square a) (square b)))
(define (sum-of-squares-of-max-2 a b c)
(if (> a b)
(if (> b c)
(sum-of-squares a b)
(sum-of-squares a c))
(if (> a c)
(sum-of-squares a b)
@adbrowne
adbrowne / Database.sql
Last active August 29, 2015 14:23
Bad idea to rely on finding changes using AutoIncrement columns or DateTimes
CREATE DATABASE [OrderedInsert]
GO
ALTER DATABASE [OrderedInsert] SET ALLOW_SNAPSHOT_ISOLATION ON
GO
USE [OrderedInsert]
GO
CREATE TABLE [dbo].[Test](