Skip to content

Instantly share code, notes, and snippets.

View gilesbradshaw's full-sized avatar
🕶️
riding my bicycle

Giles gilesbradshaw

🕶️
riding my bicycle
  • SiGyl
  • Devon
View GitHub Profile
@gilesbradshaw
gilesbradshaw / gist:658b575201b3dd828d56
Created September 22, 2014 20:05
convert rx observable to knockout observable with subscription and disposal
(function(){
function addSubscribeDispose(observable, subscribe, dispose) {
var subscriptions = [];
var oldSubscribe = observable.subscribe.bind(observable);
observable.subscribe = function (callback, callbackTarget, event) {
var oldDispose, ret;
ret = oldSubscribe(callback, callbackTarget, event);
if (!subscriptions.length) {
subscribe();
@gilesbradshaw
gilesbradshaw / gist:56925d916d4720421840
Created May 22, 2015 12:29
simple jquery valuidate
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script src="Scripts/jquery-1.9.1.js"></script>
<script src="Scripts/jquery.validate.js"></script>
<script>
@gilesbradshaw
gilesbradshaw / gist:086cd97a885a6c51770e
Last active August 29, 2015 14:23
Component library
var __componentLibrary = function () {
//an event source lets to add and remove listeners, trigger events and get the last value triggered
var EventSource = function () {
var _this = this;
_this.events = {};
_this.values = {};
_this.addEventListener = function (name, handler, noInitialEvent) {
if (_this.events.hasOwnProperty(name))
_this.events[name].push(handler);
module Shapes
( Point(..)
, Shape(..)
, area
, nudge
, baseCircle
, baseRectangle
) where
data Point = Point Float Float deriving (Show)
infixr 5 :-:
data List a = Empty | a :-: (List a) deriving (Show, Read, Eq, Ord)
infixr 5 ^++
(^++) :: List a -> List a -> List a
Empty ^++ ys = ys
(x :-: xs) ^++ ys = x :-: (xs ^++ ys)
instance (Eq m) => Eq (Maybe a) where
Just m == Just n = m == n
Nothing == Nothing = True
_ == _ = False
@gilesbradshaw
gilesbradshaw / treesearch
Last active October 30, 2015 23:58
Tree
-- making and searching a binary search tree in haskell
data Tree a = EmptyTree | Node a (Tree a) (Tree a) deriving (Show)
singleton :: a -> Tree a
singleton x = Node x EmptyTree EmptyTree
treeInsert :: (Ord a) => a -> Tree a -> Tree a
treeInsert x EmptyTree = singleton x
treeInsert x (Node a left right)
@gilesbradshaw
gilesbradshaw / arithmetic parser
Last active November 28, 2015 02:21
arithmetic parse (and other stuff) eval "(1+2)*3+4"
-- from hutton
import Control.Applicative -- Otherwise you can't do the Applicative instance.
import Control.Monad (liftM, ap)
import Data.Char
newtype Parser a = P(String -> [(a, String)])
primes :: [Int]
primes = sieve [2..]
sieve :: [Int] -> [Int]
sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /=0]
module Lab5 where
import Control.Monad
data Concurrent a = Concurrent ((a -> Action) -> Action)
instance Functor Concurrent where
fmap = liftM
instance Applicative Concurrent where