Skip to content

Instantly share code, notes, and snippets.

View thosakwe's full-sized avatar
🎯
Focusing

Tobe Osakwe thosakwe

🎯
Focusing
View GitHub Profile
@thosakwe
thosakwe / parser.dart
Last active August 15, 2016 11:37
Some parser thing in Dart
foo(stream) {
if (stream.lookahead("if")) {
var ifNode = stream.consume("if");
var elseIfNode = stream.maybe("else if") || stream.maybe("poop")
}
}
var dot = (str) => str.consume(".");
var minus = (str) => str.consume("-");
var parseIf = (str) => str.consume("if");
@thosakwe
thosakwe / fib.lang
Last active October 27, 2016 18:33
Hypothetical funclang
use <filter> as only
use <func> as F
use [Input] of <io>
fn fib(n) {
ret F.decide({
n <= 1 : () => n
}).else(() => F.sum([
fib(n - 1),
fib(n - 2)
@thosakwe
thosakwe / Grammar.g4
Created November 2, 2016 01:11
Pug (nee Jade) with ANTLR
grammar Grammar;
WS: [ \n\r\t] -> skip;
ID: [A-Za-z_] [A-Za-z0-9_]*;
compilationUnit: block*;
block: name=ID '{' (stmt ';'*)* '}';
stmt:
@thosakwe
thosakwe / .stallion
Last active November 2, 2016 01:59
Hypothetical build tool to build OS
mode release {
# Define executables
assembler "i686-elf-as"
compiler "i686-elf-gcc"
bootstrap "boot.s"
link "linker.ld"
sources "src/**/*.c", "path.c"
entry "kernel.c"
grub "menu.grub"
@component()
export default class Layout {
render() {
return div {
this.title(),
this.content()
};
}
}
@thosakwe
thosakwe / main.generated.js
Last active November 29, 2016 12:48
Generate curry functions
function add2(num) {
return num + 2;
}
function add2_array(num[]) {
return num.map(function(num) {
return add2(num);
});
}
@thosakwe
thosakwe / home.dart
Created December 28, 2016 05:23
Angel template hypothetical thing
import 'package:angel_framework/angel_framework.dart';
import 'package:angular2/angular2.dart';
import 'playing_card.dart';
import 'lib/models/user.dart';
@Component(
selector: 'home',
templateUrl: 'home.html',
directives: const [PlayingCardComponent])
class HomeComponent {
@thosakwe
thosakwe / calculator.txt
Last active January 24, 2017 22:17
Dart-specific parser generator.
options {
prefix: 'MyAmazingCalculatorGrammar',
mixins: {
ExampleMixin: 'example_mixin.dart'
}
}
lexer {
// Tags for grouping tokens separately, i.e. comments
@thosakwe
thosakwe / foo.dart
Created April 18, 2017 20:30
Cookies with Dart
import 'dart:convert';
import 'dart:io';
main() async {
var client = new HttpClient();
List<Cookies> sessionCookies = []; // Store our cookies here
// Let's login
var rq = await client.openUrl('POST', 'http://foo.com/login');
rq.write('username=foo&password=bar');
@thosakwe
thosakwe / promises.js
Last active April 20, 2017 12:51
Custom Promise
// http://stackoverflow.com/questions/43519368/promise-practical-self-implement/43519600?noredirect=1#comment74092616_43519600
function Promises(cb) {
if (cb) {
cb(Promises.prototype.resolve.bind(this), Promises.prototype.reject.bind(this));
}
}
Promises.prototype.resolve = function(value) {
if (this.callback) this.callback(value);