Skip to content

Instantly share code, notes, and snippets.

@anttih
anttih / Merge.purs
Last active December 7, 2018 17:48
module Control.Coroutine.Aff.Utils where
import Prelude
import Control.Coroutine (Producer, consumer, runProcess, ($$))
import Control.Coroutine.Aff (close, emit, produceAff)
import Control.Monad.Trans.Class (lift)
import Data.Maybe (Maybe(..))
import Effect.Aff (Aff, forkAff, parallel, sequential)
import Effect.Aff.AVar as AV
ticker :: Aff _ Unit
ticker = do
v1 <- makeEmptyVar
_ <- forkAff $ forever $ delay (Milliseconds 1000.0) *> putVar unit v1
v2 <- makeEmptyVar
_ <- forkAff $ forever $ delay (Milliseconds 1000.0) *> putVar unit v2
v3 <- liftAff makeEmptyVar
module Concur.VDom where
import Prelude
import Control.Alt (alt)
import Control.Alternative (class Alternative, (<|>))
import Control.Monad.Aff (forkAff, launchAff_)
import Control.Monad.Aff.AVar (makeEmptyVar, makeVar, putVar, takeVar)
import Control.Monad.Aff.Class (class MonadAff, liftAff)
import Control.Monad.Eff (Eff)
@anttih
anttih / parser.rkt
Created August 20, 2013 10:40
My first Typed Racket program: the first pieces of a parser.
#lang typed/racket
(provide (all-defined-out))
(define-type Stream (Listof Char))
(struct: Success ([match : Any] [rest : Stream]) #:transparent)
(struct: Fail () #:transparent)
(define-type Result (U Success Fail))
@anttih
anttih / to-html.ls
Created August 28, 2012 11:52
Simple templating in LiveScript
toHtml = (x) ->
if $.isArray x
if typeof x[0] is not \string then return map(toHtml, x).join('')
switch x.length
case 3
"<#{x[0]} #{objToAttrs(x[1])}>#{toHtml(x[2])}</#{x[0]}>"
case 2
"<#{x[0]}>#{toHtml(x[1])}</#{x[0]}>"
case 1
"<#{x[0]}/>"
(context
(lambda (test)
(test "hello")))
;; I would like this to transform to the above
(group
(test "hello"))
@anttih
anttih / gist:738010
Created December 12, 2010 12:36
Modules in Io (closure problem)
# I'd like the inner object's methods to have access to Module's `inside` slot.
# The new lexicalDo won't cut it since the proto is long gone when the
# block/method gets called.
Module := Object clone do(
inside := 2
Test := Object clone lexicalDo(
num := method(inside)
numblock := block(inside) setIsActivatable(true)
@anttih
anttih / Assert.io
Created November 4, 2010 18:40
Tests for Object assert
Protos AssertionException := Exception clone
Object do(
assert := method(v, m,
if(true != v,
m ifNil(m = "true != (#{ call argAt(0) })" interpolate)
AssertionException raise(m)
)
)
/*jslint regexp: false*/
"use strict";
function hrefs2links(text) {
// Uses Grubers regex with some extra captures
var urire = /\b(?:[a-z][\w\-]+:(?:\/{1,3}|[a-z0-9%])|(www\d{0,3}[.]))((?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/g;
// replace URIs with HTML anchors
return text.replace(urire, '<a href="$&">$1$2</a>');
}
@anttih
anttih / Replace URIs with anchor tags in a string
Created February 4, 2010 18:34
Code to replace URIs in a string with HTML anchors. Uses Grubers regex with some extra captures.
function hrefs2links(text) {
// Uses Grubers regex with some extra captures
var urire = /\b(?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|(www\d{0,3}[.]))((?:[^\s()<>]+|\([^\s()<>]+\))+(?:\([^\s()<>]+\)|[^`!()\[\]{};:'".,<>?«»“”‘’\s]))/g;
// replace URIs with HTML anchors
return text.replace(urire, '<a href="$&">$1$2</a>');
}
var text = hrefs2links("Check out http://example.com");