Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>asgard</groupId>
<artifactId>asgard</artifactId>
<version>1.0.0-SNAPSHOT</version>
<inceptionYear>2008</inceptionYear>
<licenses>
<license>
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.deeplearning4j.nn.api.OptimizationAlgorithm;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.gradient.Gradient;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.nn.workspace.LayerWorkspaceMgr;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.deeplearning4j.nn.conf.ComputationGraphConfiguration;
import org.deeplearning4j.nn.conf.NeuralNetConfiguration;
import org.deeplearning4j.nn.conf.layers.DenseLayer;
import org.deeplearning4j.nn.gradient.Gradient;
import org.deeplearning4j.nn.graph.ComputationGraph;
import org.deeplearning4j.nn.weights.WeightInit;
import org.deeplearning4j.nn.workspace.LayerWorkspaceMgr;
import org.deeplearning4j.optimize.listeners.ScoreIterationListener;
import org.nd4j.linalg.activations.Activation;
import org.nd4j.linalg.api.ndarray.INDArray;
@gfrison
gfrison / grow intermediate values in array.java
Created August 1, 2018 08:40
I need to find a way to create a new array in Java that will insert intermediate values between the values of an already-existing array.
/**
* > arr = {1, 2, 3}, size = 5
* < [1.0, 1.5, 2.0, 2.5, 3.0]
* @param arr
* @param newSize
* @return
*/
public static double[] growIntermediate(double[] arr, int newSize) {
if (newSize < arr.length) {
throw new IllegalArgumentException("newSize lower than array length");
int __main__ (int var0)
vars: int var1, int var2, int var3
var2 = 2
if (((var0 - 2) % 3) == 0)
var1 = 1
else
var1 = 0
var3 = 1
for(; (var3<var0); var3 = (var3 + 1))
if (var2<var0)
static class CacheOp implements Op<Double> {
private final AtomicDouble ref;
public CacheOp(int i) {
ref = new AtomicDouble(i);
}
public CacheOp() {
this(0);
}
@gfrison
gfrison / n-gram generator
Created February 8, 2018 13:46
a simple method for creating all possible n-grams of a given string
import static java.util.stream.IntStream.range;
import static java.util.stream.IntStream.rangeClosed;
private List<String> possibleNgrams(String[] words) {
return rangeClosed(1, words.length)
.mapToObj(
window ->
rangeClosed(0, words.length - window)
.mapToObj(
i ->
@gfrison
gfrison / groovy-date-time-operations
Created February 5, 2011 15:00
How to add months, days, years to a date in Groovy
Groovy also has a Time Category class which gives you DSL style syntax for manipulating dates. Here is an example:
import org.codehaus.groovy.runtime.TimeCategory
now = new Date()
println now
use(TimeCategory) {
footballPractice = now + 1.week - 4.days + 2.hours - 3.seconds
}
println footballPractice
which will produce output like this:
@gfrison
gfrison / WriteFile.java
Last active February 12, 2016 14:33
Monitor file writing for a given InputStream, with NIO.2 AsynchronousFileChannel and RxJava
public static Observable<Long> write(Path target, InputStream inputStream) {
return Observable.create(subscriber -> {
try {
final AtomicLong offset = new AtomicLong(0);
AsynchronousFileChannel afc = AsynchronousFileChannel.open(Utils.home.resolve(target), StandardOpenOption.WRITE,
StandardOpenOption.CREATE);
afc.lock(new Object(), new CompletionHandler<FileLock, Object>() {
@Override
public void completed(final FileLock lock, final Object attachment) {
log.debug("write:{} acquired lock", target);
@gfrison
gfrison / main.js
Created January 16, 2014 22:37 — forked from carchrae/main.js
var vertx = require("vertx.js")
var console = require('vertx/console');
console.log('module ' + JSON.stringify(module));
var dust;
var x = function(){
var module = undefined;