Instantly share code, notes, and snippets.

View lsb.c
unsigned int v;
int r;
static const int MultiplyDeBruijnBitPosition[32] =
{
0, 1, 28, 2, 29, 14, 24, 3, 30, 22, 20, 15, 25, 17, 4, 8,
31, 27, 13, 23, 21, 19, 16, 7, 26, 12, 18, 6, 11, 5, 10, 9
};
r = MultiplyDeBruijnBitPosition[((uint32_t)((v & -v) * 0x077CB531U)) >> 27];
View eulerian_circuit.js
function find_circuit(graph: Graph, initialVertex: number) {
let vertex = initialVertex;
const path = new Path();
path.append(vertex);
while (true) {
const edge = graph.getNextEdgeForVertex(vertex);
if (edge == null) {
throw new Error("This graph is not Eulerian");
View person.js
var joe = {
name: "Joe",
age: 20,
job: "carpenter"
};
View person_new_valid.ml
(* Creating record *)
let joe = person ~name:"Joe" ~age:20 ~job:"Programmer"
let joeNameVerbose = name joe
let joeName = joe |. name
View person_new.ml
{name: "Joe", age: 20, job: "teacher"}
View person.ml
type person = {
name: string;
age: int;
job: string [@bs.optional];
} [@@bs.deriving abstract]
View map.ml
let mapping: string Js.Dict.t = Js.Dict.empty ()
(* Error: This expression has type int but an expression was expected of type *)
let () = Js.Dict.set mapping "some_key" 10
View module_syntax.txt
external <function name alias> :
<function type interface> =
<function name> [[@@bs.module "<module name>"]
View read_file.ml
external readFile :
name:string ->
([ `utf8
| `useAscii [@bs.as "ascii"]
] [@bs.string]) ->
(string -> string -> unit) ->
unit = ""
[@@bs.module "fs"]
let callback error data = Js.log(data)
View read_file.js
fs = require("fs");
fs.readFile("data.json", "utf8", (err, data) => {
console.log(data);
});