Skip to content

Instantly share code, notes, and snippets.

@danneu
danneu / .elm
Last active August 6, 2017 16:12 — forked from pablohirafuji/defaultvalue-vs-value.elm
Elm defaultValue vs value -- Paste into http://elm-lang.org/try
import Html exposing (..)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput, onClick)
main =
Html.beginnerProgram { model = Model "" "", view = view, update = update }
type alias Model =
@danneu
danneu / Json.scala
Created July 28, 2017 09:43 — forked from pchiusano/Json.scala
Simple JSON parser combinator library that does not use zippers
// WARNING! totally untested, I have only compiled the code! :)
package json
import collection.immutable.Map
import scalaz.{\/, MonadPlus}
import scalaz.\/._
import scalaz.std.vector._
import scalaz.std.map._
import scalaz.std.list._
@danneu
danneu / .kt
Last active July 15, 2017 16:59
package com.danneu.result
class State <T> (var target: T, var tip: String? = null) {
override fun toString() = "[State tip=$tip]"
}
typealias ResultState <T> = Result<State<T>, String>
package com.danneu.msgpack
import org.msgpack.core.MessagePack
import org.msgpack.core.MessagePacker
import org.msgpack.core.MessageUnpacker
import org.msgpack.value.ValueType
import java.math.BigInteger
// DEMO: Encode <-> Decode roundtrip
MZPˇˇ∏@∫¥ Õ!∏LÕ!êêThis program must be run under Win32
$7PEL^B*‡éÅ "Ï/@@† ù
@pÜ! @|: #¿^∞CODEà " `DATAî@&@¿BSSE `8¿.idataÜ!p"8@¿.tls†Z¿.rdata∞Z@P.reloc^¿`\@P.rsrc@| ~º@Pp @P
package com.danneu.result
// These were moved into extension functions since they violated `out` constraint
// when implemented as instance methods.
/**
* Result.ok(42).getOrElse(-1) == 42
* Result.err("failure").getOrElse(-1) == -1
*/
fun <V, E> Result<V, E>.getOrElse(default: V): V = when (this) {
'use strict'
// 3rd
const uuid = require('uuid')
const debug = require('debug')('app:middleware:track')
// 1st
const db = require('../db')
const {isValidUuid, futureDate} = require('../belt')
module.exports = ({cookieKey = 't', interval = 5000} = {}) => {
debug('initializing track middleware')
CREATE TABLE users (
id bigserial PRIMARY KEY,
uname text NOT NULL,
created_at timestamptz NOT NULL DEFAULT NOW()
);
-- A hit is inserted for every authenticated page view
CREATE TABLE hits (
id bigserial PRIMARY KEY,
user_id int NOT NULL REFERENCES users(id) ON DELETE CASCADE,
var SecondaryClipboard = {
cut: function(editorState: EditorState): EditorState {
var content = editorState.getCurrentContent();
var selection = editorState.getSelection();
var targetRange: ?SelectionState = null;
if (selection.isCollapsed()) {
var anchorKey = selection.getAnchorKey();
var block = content.getBlockForKey(anchorKey);
var blockEnd = block.getLength();
import {
EditorState,
ContentBlock,
genKey
} from 'draft-js'
// Inserts a new block before the current block and selects it
export function insertBlockBefore (editorState, newBlock) {
return injectBlock(true, editorState, newBlock)