Skip to content

Instantly share code, notes, and snippets.

View olange's full-sized avatar
🚀

Olivier Lange olange

🚀
View GitHub Profile
@olange
olange / accounting.factory.transaction.clj
Last active November 7, 2022 17:37
Answer to @puredanger's tweet: about the «trouble» I had first using type hints and records in Clojure.
(ns accounting.factory.transaction
(:require [accounting.model.transaction :as transaction]
[accounting.model.document :as document]
[accounting.model.movement :as movement])
(:import [accounting.model.transaction Transaction]
[accounting.model.document Document]
[org.joda.time LocalDate]))
(defn create-exchange-difference
^Transaction
@olange
olange / graphviz-build-system-for-sublime.md
Created January 4, 2015 00:21
Graphviz (DOT) Build System for Sublime Text 2 and 3

To transform the currently opened Graphviz source file (in DOT Language) into a PNG:

{
    "cmd": [ "dot", "-Tpng", "-o", "$file_base_name.png", "$file"],
    "selector": "source.dot"
}

Usage

@olange
olange / neo4j-graphviz-runnning.md
Last active August 29, 2015 14:26
Getting Neo4j Graphviz command-line options right

### Running the Neo4j GraphViz module

The quotes around the nodeTitle, relationshipTitle and nodePropertyFilter must be escaped on the shell command-line, to get them to the graphviz main class:

$ ./graphviz ~/neo4j/data/graph.db \
             relationshipTitle=\"@type\" nodePropertyFilter=name

or

@olange
olange / neo4j-compiling.md
Last active August 27, 2015 22:57
Compiling Neo4j Community on my Mac OS X

Resume of the build instructions found in the Neo4j project page on GitHub.

### Compiling

$ export MAVEN_OPTS="-Xmx512m"
$ cd neo4j/community/
$ mvn [clean] install -Dlicense.skip=true -DskipTests
@olange
olange / ShowMyTransforms.cs
Last active January 20, 2016 18:10 — forked from david-hodgetts/ShowMyTransforms.cs
An Unity Gizmo that displays the origin and orientation of a _game object_ when it is selected in the _Editor_, displaying its right/forward/up as red/blue/green axis
using UnityEngine;
using System.Collections;
[ExecuteInEditMode]
public class ShowTransforms : MonoBehaviour {
private const float radius = 0.02f;
void OnDrawGizmosSelected() {
Vector3 origin, axisRight, axisForward, axisUp;
@olange
olange / mono-runtime-version.cs
Created March 4, 2016 15:40
Reading Mono Runtime version
using System.Reflection;
System.Type type = System.Type.GetType( "Mono.Runtime");
if( type != null) {
MethodInfo displayName = type.GetMethod( "GetDisplayName", BindingFlags.NonPublic|BindingFlags.Static);
if( displayName != null)
Debug.Log( "Mono Runtime version" + displayName.Invoke(null,null));
}
@olange
olange / graphqlScalarDateTimeType.coffee
Last active April 8, 2016 17:55
Defines and exports a custom GraphQL scalar type that represents date and time with a time zone, which, while serialized as a string, promises to conform to ISO‐8601 format.
# Defines and exports a custom GraphQL scalar type that represents date and time,
# which, while serialized as a string, promises to conform to ISO‐8601 format.
# (adapted from https://github.com/soundtrackyourbrand/graphql-custom-datetype)
graphql = require 'graphql'
graphql_language = require 'graphql/language'
graphql_error = require 'graphql/error'
GraphQLScalarType = graphql.GraphQLScalarType
GraphQLError = graphql_error.GraphQLError
@olange
olange / symmetricDiff.coffee
Created May 13, 2016 18:12
Symmetric difference of two Sets in CoffeeScript
##
# Given two sets A and B, returns a triple with the set of elements
# in A only, in both and in B only.
#
symmetricDiff = (setA, setB) ->
[inAOnly, inBoth, inBOnly] = [new Set(), new Set(), new Set()]
setA.forEach (eid) ->
(if setB.has( eid) then inBoth else inAOnly).add eid
setB.forEach (eid) ->
inBOnly.add( eid) unless inBoth.has( eid)
@olange
olange / measuringDuration.coffee
Created May 19, 2016 16:56
Measuring a duration of execution in Node.js
##
# Utility function to measure time intervals. Polymorphic return value:
#
# * returns either the current high-resolution real time, given no argument;
# * or the time elapsed since a given high-resolution real time, that was
# retrieved from a previous call to this function.
#
# Usage:
# t0 = hrtime()
# duration = hrtime( t0) # expressed in milliseconds
@olange
olange / nearlyEqual.coffee
Last active May 20, 2016 16:13
Near equality in CoffeeScript for Node.js (comparison with a maximum relative difference)
##
# Minimum number added to one that makes the result different than one
#
EPSILON = Number.EPSILON ? 2.2204460492503130808472633361816e-16
##
# Given two floating point numbers and the maximum relative difference
# between the two, returns true if the two numbers are nearly equal,
# false otherwise. If the maximum relative difference (aka _epsilon_)
# is undefined, the function will test whether x and y are exactly equal.