Skip to content

Instantly share code, notes, and snippets.

@Eyas
Eyas / EdmondsKarp.cs
Created November 18, 2013 01:08
Edmonds Karp in C#
using System;
using System.Collections.Generic;
namespace Algorithms
{
/// Edmonds Karp MaxFlow Algorithm
/// based on en.wikipedia.org/wiki/Edmonds%E2%80%93Karp_algorithm
public class EdmondsKarp {
private int n = 0;
/**
* Unpack-able variadic tuples in C++. You can use these classes to conviniently unpack
* tuple contents as an lvalue using the `unpack` function.
*
* Example:
* tuple<int, double, int> t(1, 5.0, 3);
* int x_1; double x_2; int x_3;
* unpack(x_1, x_2, x_3) = t;
*/
@Eyas
Eyas / promise.ts
Last active August 29, 2015 14:20
Simple TypeScript Promises
module simple {
export class Promise<T> {
public map<R>(func: (t: T) => R): Promise<R> {
var promise: Promise<R> = new Promise<R>();
if (this.v !== undefined) promise.result(func(this.v));
else if (this.e !== undefined) promise.result(this.e);
else {
this.tcb.push(t => {
promise.result(func(t));
});
@Eyas
Eyas / keybase.md
Last active September 16, 2019 19:05
Keybase proof

Keybase proof

I hereby claim:

  • I am eyas on github.
  • I am eyas (https://keybase.io/eyas) on keybase.
  • I have a public key ASAA-BJC35BzpVJ3h34r6dxKm5_WB126wVPWzA438NYViQo

To claim this, I am signing this object:

function parseComment(comment: string): string {
const result: string[] = [];
const parser = new Parser({
ontext: text => result.push(replace(text)),
onopentag: (tag, attrs) => {
switch (tag) {
case 'a': result.push(`{@link ${attrs['href']} `); break;
case 'em': case 'i': result.push('_'); break;
case 'strong': case 'b': reslt.push('__'); break;
// ...
// Tag Management: Define functions describing what to do with HTML tags in our
// comments.
interface OnTag {
open(attrs: {[key: string]: string}): string;
close(): string;
}
// Some handlers for behaviors that apply to multiple tags:
const em: OnTag = { open: () => '_', close: () => '_' };
const strong = { open: () => '__', close: () => '__' };
export class Class {
// ...
private baseNode(skipDeprecatedProperties: boolean, context: Context):
TypeNode {
// ...
const parentNode = /* ... */;
const isRoot = parentNode === null;
const propLiteral = createTypeLiteralNode([
// Add an '@id' property for the root.
- } else if (propLiteral.members.length > 0) {
- return propLiteral;
} else {
- return createTypeLiteralNode([]);
+ return propLiteral;
}
// Top-level module:
const wellKnownTypes = [ ... ]; // Top-level var with more than one "Type".
const dataType = ...;
function ForwardDeclareClasses(topics: ReadonlyArray<TypedTopic>): ClassMap {
const classes = new Map<string, Class>();
for (const wk of wellKnownTypes) {
classes.set(wk.subject.toString(), wk);
}
classes.set(dataType.subject.toString(), wk);
- if (classes.size === 0) {
- throw new Error('Expected Class topics to exist.');
- }