Skip to content

Instantly share code, notes, and snippets.

@ajuckel
ajuckel / gist:7182384
Created October 27, 2013 13:53
JUnit from the command line
$ ls src
Simple.java SimpleTest.java
$ cat src/Simple.java
public class Simple {
public static int add(int x, int y) {
return x + y;
}
}
$ cat src/SimpleTest.java
import org.junit.Test;
@ajuckel
ajuckel / UnixPath.diff
Created October 25, 2013 12:15
Fix typo in UnixPath.java
diff -r b88aa723a5fa src/solaris/classes/sun/nio/fs/UnixPath.java
--- a/src/solaris/classes/sun/nio/fs/UnixPath.java Thu Oct 24 09:10:42 2013 -0700
+++ b/src/solaris/classes/sun/nio/fs/UnixPath.java Fri Oct 25 07:13:55 2013 -0500
@@ -145,7 +145,7 @@
}
if (error) {
throw new InvalidPathException(input,
- "Malformed input or input contains unmappable chacraters");
+ "Malformed input or input contains unmappable characters");
}
@ajuckel
ajuckel / filesort.rs
Created October 17, 2013 14:09
Rust 0.8 version of the file sort utility
extern mod extra;
use std::*;
use extra::*;
fn main() {
let reader = io::file_reader(&Path(os::args()[1])).unwrap();
let writer = io::file_writer(&Path(os::args()[2]),
[io::Append, io::Create]).unwrap();
let mut lines = reader.read_lines();
sort::quick_sort3(lines);
for l in lines.iter() {
@ajuckel
ajuckel / gist:7018861
Created October 17, 2013 03:31
Rust sort sample
extern mod std;
fn main() {
let input = io::file_reader(&Path(os::args()[1]));
let output = result::get(&io::file_writer(&Path(os::args()[2]), [io::Append, io::Create]));
let mut lines = result::get(&input).read_lines();
std::sort::quick_sort(lines, |a,b| {
str::le(*a, *b)
});
for lines.each |l| {
output.write_line(*l);
@ajuckel
ajuckel / gist:5263363
Created March 28, 2013 14:04
Silly programming puzzle
#!/usr/bin/env ruby
# Given a number x, print a diamond of all numbers from 1 to x^2 in the following format
# 2: 3:
# 1 1
# 3 2 4 2
# 4 7 5 3
# 8 6
# 9
def num_for num, i, j
res = num*i+j*(1-num)
@ajuckel
ajuckel / gist:1243195
Created September 26, 2011 19:42
Test invalid utf-8 parsing
public void testGetUnicodeValue() throws Exception {
byte[] bytes = new byte[] {
110, 122, -31, 32, 75
};
RubyString str = RubyString.newStringLight(Ruby.getGlobalRuntime(), new ByteList(bytes));
assertEquals(5, ((Integer)str.length().toJava(Integer.class)).intValue());
assertEquals(5, str.getUnicodeValue().length());
}
// In RubyEncodings:
@ajuckel
ajuckel / string_spec.rb
Created September 20, 2011 13:34
Quick implementation of hash format for jruby
# Not sure where this is defined in MRI, but appeared to be missing in JRuby
if defined?(JRUBY_VERSION) && RUBY_VERSION =~ /^1\.9/
class KeyError < IndexError
end
class String
alias_method :old_format, :%
def %(replacements)
split_re = /(?<!%)(%{[^}]+})/
replace_re = /(?<!%)%{([^}]+)}/
@ajuckel
ajuckel / gist:1217329
Created September 14, 2011 18:21
ARJDBC #105 Monkeypatch
module Arel
module Visitors
class DepthFirst < Arel::Visitors::Visitor
def initialize block = nil
@block = block || Proc.new
if defined?(JRUBY_VERSION)
require 'java'
if @block.to_java.block.arity.nil?
@block = lambda { |c| nil }
end
@ajuckel
ajuckel / gist:1171017
Created August 25, 2011 15:57
Varargs Examples
Java:
import java.lang.StringBuilder;
public class Test {
public static String concat(String... strings) {
StringBuilder sb = new StringBuilder();
for( String s : strings ) {
sb.append(s);
}
return sb.toString();
}
@ajuckel
ajuckel / gist:1166369
Created August 23, 2011 20:12
KVM Test
$ sh create_blitz.sh
qemu-system-x86_64: -net vnic,vlan=0,name=vnic0,ifname=rge0,macaddr=90:b8:d0:c0:
ff:ee: vnic dhcp disabled
QEMU 0.14.1 monitor - type 'help' for more information
(qemu) Start bios (version 0.6.1.2-20110201_165504-titi)
Ram Size=0x18000000 (0x0000000000000000 high)
CPU Mhz=2934
PCI: pci_bios_init_bus_rec bus = 0x0
PIIX3/PIIX4 init: elcr=00 0c