Skip to content

Instantly share code, notes, and snippets.

View RichardWarburton's full-sized avatar

Richard Warburton RichardWarburton

View GitHub Profile
Python:
# Even numbers between 1 and 49:
[ x for x in range(1,50) if x % 2 == 0 ]
Java:
// Even numbers between 1 and 49:
IntStream.range(1, 50).filter(x -> x % 2 == 0).boxed().collect(toList());
@RichardWarburton
RichardWarburton / dump
Last active August 29, 2015 13:56
Jar Size Analysis
# Convert
find | grep ".jar$" | grep -v 'tiny' | while read file; do gzip --keep $file; done
find | grep "\.jar$" | grep -v 'tiny' | while read file; do bzip2 --keep $file; done
# Dump
find | grep ".jar$" | grep -v 'tiny' | xargs ls -l | grep -P "$1" | awk '{ print $5 }' > jar_sizes
find | grep "tiny.jar$" | xargs ls -l | grep -P "$1" | awk '{ print $5 }' > tiny_jar_sizes
# Process
@RichardWarburton
RichardWarburton / battery.sh
Created February 3, 2014 19:30
World's simplest battery monitor
#!/bin/sh
BAT=/sys/devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT1/
now=`cat $BAT/energy_now`
full=`cat $BAT/energy_full`
echo "scale=3; $now / $full" | bc
Stream.of(Month.values())
.map(month -> LocalDate.now()
.with(month)
.with(lastDayOfMonth()))
.forEach(date -> System.out.println(date.getDayOfWeek()));
@RichardWarburton
RichardWarburton / .bashrc
Last active January 2, 2016 22:48
Switching between Java versions
# Goes in ~/.bashrc
export JAVA8_HOME=<PATH TO JDK 8>
export JAVA7_HOME=<PATH TO JDK 7>
export JAVA6_HOME=<PATH TO JDK 6>
export JAVA_HOME=$JAVA6_HOME
function go8 {
export JAVA_HOME=$JAVA8_HOME
export PATH=$JAVA_HOME/bin:$PATH
@RichardWarburton
RichardWarburton / gist:7390520
Created November 9, 2013 21:52
Mani's Gradient Descent Code in Java
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
import java.util.function.DoubleBinaryOperator;
import java.util.function.DoubleUnaryOperator;
public class SimpleGradientDescent {
private static final double epsilon = Double.MIN_VALUE;
package org.glassfish.json;
import java.io.IOException;
import java.io.StringReader;
import java.nio.file.FileSystems;
import java.nio.file.Files;
import java.nio.file.Path;
import javax.json.JsonObject;
import javax.json.JsonReader;
@RichardWarburton
RichardWarburton / gist:2978126
Created June 23, 2012 12:24
Lambdas Hackday Core Libraries Instructions

One area of exploration for Lambdas is exploring which areas of the core libraries can benefit from api changes in order to exploit lambdafication. This is being undertaken internally by the Expert Group, but it always takes back seat to the bigger issues. Obviously there are a million places where the libraries could be enhanced. Identifying low-hanging fruit there is the goal of the exerise. Particularly good examples are those like "Add a constructor accepting a Factory to ThreadLocal", so that people could use ThreadLocal without subclassing it just to provide an initialValue method.

You might wish to look at the following Java library areas when considering what to change:

  • IO & Networking - java.io, java.nio and java.net
  • java.text
  • XML Libraries
  • JDBC
  • java.beans