Skip to content

Instantly share code, notes, and snippets.

@tychobrailleur
tychobrailleur / ActionListener.java
Created March 23, 2012 10:25
JRuby closure conversion contrived example
public interface ActionListener {
void onAction(String actionName, boolean flag, long tgf);
}
RAGEL=ragel
JAVAC=javac
default: generate
generate: lexer_java.rl
$(RAGEL) -J lexer_java.rl -o LexerJava.java
compile: LexerJava.java
@tychobrailleur
tychobrailleur / gist:2408390
Created April 17, 2012 19:18
railswizard command
rails new myapp -m http://railswizard.org/3a09d68c754ac1488573.rb -J -T
<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.weblogism.cucumberjvm</groupId>
<artifactId>java-example</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Cucumber-jvm Java Example</name>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
@tychobrailleur
tychobrailleur / LoadDataTest.java
Created May 15, 2012 15:23
Simple dbUnit example
import org.dbunit.IDatabaseTester;
import org.dbunit.JdbcDatabaseTester;
import org.dbunit.dataset.IDataSet;
import org.dbunit.dataset.xml.FlatXmlDataSetBuilder;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class LoadDataTest {
@tychobrailleur
tychobrailleur / prepend.rb
Created June 7, 2012 12:32
Prepends a list of file with a given header
require 'tempfile'
class File
def self.prepend(path, string)
Tempfile.open File.basename(path) do |tempfile|
# prepend data to tempfile
tempfile << string
File.open(path, 'r+') do |file|
# append original data to tempfile
@tychobrailleur
tychobrailleur / svn_stats.rb
Created June 7, 2012 12:34
svn committers and number of commits
f = File.open(ARGV[0])
committers = Hash.new{ |h,k| h[k] = 0 }
IO.readlines(f).each do |word|
if word =~ /^(r[0-9]+) \| ([^|]+) \|/
committers[$2] += 1
end
end
committers.each{ |k,v| puts "#{k}: #{v}" }
@tychobrailleur
tychobrailleur / run_sp.rb
Created July 5, 2012 15:09
Call a stored procedure with JRuby, with out parameters, including a cursor.
require 'java'
require 'ojdbc-6.jar'
java_import "java.sql.Types"
java_import "oracle.jdbc.OracleTypes"
USER_ID = "12345"
WORKSPACE_ID = "222"
DOMAIN_ID = "X_1_1"
@tychobrailleur
tychobrailleur / free_fall.rb
Created August 29, 2012 10:16
First attempt at Java2D physics with Swing and JRuby
require 'java'
%w(JPanel JTextField JLabel JFrame JButton Timer).each { |c| java_import "javax.swing.#{c}"}
%w(Rectangle Insets Color BasicStroke Dimension Canvas image.BufferStrategy BorderLayout GridBagLayout GridBagConstraints Font).each { |c| java_import "java.awt.#{c}" }
WORLD_WIDTH = 800
WORLD_HEIGHT = 600
DELAY = 50
G = 9.81