Skip to content

Instantly share code, notes, and snippets.

View leobm's full-sized avatar

Felix Wittmann leobm

  • Hamburg, Germany
View GitHub Profile
@leobm
leobm / echo-ws-server.pl
Created June 21, 2020 15:52 — forked from willprice/echo-ws-server.pl
SWI-Prolog echo server with some JSON manipulation using websockets.
% INSTRUCTIONS
% =swipl echo-server.pl=
% =:- start_server.=
%
% Then navigate to http://localhost:3000 in your browser
:- module(echo_server,
[ start_server/0,
stop_server/0
@leobm
leobm / 1_promise.cljc
Created April 4, 2020 16:05 — forked from jaidetree/1_promise.cljc
A WIP library of promise macros for ClojureScript
(ns cljs.promise
(:refer-clojure :exclude [resolve]))
(defmacro promise
"
Example:
(promise (resolve 5))
(promise (reject (js/Error. \"oops\")))
"
@leobm
leobm / math.asm
Created January 10, 2020 12:24 — forked from hausdorff/math.asm
mod and div implemented in 6502 asm
; load some data up
LDA #$7
STA $00 ; memory addr A
LDA #$05
STA $01 ; memory addr B
JMP Divide
;modulus, returns in register A
Mod:
LDA $00 ; memory addr A
@leobm
leobm / mini-promise.cljc
Created August 7, 2019 12:56 — forked from beders/mini-promise.cljc
Super minimal macro to simplify dealing with promise/async/await code in ClojureScript
(defn create-function-call [param expr]
"Create an sexp for calling expr with a first argument provided by a promise.
If expr is a list (already in form suitable for a function call), insert the first argument at second position,
otherwise turn expr into a function call expression, unless the function is an fn, which is simply returned.
println -> (fn [param] (println param))
(* 2) -> (fn [param] (* param 2))
@leobm
leobm / detect_colors.py
Last active March 2, 2019 12:57
software that can name colors
# Use the tool
# python detect_color.py --image source.png
#
# Install the opencv and numpy packages before
# python -m pip install numpy
# python -m pip install opencv-python
# python -m pip install scikit-learn
# import the necessary packages
import numpy as np
@leobm
leobm / elementChange.js
Created September 21, 2018 11:14 — forked from psyrendust/elementChange.js
Add and remove MutationObserver events to a registered DOM element.
/**
* @typedef MutationCallback
* @param {NodeList} addedNodes A NodeList of elements that have been added to the DOM.
* @param {NodeList} removedNodes A NodeList of elements that have been removed from the DOM.
*/
/**
* Add a MutationObserver to a DOM node.
*
* @example
*

The project can be built using Lumo

npm install -g lumo-cljs
lumo build.cljs
@leobm
leobm / core.clj
Created June 3, 2017 15:52 — forked from philippkueng/core.clj
Fetch & write a binary file using Clojure and clj-http
(ns the-namespace.core
(:require [clj-http.client :as client]
[clojure.java.io :as io]))
(defn- fetch-photo!
"makes an HTTP request and fetches the binary object"
[url]
(let [req (client/get url {:as :byte-array :throw-exceptions false})]
(if (= (:status req) 200)
(:body req))))
@leobm
leobm / Either.scala
Created April 13, 2017 10:07 — forked from owainlewis/Either.scala
Validation examples
object EitherValidationExamples {
type ValidationError = String
def validateEmail(user: User): Either[ValidationError, User] =
if (user.email contains "@") Right(user) else Left("Must supply a valid email")
def validateAge(user: User): Either[ValidationError, User] =
if (user.age > 18) Right(user) else Left("Must be over 18")
@leobm
leobm / uri.js
Created February 14, 2017 11:04 — forked from jlong/uri.js
URI Parsing with Javascript
var parser = document.createElement('a');
parser.href = "http://example.com:3000/pathname/?search=test#hash";
parser.protocol; // => "http:"
parser.hostname; // => "example.com"
parser.port; // => "3000"
parser.pathname; // => "/pathname/"
parser.search; // => "?search=test"
parser.hash; // => "#hash"
parser.host; // => "example.com:3000"