Skip to content

Instantly share code, notes, and snippets.

/** Used by Flavor to mark a type in a readable way. */
export interface Flavoring<FlavorT> {
_type?: FlavorT;
}
/** Create a "flavored" version of a type. TypeScript will disallow mixing flavors, but will allow unflavored values of that type to be passed in where a flavored version is expected. This is a less restrictive form of branding. */
export type Flavor<T, FlavorT> = T & Flavoring<FlavorT>;
/** Used by Brand to mark a type in a readable way. */
export interface Branding<BrandT> {
_type: BrandT;
@piecyk
piecyk / sds011
Created November 25, 2017 15:51 — forked from kadamski/sds011
SDS011 dust sensor reading
#!/usr/bin/python
# coding=utf-8
# "DATASHEET": http://cl.ly/ekot
from __future__ import print_function
import serial, struct, sys, time
DEBUG = 1
CMD_MODE = 2
CMD_QUERY_DATA = 4
CMD_DEVICE_ID = 5
@piecyk
piecyk / sds011
Created November 25, 2017 15:51 — forked from kadamski/sds011
SDS011 dust sensor reading
#!/usr/bin/python
# coding=utf-8
# "DATASHEET": http://cl.ly/ekot
from __future__ import print_function
import serial, struct, sys, time
DEBUG = 1
CMD_MODE = 2
CMD_QUERY_DATA = 4
CMD_DEVICE_ID = 5
@piecyk
piecyk / HOCBaseRender.tsx
Created August 28, 2017 13:57 — forked from tejacques/HOCBaseRender.tsx
React Higher Order Components in TypeScript
import * as React from 'react';
import { Component } from 'react';
export default function HOCBaseRender<Props, State, ComponentState>(
Comp: new() => Component<Props & State, ComponentState>) {
return class HOCBase extends Component<Props, State> {
render() {
return <Comp {...this.props} {...this.state}/>;
}
}
@piecyk
piecyk / Enhance.js
Created March 29, 2016 11:42 — forked from sebmarkbage/Enhance.js
Higher-order Components
import { Component } from "React";
export var Enhance = ComposedComponent => class extends Component {
constructor() {
this.state = { data: null };
}
componentDidMount() {
this.setState({ data: 'Hello' });
}
render() {
@piecyk
piecyk / postgis.clj
Created October 6, 2015 10:21 — forked from attentive/postgis.clj
PostGIS and Korma
(ns postgis
(:require [clj-json.core :as json])
(:use korma.core korma.db korma.sql.engine))
(defn intersects [first-geom second-geom]
"An extended Korma predicate that uses the PostGIS function ST_Intersects."
(sql-func "ST_Intersects" first-geom second-geom))
(defn from-wkt [wkt]
"Create a PostGIS geometry with geographic SRID from WKT using ST_GeomFromText."
@piecyk
piecyk / bloop.js
Last active September 22, 2015 11:19 — forked from jlongster/bloop.js
bloop
(function() {
// Do not use this library. This is just a fun example to prove a
// point.
var Bloop = window.Bloop = {};
var mountId = 0;
function newMountId() {
return mountId++;
}
@piecyk
piecyk / ScalaEnum.scala
Last active August 29, 2015 14:27 — forked from viktorklang/ScalaEnum.scala
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
(add-hook 'js-mode-hook '(lambda ()
;; /home/hvesalai/projects/foo/Bar.jsx: line 6, col 63
(add-to-list 'compilation-error-regexp-alist-alist
`(eslint-compact
,(rx line-start
(group (zero-or-one letter ":") (1+ (not (any ": "))))
": line " (group (1+ digit))
", col " (group (1+ digit)))
1 2 3))
@piecyk
piecyk / config.js
Last active August 29, 2015 14:18 — forked from mccahill/config.js
module.exports = {
'HOSTPATH': 'http://your.host.here',
'PORT': 80,
'EXPRESS_SESSION_SECRET': '123456',
'TWITTER_CONSUMER_KEY': 'your-consumer-key-here',
'TWITTER_CONSUMER_SECRET': 'your-secret-here',
'GOOGLE_APP_ID': 'your-app-id-here',
'GOOGLE_CONSUMER_SECRET': 'your-consumer-secret-here',
};