Skip to content

Instantly share code, notes, and snippets.

@gatlin
gatlin / mymap.pl
Created December 26, 2011 23:42
Functional definition of map in Perl
#!/usr/bin/env perl
use strict;
use warnings;
sub myMap (&@) {
my ($fn, @lst) = @_;
return () unless @lst;
return (sub { local $_=$_[0];$_[1]->() }->($lst[0],$fn),
&myMap( $fn, @lst[1..$#lst] ));
@gatlin
gatlin / sat.hs
Created February 6, 2012 23:05
SAT Solver in Haskell
-- This is going to be on Hackage soon! https://github.com/gatlin/surely
{-# LANGUAGE BangPatterns #-}
-- |
-- Module : AI.Surely
-- Copyright : 2012 Gatlin Johnson
-- License : LGPL 3.0
-- Maintainer : rokenrol@gmail.com
-- Stability : experimental
@gatlin
gatlin / lexical.pl
Created June 27, 2012 07:18
Extremely basic example of lexical scope use in Perl
#!/usr/bin/env perl
use v5.16;
use strict;
use warnings;
sub c {
my $lexicalValue = 0;
return sub {
say $lexicalValue;
@gatlin
gatlin / hello.ll
Created July 6, 2012 01:48
LLVM output of a simple Haskell program
target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
target triple = "x86_64-apple-darwin10.0.0"
declare ccc i8* @memcpy(i8*, i8*, i64)
declare ccc i8* @memmove(i8*, i8*, i64)
declare ccc i8* @memset(i8*, i64, i64)
declare ccc i64 @newSpark(i8*, i8*)
%__stginit_Main_struct = type <{}>
@__stginit_Main = global %__stginit_Main_struct<{}>
%sfT_srt_struct = type <{i64}>
@gatlin
gatlin / hello.hs
Created July 6, 2012 01:49
Simple Haskell program
module Main where
main = do
putStrLn $ "Hello, World!"
@gatlin
gatlin / hello.js
Created July 6, 2012 01:51
Emscripten output for a simple Haskell program
// Note: Some Emscripten settings will significantly limit the speed of the generated code.
// Note: Some Emscripten settings may limit the speed of the generated code.
// TODO: " u s e s t r i c t ";
try {
this['Module'] = Module;
} catch(e) {
this['Module'] = Module = {};
}
@gatlin
gatlin / degree.pl
Created July 29, 2012 21:00
Simple regex for DMS angle notation
#!/usr/bin/env perl
use v5.16;
use strict;
use warnings;
while (my $str = <STDIN>) {
say "DMS" if $str =~
m/([0-9]+(\W*)deg((ree)?s?)?)?(\W*)([0-9]+(\W*)min((ute)?s?)?)?(\W*)([0-9]+(\.[0-9]*)?(\W*)sec((ond)?s?)?)?/;
}
@gatlin
gatlin / orc-sample.lsp
Created August 11, 2012 18:35
Sample Orc DSL for Common Lisp
; examples from http://orc.csres.utexas.edu/tryorc.shtml#tryorc/tutorial/
; site definition, similar to a function but handles network transparency and will publish multiple values if you call them
; multiple times
; they will necessarily hide much magic
(defsite name (arg)
(body ...))
; I may consider using plain-old functions for this but at the moment I might need to hide some magic
@gatlin
gatlin / main.go
Created August 13, 2012 22:23
Concepts from Orc applied in Go
package main
import (
"fmt"
"github.com/gatlin/go-orc"
"net/http"
"time"
)
/*
@gatlin
gatlin / uninstall-haskell-osx.sh
Last active April 11, 2024 22:31
Uninstall Haskell from Mac OS X
#!/bin/bash
# source: http://www.haskell.org/pipermail/haskell-cafe/2011-March/090170.html
sudo rm -rf /Library/Frameworks/GHC.framework
sudo rm -rf /Library/Frameworks/HaskellPlatform.framework
sudo rm -rf /Library/Haskell
rm -rf ~/.cabal
rm -rf ~/.ghc
rm -rf ~/Library/Haskell