Skip to content

Instantly share code, notes, and snippets.

Avatar
🕶️
riding my bicycle

Giles gilesbradshaw

🕶️
riding my bicycle
  • SiGyl
  • Devon
View GitHub Profile
@gilesbradshaw
gilesbradshaw / gist:658b575201b3dd828d56
Created Sep 22, 2014
convert rx observable to knockout observable with subscription and disposal
View gist:658b575201b3dd828d56
(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();
View gist:56925d916d4720421840
<!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>
View gist:086cd97a885a6c51770e
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);
View shape.hs
module Shapes
( Point(..)
, Shape(..)
, area
, nudge
, baseCircle
, baseRectangle
) where
data Point = Point Float Float deriving (Show)
View list
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)
View Eq Maybe
instance (Eq m) => Eq (Maybe a) where
Just m == Just n = m == n
Nothing == Nothing = True
_ == _ = False
View treesearch
-- 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 Nov 28, 2015
arithmetic parse (and other stuff) eval "(1+2)*3+4"
View arithmetic parser
-- 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)])
View The Sieve of Aristophenes
primes :: [Int]
primes = sieve [2..]
sieve :: [Int] -> [Int]
sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /=0]
View poor mans concurrency
module Lab5 where
import Control.Monad
data Concurrent a = Concurrent ((a -> Action) -> Action)
instance Functor Concurrent where
fmap = liftM
instance Applicative Concurrent where
You can’t perform that action at this time.