Skip to content

Instantly share code, notes, and snippets.

View emilniklas's full-sized avatar

Emil Broman emilniklas

View GitHub Profile
@emilniklas
emilniklas / usage.js
Last active March 31, 2017 17:00
Prototypal mixins i JavaScript + strong TypeScript types
import { mix } from './mix'
class Mixin1 {
one () {}
}
class Mixin2 {
two () {}
}
dependencies:
embla: ^0.1.13
embla_trestle: ^0.1.0
@emilniklas
emilniklas / optional.d.ts
Last active February 17, 2016 06:26
Implementation of optional types in TypeScript. Just replace `null` with `nil` in your app
declare interface Optional<T> {
isNil: boolean
valueOf(): T
}
declare const nil: Optional<any>
interface Object {
isNil: boolean
}
@emilniklas
emilniklas / a-test-1.dart
Last active March 6, 2020 02:29
The Three Rules of TDD in Dart
// T1 – Empty test (Rule 3)
import 'package:test/test.dart';
import 'b-production-1.dart';
main() {
}
@emilniklas
emilniklas / tether_protocol_1.0.md
Last active December 7, 2015 14:44
Tether Protocol v1.0

The Tether Messaging Protocol

Version 1.0

This Gist is the draft document for the Tether Messaging Protocol implemented in the Tether package for Dart.

Introduction

The Web is by definition a very connected platform. A device connected to the internet virtually has access to every other device on the web. There are multiple protocols that describe communications between these devices. For web pages, the dominating protocol is HTTP.

HTTP at the highest level is a standard for mapping resources and actions applied to those resources to a series of methods (GET, POST, PUT, PATCH, DELETE, OPTIONS and more) and URIs.

@emilniklas
emilniklas / entry.dart
Last active November 14, 2015 16:37
RSS templating with Chalk
class Entry {
String title; // My Blog Post
String url; // http://example.com/posts/my-blog-post
String tag; // tag:example.com,2015-11-14:/posts/my-blog-post (http://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id)
DateTime updatedAt; // 2015-11-14
String summary; // A post about an important issue that needs discussing
}
@emilniklas
emilniklas / lib_greeter.dart
Created November 6, 2015 15:59
Testing package level Dart code from the outside
library greeter;
part 'src/greeter.dart';
@emilniklas
emilniklas / benchmark_mirrors.dart
Last active August 29, 2015 14:27
dart:mirrors benchmark
import 'dart:mirrors';
class Class {
int field;
}
final mirror = reflectClass(Class);
final constructor = const Symbol('');
main() {
@emilniklas
emilniklas / nginx_config
Created June 4, 2015 11:33
Nginx proxy with WebSockets
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
server {
listen 80;
server_name example.com;
location / {
proxy_pass http://localhost:1337;
@emilniklas
emilniklas / .travis.yml
Created May 19, 2015 10:12
Dart Travis file
language: dart
dart:
- stable
script: pub run test test/