Skip to content

Instantly share code, notes, and snippets.

View dmolesUC's full-sized avatar

David Moles dmolesUC

View GitHub Profile
@dmolesUC
dmolesUC / travis-ci.md
Last active August 18, 2016 19:50
Travis-CI lightning talk notes

Travis CI

  • developers check in early, check in often
  • automated build verifies every check-in

Why continuous integration

  • catch issues quickly
@dmolesUC
dmolesUC / neo4j-gd.md
Created July 6, 2017 20:57
Neo4J Graph Days: notes

username/password: neo4j/neo4j1

building blocks

  • nodes = nouns
  • relationships = verbs
    • no dangling relationships
  • properties = adjectives or adverbs
    • on nodes or relationships
  • strings, floats, longs, arrays, etc.
@dmolesUC
dmolesUC / VertxThreadTest.java
Created November 16, 2017 23:26
Vert.x test example with thread debugging
/*
Output (with org.slf4j:slf4j-simple:1.7.25):
[main] INFO VertxThreadTest - setUp running
[main] INFO VertxThreadTest - deploying on port 53539
[main] INFO VertxThreadTest - Test status200 running
[vert.x-eventloop-thread-0] INFO VertxThreadTest - Handling request
[vert.x-eventloop-thread-2] INFO VertxThreadTest - Test status200 got response
[main] INFO VertxThreadTest - tearDown running
[main] INFO VertxThreadTest - setUp running
@dmolesUC
dmolesUC / compareTo.java
Last active November 30, 2017 22:19
Java compareTo() in functional style
import io.vavr.collection.Array;
import java.net.URI;
import java.util.Objects;
import java.util.function.IntSupplier;
import java.util.stream.Stream;
class Vocab implements Comparable<Vocab> {
private final String prefix;
private final URI uri;
@dmolesUC
dmolesUC / supplementary.md
Created December 18, 2017 23:12
Match Unicode supplementary characters (U+10000–U+EFFFF) with regex in Java

A naive regex to match supplementary characters in the range U+10000–U+EFFFF produces nonsensical results:

jshell> Pattern.matches("[\u10000-\uEFFFF]+", "abc")
    ==> true

Likewise the version using regex escapes rather than character escapes:

jshell> Pattern.matches("[\\u10000-\\uEFFFF]+", "abc")
    ==> true
@dmolesUC
dmolesUC / jruby-openssl-x509-storeerror.txt
Created January 3, 2018 18:42
Stack trace: "OpenSSL::X509::StoreError: setting default path failed: No password supplied for PKCS#12 KeyStore"
$ ./gradlew check
> Configure project :buildSrc
2018-01-03 10:41:04.718:INFO::Daemon worker Thread 10: Logging initialized @6632166ms
2018-01-03 10:41:04.763:INFO:oejs.Server:Daemon worker Thread 10: jetty-9.2.12.v20150709
OpenSSL::X509::StoreError: setting default path failed: No password supplied for PKCS#12 KeyStore.
set_default_paths at org/jruby/ext/openssl/X509Store.java:165
SSLContext at uri:classloader:/META-INF/jruby.home/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:31
SSL at uri:classloader:/META-INF/jruby.home/lib/ruby/shared/jopenssl19/openssl/ssl-internal.rb:22
@dmolesUC
dmolesUC / Arguments.java
Created January 3, 2018 23:40
Argument assertions
public class Arguments {
// ------------------------------------------------------------
// Checks
public static <T> T require(T argument, Predicate<T> condition, Supplier<String> msgSupplier) {
return require(argument, () -> condition.test(argument), msgSupplier);
}
public static <T> T requireNot(T argument, Predicate<T> condition, Supplier<String> msgSupplier) {
@dmolesUC
dmolesUC / fold-and-reduce.md
Created January 25, 2018 20:13
foldLeft(), Stream.reduce(), and Observable.reduce()

Vavr List:

List<String> str = List.of("A", "B", "C");
HashSet<String> res = str.foldLeft(
  HashSet.empty(), 
  (set, s) -> set.add(s)
);
@dmolesUC
dmolesUC / combine.py
Last active March 26, 2018 18:14
Python script implementing "Combining Multiple Averaged Data Points and Their Errors" by Ken Tatebe
from typing import Tuple, List
"""A 'bin' of observations in the form (average, error, # of observations)"""
Bin = Tuple[float, float, int]
"""Based on http://isi.ssl.berkeley.edu/~tatebe/whitepapers/Combining%20Errors.pdf"""
def combine(a: Bin, b: Bin) -> Bin:
a_avg, a_err, n_a = a
b_avg, b_err, n_b = b
n = n_a + n_b
@dmolesUC
dmolesUC / wait-for-ajax.rb
Last active July 10, 2018 20:18
Capybara: wait for Ajax with Prototype.js
# in spec/features_helper.rb
# adapted from https://robots.thoughtbot.com/automatically-wait-for-ajax-with-capybara
# for legacy Rails apps still using Prototype.js
def wait_for_ajax!
Timeout.timeout(Capybara.default_max_wait_time) do
# Error pages etc. may not have Ajax defined
loop until page.evaluate_script("(typeof Ajax === 'undefined') ? 0 : Ajax.activeRequestCount").zero?
end
end