Skip to content

Instantly share code, notes, and snippets.

@gbluma
gbluma / index.php
Created June 20, 2012 15:47
Use Joomla outside of Joomla
<?php
error_reporting(E_ALL);
define( '_JEXEC', 1 );
define( 'JPATH_BASE', realpath(dirname(__FILE__) .'/' ) );
define( 'DS', DIRECTORY_SEPARATOR );
// PREPARE
require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' );
@gbluma
gbluma / GameState.hs
Created June 23, 2012 04:57
Finally wrote out a decent proof-of-concept for a resource pool
module GameState where
import qualified Control.Monad.State as ST
-- define our data structure w/o any special state information
data GameState = GameState {
gs_camera_x :: Float,
gs_camera_y :: Float,
gs_camera_z :: Float
}
@gbluma
gbluma / get-lines.rkt
Created September 10, 2012 20:18
Simple recursive function to build a list of paired points (line segments) that also loops back to first element.
#lang racket
(define shapes '(((0 0) (0 110) (220 0 ) (220 110))
((1 1) (1 111) (221 1 ) (221 111)))
)
(define (get-lines shape output)
;; do we have enough elements to build a pair?
(if (> (length shape) 1)
;; ... more than one element (build pair and recurse)
@gbluma
gbluma / fdep.v
Created September 21, 2012 04:50
Functional Dependency Theory in Coq
(*
The following is an attempt at verifying Armstrong's axioms[1] of functional dependencies.
These include: Reflexivity, Transitivity, Augmentation, Union, Decomposition, and
Pseudotransitivity. These appear to hold, and should be considered valid axioms.
[1] http://en.wikipedia.org/wiki/Armstrong's_axioms
*)
Theorem dep_reflexivity :
forall a:Prop,
<?php
class Matcher {
private $cases = array();
function __construct($target, $source) {
$this->target = $target;
$this->source = $source;
}
module Main where
import Control.Concurrent (forkIO, threadDelay)
import Control.Monad
-- from package "HTTP"
import Network.HTTP
import Network.HTTP.Headers
import Network.HTTP.Base
@gbluma
gbluma / hindley_milner.php
Last active January 16, 2017 16:05
A Hindley-Milner type-system in PHP.
<?php
/** Lambda abstraction */
class Lambda
{
function __construct($v, $body) {
$this->v = $v;
$this->body = $body;
}
@gbluma
gbluma / Simpson.scala
Last active December 14, 2015 19:58
Using Simpson's rule to calculate integrals in Scala.
/** Desc: Using Simpson's rule to calculate integrals in Scala.
* Date: March 11, 2013
* Author: Garrett Bluma
*/
object Simpson
{
def sum(term:Double=>Double, a:Double, next:Double=>Double, b:Double):Double =
if (a > b) 0.0
else term(a) + sum(term, next(a), next, b);
@gbluma
gbluma / Simpson.flx
Created March 12, 2013 04:18
Simpson's rule to calculate integrals in Felix. (Very similar to Scala version: http://gist.github.com/gbluma/5140262 )
/** Using Simpson's rule to calculate integrals in Felix
* Date: March 11, 2013
* Author: Garrett Bluma
h/3 (y_0 + 4y_1 + 2y_2 + 4y_3 + 2y_4 + ... + 2y_{n-2} + 4y_{n-1} + y_n)
where h = (b - a)/n for some even integer n
y_k = f(a + kh)
@gbluma
gbluma / gist:5140384
Created March 12, 2013 04:34
Simpson's rule to calculate integrals in Idris.
-- Using Simpson's rule to calculate integrals in Idris.
-- Date: March 11, 2013
-- Author: Garrett Bluma
module Simpson
mysum : (Float -> Float) -> Float -> (Float -> Float) -> Float -> Float
mysum term a next b =
if (a > b)