Skip to content

Instantly share code, notes, and snippets.

View coot's full-sized avatar
:octocat:

Marcin Szamotulski coot

:octocat:
View GitHub Profile
@coot
coot / gist:5897200
Created June 30, 2013 22:12
PEP 342 (http://www.python.org/dev/peps/pep-0342/) contains an example of a Trampoline (i.e. manager of coroutines) and an example of a simple server based on it. It is lacking a few details though. Here is working example. It does not catch StopIteration excetpion by design. You can add time.sleep(1) in Trampoline.run method to slow it down.
import collections
import types
import sys
import time
import logging
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
stdh = logging.StreamHandler()
const dgram = require("dgram");
const ssdpRequest = `M-SEARCH * HTTP/1.1
HOST: 239.255.255.250:1900
MAN: "ssdp:discover"
MX: 0
ST: urn:schemas-sony-com:service:ScalarWebAPI:1
USER-AGENT: nodejs
`;
@coot
coot / func.js
Last active September 16, 2016 09:19
Simple and useful functional tools for javascript
"use strict";
/**
* A tiny functional library.
*/
/**
* reduceObject - reduce an object
*
* @param {object} obj
@coot
coot / bls.py
Created December 29, 2016 09:59
A script which lists all buffers in all running vim instances
#!/usr/bin/python
"""
The %prog (vim buffer ls) lists files hosted on all running vim servers. Star
before file indicates that the buffer is loaded.
"""
"""
Author: Marcin Szamotulski
"""
@coot
coot / Main.purs
Last active August 18, 2017 02:28
Compose Free / Cofree DSL's
module Main where
import Control.Comonad.Cofree (Cofree, explore, head, mkCofree, tail, unfoldCofree)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Free (Free, liftF)
import Data.Either (Either(..))
import Data.Foldable (fold)
import Data.Functor.Coproduct (Coproduct(..), left, right)
import Data.Functor.Product (Product(..), product)
@coot
coot / Main.purs
Last active June 29, 2017 09:47
Compose Streams
module Main where
import Prelude
import TryPureScript
import Control.Comonad.Cofree (Cofree, head, mkCofree, tail, unfoldCofree)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Unsafe (unsafePerformEff)
import Data.Array (fromFoldable)
@coot
coot / Main.purs
Last active April 22, 2018 15:01
PureScript: pick subrecords from a record.
module Main where
import Prelude
import Data.Foldable (fold, elem)
import TryPureScript
import Type.Row (class ListToRow, class RowToList, Cons, Nil, kind RowList)
import Type.Proxy (Proxy(..))
import Type.Data.Symbol (class IsSymbol, reflectSymbol)
import Data.Array (cons)
import Data.Monoid (mempty)
@coot
coot / Main.purs
Last active July 21, 2017 07:48
React.RecSpec
module React.RecSpec where
import Control.Monad.Eff (Eff, kind Effect)
import Data.Maybe (Maybe(..), fromMaybe)
import Data.Record as R
import Prelude (Unit, bind, pure, show, unit, ($))
import React (Disallowed, ReactElement, ReactProps, ReactRefs, ReactState, ReadOnly, ReadWrite)
import React.DOM as D
import Type.Data.Symbol (class IsSymbol, SProxy(..))
import Type.Row (class RowLacks)
@coot
coot / term.vim
Created September 17, 2017 22:12
Vim 8.1112 terminal helper
set tk=<C-L>
tmap <c-x> <c-l>:hide<cr>
tmap <c-w><c-x> <c-l>:bd!<cr>
" Find first terminal buffer
fun! TermBufNr()
redi => ls
filter #\v<(zsh|bash)># ls
redi END
@coot
coot / Main.purs
Last active September 23, 2017 09:27
Array builder
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (logShow)
import Control.Monad.ST (ST, pureST)
import Data.Foreign (Foreign, toForeign)
import Data.StrMap as StrMap
import Data.StrMap.ST as STStrMap