Skip to content

Instantly share code, notes, and snippets.

View bonifaido's full-sized avatar

Nándor István Krácser bonifaido

View GitHub Profile
@bonifaido
bonifaido / diagonal.clj
Created August 5, 2012 09:23
Matrix diagonal
(defn diagonal [m]
(map #(nth (nth m %) %)
(take (count m) (iterate inc 0))))
@bonifaido
bonifaido / disk-speed.zsh
Created November 2, 2012 12:16
Benchmark your HDD or SSD read/write speed
disk-speed() {
tstfile=/tmp/tstfile.$RANDOM
print "Write speed: " $(dd if=/dev/zero bs=1024k of=$tstfile count=1024 2>&1 | awk '/sec/ {print $1 / $5 / 1048576, "MB/sec" }')
purge
print " Read speed: " $(dd if=$tstfile bs=1024k of=/dev/null count=1024 2>&1 | awk '/sec/ {print $1 / $5 / 1048576, "MB/sec" }')
rm $tstfile
}
@bonifaido
bonifaido / euler16.clj
Created December 5, 2012 10:42
Project Euler - Problem 16
(reduce +
(map #(read-string (str %))
(str (.pow (BigInteger. "2") 1000))))
@bonifaido
bonifaido / pom.xml
Last active December 10, 2015 02:08
Simple POM for standalone JARs.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>app</artifactId>
<version>0.1</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.resources.sourceEncoding>UTF-8</project.resources.sourceEncoding>
</properties>
<dependencies>
@bonifaido
bonifaido / DelayedDocumentListener.java
Last active December 12, 2015 06:38
Good for autocompletion/searching
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Timer;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
public class DelayedDocumentListener implements DocumentListener {
private final Timer timer;
private DocumentEvent lastEvent;
@bonifaido
bonifaido / IsolatedClassLoader.java
Created March 2, 2013 19:21
An isolated class loader after http://blog.markturansky.com/archives/21 Usage: javac IsolatedClassLoader.java && java -ea IsolatedClassLoader
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.List;
public class IsolatedClassLoader extends URLClassLoader {
private static URL[] classPathAsURLArray() {
@bonifaido
bonifaido / ExchangerTest.java
Last active October 6, 2017 12:16
Playing with Java Exchangers.
package me.nandork.exchangertest;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Exchanger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
@bonifaido
bonifaido / FixMessageUtil.java
Last active December 16, 2017 20:27
This utility class converts QuickFIX/J Messages into a human readable format.
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.math.BigDecimal;
@bonifaido
bonifaido / 9003176.patch
Created May 24, 2013 16:24
Fix for javac 9003176: Class reference duplicates in constant pool
diff --git a/src/share/classes/com/sun/tools/javac/jvm/Pool.java b/src/share/classes/com/sun/tools/javac/jvm/Pool.java
--- a/src/share/classes/com/sun/tools/javac/jvm/Pool.java
+++ b/src/share/classes/com/sun/tools/javac/jvm/Pool.java
@@ -28,6 +28,7 @@
import java.util.*;
import com.sun.tools.javac.code.Symbol.*;
+import com.sun.tools.javac.code.Type.ClassType;
/** An internal structure that corresponds to the constant pool of a classfile.
@bonifaido
bonifaido / build-openjdk9-osx.sh
Last active January 25, 2018 04:38
Build OpenJDK 9 Zero(Shark) on Mac OS X Yosemite (bash build-openjdk9-osx.sh)
#!/bin/bash
# Latest Mercurial, OS X Command Line Tools, JDK 8 and libffi are needed
# Tested with OSX 10.10.3 and Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
brew install mercurial
brew install libffi
brew link libffi --force
# only needed if you build the zeroshark variant
# brew install llvm
# brew link llvm --force
hg clone http://hg.openjdk.java.net/jdk9/jdk9