Skip to content

Instantly share code, notes, and snippets.

View akkerman's full-sized avatar

Marcel Akkerman akkerman

View GitHub Profile
import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Created with IntelliJ IDEA.
*
* @author M. Akkerman
@akkerman
akkerman / CopyReaderWriter.java
Created December 15, 2012 11:32
copy reader to writer
private static void copy(BufferedReader reader, PrintWriter writer) {
String line;
while ((line = reader.readLine()) != null) {
writer.println(line);
}
}
@akkerman
akkerman / relative filename build.xml
Created December 19, 2012 12:54
ant build.xml -- shows file operations: loop, make relative and save to file -- also see comments
<project name="myProject" default="generate">
<property name="outputFile" location="outputFile.htm"/>
<property name="fileName" value=""/>
<property name="relativeFileName" value=""/>
<property name="target" value="${basedir}"/>
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="ant-contrib.jar"/>
</classpath>
@akkerman
akkerman / CopyUtil.java
Last active December 10, 2015 22:18
Shallow copier for objects with equivalent get/set combination
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class CopyUtil {
public static void copy(Object src, Object dst) {
try {
for (Method getter : src.getClass().getDeclaredMethods()) {
final String getterName = getter.getName();
if (!getterName.startsWith("get") || getter.getReturnType() == void.class)
continue;
import math
def is_prime(n):
if (n == 2):
return True
if (n == 1 or n % 2 == 0):
return False
square = int(math.ceil(math.sqrt(abs(n)))) + 1
i = 3
while i <= square:
class Voertuig(object):
def __init__(self,naam,snelheid):
self.naam = naam
self.snelheid = snelheid
class Auto(Voertuig):
def __init__(self,naam,snelheid):
super(Auto,self).__init__(naam,snelheid)
def rijden(self):
print self.naam, "lekker stukje rijden"
class Voertuig(val naam:String, var snelheid:Int = 0) { }
trait Auto extends Voertuig {
def rijden() {
println( "Ik rij in mijn " + naam)
}
}
trait Boot extends Voertuig {
def varen() {
Object.prototype.mixin = (aClass) ->
for key, value of aClass
@[key] = value
for key, value of aClass.prototype
@::[key] = value
@
class Voertuig
constructor: (@naam, @snelheid=0)->
@akkerman
akkerman / psgrep.sh
Last active December 21, 2015 07:58
check if a certain program is running on linux without it returning the grep command itself e.g. `psgrep apache`
ps -ef | grep -v grep | grep -i --color=auto $@
@akkerman
akkerman / disks.sh
Last active December 21, 2015 07:58
shows model number of all disks and the device it is associated with
sudo hdparm -I `sudo fdisk -l | grep Disk\ / | awk '{print $2}' | sed -e 's/.$//' ` | grep --c