Skip to content

Instantly share code, notes, and snippets.

View EmmanuelOga's full-sized avatar
🕹️

Emmanuel Oga EmmanuelOga

🕹️
View GitHub Profile
@EmmanuelOga
EmmanuelOga / main.go
Created October 20, 2023 01:26
Simple recursive algorithm and its cost.
package main
import "fmt"
var cost int
func f2(s, e int) int {
cost += 1
if e <= s {
@EmmanuelOga
EmmanuelOga / resources.md
Last active October 4, 2023 11:58
Some resources on programming, computer science vs engineering, optimization
@EmmanuelOga
EmmanuelOga / rpn.hs
Last active May 11, 2023 08:44
A simple RPN expression parser and calculator in haskell.
data Operator = Plus | Minus | Multiply | Divide deriving Show
data Token = Val Int | Op Operator deriving Show
calc :: [Token] -> [Int] -> Either String Int
calc (Val t:ts) xs = calc ts (t:xs)
calc (Op Minus:ts) (a:b:xs) = calc ts ((a - b):xs)
calc (Op Plus:ts) (a:b:xs) = calc ts ((a + b):xs)
calc (Op Multiply:ts) (a:b:xs) = calc ts ((a * b):xs)
calc (Op Divide:ts) (a:b:xs) = calc ts ((a `div` b):xs)
calc [] [x] = Right x
import it.unimi.dsi.fastutil.objects.ObjectAVLTreeSet
data class Quad(val s: String = "", val p: String = "", val o: Comparable<Any>? = null, val c: String = "") :
Comparable<Quad> {
override fun compareTo(other: Quad): Int = compareValuesBy(this, other, Quad::s, Quad::p, Quad::o, Quad::c)
override fun toString(): String = "Q<S=$s P=$p O=$o C=$c>"
}
@EmmanuelOga
EmmanuelOga / commit-msg
Created June 13, 2012 22:01
commit-msg hook to add a prefix to commit messages
#!/usr/bin/env ruby
#
# Git commit-msg hook. If your branch name is in the form "US1234-postfix", or
# "US1234_postfix", it automatically adds the prefix "[US1234]" to commit
# messages.
#
# Example
# =======
#
# git checkout -b US1234-some-cool-feature
@EmmanuelOga
EmmanuelOga / hello_world.cairo.c
Created January 6, 2010 03:29
gcc hello_world.cairo.c -lcairo -ohello_world
#include <cairo/cairo.h>
int
main (int argc, char *argv[])
{
cairo_surface_t *surface =
cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
cairo_t *cr =
cairo_create (surface);
@EmmanuelOga
EmmanuelOga / index.md
Last active December 11, 2021 16:26
Simpler HTTP APIs

Simpler HTTP APIs

A quick note on writing HTTP APIs in an RPC style ... also sharing my enthusiasm for RDF and RDF schemas all around :-)

Typical HTTP API design

Someone put together a crazy big decision diagram explaining which status code to return under which circumstance, etc.

In practice, many HTTP service APIs work more like a Remote Procedure Call and less like a fully conforming "Hypermedia Service". Headers are usually considered "low level", used for things like caching, ETags, cookies, CORS, etc.

@EmmanuelOga
EmmanuelOga / json-ld.js
Created November 27, 2020 09:34
From JSON-LD to TriG, requires "jsonld" and "n3" npm packages.
import * as jsonld from "jsonld";
import * as n3 from "n3";
const doc = { "YOUR" : "JSONLD" };
const nquads = await jsonld.toRDF(doc, { format: "application/n-quads" });
const parser = new n3.Parser({ format: "application/n-quads" });
const writer = new n3.Writer({ format: "application/trig" });
await parser.parse(nquads, (error, quad, prefixes) => {
@EmmanuelOga
EmmanuelOga / IterateCodepoints.java
Last active September 16, 2021 22:34
Iterating over the "letters" (codepoints, not chars) of a string.
package com.emmanueloga.cracking.arrays;
import java.util.Iterator;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
class StringCodepointsIterable implements Iterable<String> {
public class StringCodepointsIterator implements Iterator<String> {
private int index = 0;