Skip to content

Instantly share code, notes, and snippets.

@ajuckel
ajuckel / gist:7182384
Created Oct 27, 2013
JUnit from the command line
View gist:7182384
$ 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 Oct 25, 2013
Fix typo in UnixPath.java
View UnixPath.diff
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 Oct 17, 2013
Rust 0.8 version of the file sort utility
View filesort.rs
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 Oct 17, 2013
Rust sort sample
View gist:7018861
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 Mar 28, 2013
Silly programming puzzle
View gist:5263363
#!/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 Sep 26, 2011
Test invalid utf-8 parsing
View gist:1243195
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 Sep 20, 2011
Quick implementation of hash format for jruby
View string_spec.rb
# 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 Sep 14, 2011
ARJDBC #105 Monkeypatch
View gist:1217329
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 Aug 25, 2011
Varargs Examples
View gist:1171017
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();
}
View gist:1166369
$ 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
You can’t perform that action at this time.