Skip to content

Instantly share code, notes, and snippets.

View benhardy's full-sized avatar

benhardy benhardy

View GitHub Profile
@benhardy
benhardy / horrorofhorrors.java
Last active August 29, 2015 14:09
java 8 enumeration as stream
public static <T> Stream<T> asStream(final Enumeration<T> horror) {
if (horror.hasMoreElements()) {
return Stream.concat(Stream.of(horror.nextElement()), asStream(horror));
} else {
return Stream.empty();
}
}
public static <T> Iterable<T> asIterable(final Enumeration<T> anotherHorribleEnumeration) {
return () -> new Iterator<T>() {
@Override
public boolean hasNext() {
return anotherHorribleEnumeration.hasMoreElements();
}
@Override
public T next() {
return anotherHorribleEnumeration.nextElement();
@benhardy
benhardy / keybase.md
Created September 25, 2014 05:58
keybase proof

Keybase proof

I hereby claim:

  • I am benhardy on github.
  • I am benhardy (https://keybase.io/benhardy) on keybase.
  • I have a public key whose fingerprint is E6EC 21D8 301F 8F48 375C D6C7 F32A 2090 4F46 ED42

To claim this, I am signing this object:

@benhardy
benhardy / kern.log
Created August 22, 2014 16:44
shonky kern.log
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: imklog 5.8.6, log source = /proc/kmsg started.
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] Initializing cgroup subsys cpuset
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] Initializing cgroup subsys cpu
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] Linux version 3.2.0-67-generic (buildd@brownie) (gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5) ) #101-Ubuntu SMP Tue Jul 15 17:46:11 UTC 2014 (Ubuntu 3.2.0-67.101-generic 3.2.60)
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] Command line: BOOT_IMAGE=/boot/vmlinuz-3.2.0-67-generic root=UUID=02102d06-ff39-4079-899f-c3ec91691ea3 ro quiet splash
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] KERNEL supported cpus:
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] Intel GenuineIntel
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] AMD AuthenticAMD
Aug 21 00:14:10 ci-na-frontdoor-03 kernel: [ 0.000000] Centaur CentaurHauls
Aug 21 00:14:10 ci
@benhardy
benhardy / bootstrap.sh
Created June 24, 2014 05:53
docker startup script for benhardy/ubuntu-java8
#!/usr/bin/env sh
TARBALL_URL=$1
APP_NAME=$2
echo "Cleaning up any previous $APP_NAME directory"
rm -rf $APP_NAME
echo "curling $TARBALL_URL -> $APP_NAME.tgz"
curl $TARBALL_URL -o $APP_NAME.tgz
@benhardy
benhardy / keybase.md
Created May 27, 2014 21:55
keybase.md

Keybase proof

I hereby claim:

  • I am benhardy on github.
  • I am benhardy (https://keybase.io/benhardy) on keybase.
  • I have a public key whose fingerprint is F313 68B9 32AA 2C12 E021 D863 0A6F DC0E DF9F EB9C

To claim this, I am signing this object:

public List<String> randomDictionaryWords() throws IOException {
try (InputStream is = new FileInputStream(new File("/usr/share/dict/words"))) {
BufferedReader br = new BufferedReader(new InputStreamReader(is));
return br.lines()
.filter(line -> line.length() >= MIN_WORD_LENGTH && line.length() <= MAX_WORD_LENGTH)
.filter(word -> word.equals(word.toLowerCase()))
.filter(word -> random() < DICTIONARY_SAMPLING_RATE)
.limit(50)
.collect(Collectors.toList());
@benhardy
benhardy / spheres.scala
Last active December 29, 2015 22:29
little functional raytracer. it may be longer that the "35 lines of javascript" one but is actually readable. (albeit in need of cleanup, optimizing, etc)
/**
* See bottom for file for example spheres scene
*/
import java.awt.Color
import java.awt.image.BufferedImage
import java.io.File
import javax.imageio.ImageIO
import math.sqrt
import math.min
import math.max
@benhardy
benhardy / broc.pov
Last active December 16, 2015 11:18
Generate a broccoli using POV-Ray's macros, which can be recursive.
// Generate a broccoli like structure
#include "colors.inc"
#include "textures.inc"
light_source {
<-100, 400,-200>
color <0.8,0.8,0.8>
area_light <50,0,0>, <0,0,50>, 5, 5
adaptive 1
jitter
@benhardy
benhardy / WebAppInit.scala
Created November 18, 2012 03:38
webapp config
/**
* Our instance of WebApplicationInitializer. This replaces web.xml for the initial
* configuration of the servlet.
*/
class WebAppInit extends WebApplicationInitializer {
override def onStartup(servletContext: ServletContext) {
// Create the 'root' Spring application context
val root = new AnnotationConfigWebApplicationContext()