Skip to content

Instantly share code, notes, and snippets.

View stevez's full-sized avatar

Steve Zhang stevez

  • Markham, Ontario, Canada
View GitHub Profile
@stevez
stevez / gist:e0d3906c19ed94e13fdc
Created April 30, 2015 02:27
scala array swap
val s = Array(1,2,3,4,5)
for( i<-1 until (s.length, 2)) {
val t = s(i-1)
s(i-1) = s(i)
s(i) = t
}
s
//Array[Int] = Array(2, 1, 4, 3, 5)
@stevez
stevez / gist:4ad40e28261569da15dc
Created March 20, 2015 03:58
gradle srcript to run robotframework test cases
apply plugin: 'java'
repositories {
mavenCentral()
}
dependencies {
runtime group: 'org.robotframework', name: 'robotframework', version: '2.8.7'
runtime group: 'com.github.markusbernhardt', name:'robotframework-selenium2library-java', version:'1.4.0.7'
}
@stevez
stevez / gist:cfe48ae386ebdebcca17
Created March 20, 2015 03:52
robotframework maven plugin example
<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>org.robotframework</groupId>
<artifactId>robotframework-maven-plugin-test-java-keyword</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Test</name>
@stevez
stevez / gist:3946134
Created October 24, 2012 13:45
gzip_ruby
require 'zlib'
require 'stringio'
require 'json'
def gunzip(data)
io = StringIO.new(data, "rb")
gz = Zlib::GzipReader.new(io)
decompressed = gz.read
end
def request_json
@response['headers']['Content-Type']='application/json'
obj = {"a" => 1, "b"=> 2}
result = obj.to_json
render :string => result, :use_layout_on_ajax => true
end
$.getJSON(<%= url_for :action => :request_json %>, function(data) {
alert(data.a);
alert(data.b);
});
private static void addTiming(CtClass clas, String mname)
throws NotFoundException, CannotCompileException {
// get the method information (throws exception if method with
// given name is not declared directly by this class, returns
// arbitrary choice if more than one with the given name)
CtMethod mold = clas.getDeclaredMethod(mname);
// rename old method to synthetic name, then duplicate the
// method with original name for use as interceptor
@stevez
stevez / alias_method
Created September 24, 2012 03:06
alias_method
module Mod
alias_method :orig_exit, :exit
def exit(code=0)
puts "Exiting with code #{code}"
orig_exit(code)
end
end
include Mod
exit(99)
public void test_load_2_files() {
CompositeConfiguration config = new CompositeConfiguration();
try {
config.addConfiguration(new PropertiesConfiguration(
"user.properties"));
config.addConfiguration(new PropertiesConfiguration(
"app.properties"));
Configuration extConfig = config.interpolatedConfiguration();
#user.properties
user.name=steve
user.password=nobody
#app.properties
connection.string=${user.name}:${user.password}