Skip to content

Instantly share code, notes, and snippets.

View spion's full-sized avatar
:shipit:

Gjorgji Kjosev spion

:shipit:
View GitHub Profile
@spion
spion / existing.sql
Last active November 9, 2015 04:58 — forked from eduardoleon/existing.sql
create table male
( male_id int not null
, primary key (male_id) );
create table female
( female_id int not null
, primary key (female_id) );
create table name
( id int not null
@spion
spion / table.ts
Created November 6, 2015 18:00 — forked from whoeverest/table.ts
/// <reference path="anydb-sql.d.ts" />
import anydbsql = require('anydb-sql');
var db = anydbsql({
url: 'postgres://user:pass@host:port/database',
connections: { min: 2, max: 20 }
});
// Table Post
module ValidEmail (mkEmail, emailToString, EmailAddress) where
newtype EmailAddress = ValidAddress String
validate :: String -> Boolean
validate email = ...
mkEmail :: String -> Maybe ValidEmail
mkEmail = case validate email of
@spion
spion / 01-fractal-weird-design.md
Last active November 2, 2019 12:27
Node streams - a fractal of weird design

Node streams - a fractal of weird design

and a potential refactor that could fix that

This is a list of issues and confusions I've encountered with node streams, and things I wish were designed and implemented differently. If promise-streams is ever going to change to a design that doesn't build on top of node streams, this would be a list of mistakes to avoid

  1. enc parameter - Why is encoding always passed together with the data? It should be a separate concern. It doesn't even make sense in objectMode
  2. eventemitter base - This encourages a lot of random events to be "attached" by other authors which doesn't work. Best to have an uniform (typed) interface so that everyone knows what to expect.
  3. relying on nextTick etc for execution order - This is very unreliable and causes all sorts of unpredictable rules for implementers which are not documented anywhere. When you attach listeners determines what will happen.
  4. no error propagation - we need the
var observer = require('promise-observer')
var Promise = require('bluebird');
var assert = require('assert');
function mkTransaction(tId) {
var queries = []
return {
query: function query(q) { queries.push(q); return query },
close: function() { queries.push('close ' + tId); return queries; }
}
@spion
spion / kulvezba.md
Last active September 28, 2015 23:05

Кул вежба

Да направиме сервис кој има два endpoints

/data endpoint

Враќа min/max/average/current за температурите, бројот на присутни и отворен/затворен сензорите во Хаклаб земајќи податоци до Xively

Формат: JSON, dictionary of sensor name to Object { min, max, avg, current }

getDataAsync :: String -> IO (IO ByteString)
getDataAsync url = do
m <- newEmptyMVar
_ <- forkIO $ HTTP.simpleHttp url >>= putMVar m
return $ readMVar m
-- More generally:
async :: IO a -> IO (IO a)
{
"type": "Program",
"body": [
{
"type": "ExpressionStatement",
"expression": {
"type": "MemberExpression",
"computed": true,
"object": {
"type": "Identifier",
@spion
spion / build.sh
Last active August 29, 2015 14:27
Initialize typescript/react project
tsc
browserify lib/main.js -o bundle.js -d
@spion
spion / 01-future.js
Last active June 26, 2016 20:52 — forked from robotlolita/0-specification.md
Future and ReaderT with auto-lifting and example
class Future {
constructor(computation) {
this.fork = computation
this.__future__ = true;
}
static is(val) {
return (val != null && val.__future__ === true)
}
static of(value) {
if (Future.is(value)) return value;