Skip to content

Instantly share code, notes, and snippets.

::: Query Term: Jvaa
@ -> 4
A -> 4
B -> 4
C -> 4
D -> 4
E -> 4
F -> 4
G -> 4
@dylon
dylon / multimethods-under-varying-relationship-hierarchies.clj
Last active December 30, 2015 18:09
Demonstrates how to dispatch on multimethods with relationship hierarchies other than the global hierarchy. In Clojure, multimethods compare dispatch values using isa?, which operates on a relationship hierarchy that may be overridden via the ":hierarchy" option to defmulti.
(def h (atom (make-hierarchy)))
(swap! h derive ::a ::b)
;-> "(isa? user/a user/b), under the global hierarchy: false"
(println "(isa? user/a user/b), under the global hierarchy:" (isa? ::a ::b))
;-> "(isa? user/a user/b), under the hierarchy, h: true"
(println "(isa? user/a user/b), under the hierarchy, h:" (isa? @h ::a ::b))
@dylon
dylon / ExtensionMethodTest.java
Created September 15, 2013 05:15
Demonstrates how to use lombok's @ExtensionMethod annotation on objects and primitive types.
import lombok.ExtensionMethod;
@ExtensionMethod(Extensions.class)
public class ExtensionMethodTest {
public static void main(final String... args) {
System.out.println(args.isNull()); //-> false
System.out.println(null.isNull()); //-> true
int i = 0;
@dylon
dylon / ValidateTest.java
Last active December 23, 2015 02:39
Demonstrates how to use lombok-pg 0.11.3's @Validate and @Validate.With annotations
import lombok.Validate;
public class ValidateTest {
public static void main(final String... args) {
foo(0); //-> Passes validation (0 is the most-even number)
foo(1); //-> IllegalArgumentException: The object 'i' (argument #1) is invalid
}
@Validate //-> Required for @Validate.With(*) to be detected
private static void foo(@Validate.With("isEven") final Integer i) {
@dylon
dylon / YieldTest.java
Created September 15, 2013 04:37
Demonstrates how to use lombok-pg 0.11.3's yield statement to create a generator function (i.e. lazy sequence).
import static lombok.Yield.yield;
public class YieldTest {
public static void main(final String... args) {
for (int i : evens()) {
System.out.println(i);
}
}
private static Iterable<Integer> evens() {
@dylon
dylon / WeightedRandomTest.java
Last active December 22, 2015 10:59
Demonstrates how to randomly sort a collection of elements, where each class may have a different weight (all weights must be non-negative and sum to 1.0)
import java.util.Map;
import java.util.HashMap;
public class WeightedRandomTest {
private static final int NUM_CLASSIFICATIONS = 1_000_000;
private static Classification classify() {
double factor = Math.random();
for (final Classification classification : Classification.values()) {
factor -= classification.getWeight();
@dylon
dylon / .bash_profile
Last active September 9, 2023 14:51
How to get 256 colors in a standard Linux terminal + screen (without X windows).
# ...
# This is for what I would consider a standard setup, where TTY's 1 -- 6 are
# "linux" terminals and TTY's 7+ are reserved for X windows. You should adjust
# it to your setup, accordingly.
#
# ::: Important ::: You must have both fbterm and screen installed and on your
# path for this to work.
virtual_terminal="$( tty | grep -oE ....$ )"
#include <stdio.h>
struct Foo {
const int baz;
Foo(const int baz) : baz(baz) {}
};
struct Qux : public Foo {
Qux(const int baz) : Foo(baz) {}
};
BEGIN;
CREATE EXTENSION IF NOT EXISTS LTREE;
/*==============================================================================
Define the tables.
==============================================================================*/
CREATE TABLE nodes
(