Skip to content

Instantly share code, notes, and snippets.

View alf239's full-sized avatar

Alexey Filippov alf239

  • Cambridge, UK
View GitHub Profile
@alf239
alf239 / HSQL.java
Created February 3, 2011 18:53
Aggregare function for HSQL to emulate Oracle's WM_CONCAT
@SuppressWarnings("unused")
public static String wmConcat(String in, Boolean flag,
String[] register, Integer[] counter) {
if (flag) {
if (register[0] == null) {
return null;
}
return register[0];
}
if (in == null) {
@alf239
alf239 / CHECK_TABLES.sql
Created February 18, 2011 14:30
Fix the Oracle sequences
select * from all_sequences where sequence_owner = sys_context('USERENV', 'SESSION_USER')
@alf239
alf239 / public_data.sql
Created February 28, 2011 11:47
I love write-only languages
/*
A very special SQL file - actually, a configuration for the exporter
the exporter is in the where.clause.awk script,
which is called as follows:
awk -v table=$TABLE_NAME -f where_clause.awk Schema/public_data.sql
NB: We have slightly weird syntax for comments here: a line containing / and *
will be completely ignored; so will the line containing */
/*
@alf239
alf239 / chebi.xml
Created March 17, 2011 09:48
chEBI output proposal
<ontologyReferences>
<term accession="CHEBI:29022">
<a href="http://www.ebi.ac.uk/gxa/experiment/E-MEXP-1573" rel="experiment">E-MEXP-1573</a>
<a href="http://www.ebi.ac.uk/gxa/experiment/E-MEXP-2209" rel="experiment">E-MEXP-2209</a>
<a href="http://www.ebi.ac.uk/gxa/experiment/E-MEXP-749" rel="experiment">E-MEXP-749</a>
</term>
<term accession="CHEBI:17790">
<a href="http://www.ebi.ac.uk/gxa/experiment/E-GEOD-5301" rel="experiment">E-GEOD-5301</a>
<a href="http://www.ebi.ac.uk/gxa/experiment/E-MEXP-1797" rel="experiment">E-MEXP-1797</a>
</term>
@alf239
alf239 / ConcurrentSection.java
Created June 8, 2011 07:41
synchronized method vs block
// : c13:CriticalSection.java
// Synchronizing blocks instead of entire methods. Also
// demonstrates protection of a non-thread-safe class
// with a thread-safe one.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import java.util.ArrayList;
import java.util.List;
@alf239
alf239 / autohider.user.js
Created November 8, 2011 23:26
Autohider in JS
$.each(
$.grep(
$(".l_expandcomments"),
function(e) {
var m = /(\d+) more comments/.exec(e.innerHTML);
return m && parseInt(m[1]) > 10;
}),
function() {
$(".l_hideone", $(this).parents(".l_entry"))
.click();
@alf239
alf239 / version.groovy
Created November 29, 2011 13:14
Get git version
def env = System.getenv()
def gitcmd = "git"
if (env["com.apple.java.jvmMode"])
gitcmd = "/usr/local/git/bin/git"
if (env["OS"] =~ /^Windows/)
gitcmd = "cmd /c ${gitcmd}"
def gitDescribe = """${gitcmd} describe""".execute().in.text.trim()
def m = gitDescribe =~ /(?:atlas-)?(.*)/
def gitBranch = """${gitcmd} symbolic-ref -q HEAD""".execute().in.text.trim()
public class VolatileExample implements Runnable {
public static boolean flag = true; // do not try this at home
public void run() {
long i = 0;
while (flag) {
if (i++ % 10000000000L == 0)
System.out.println("Waiting " + System.currentTimeMillis());
}
}
@alf239
alf239 / Chain.java
Created January 7, 2012 16:52
Chained method invocation VS JavaBeans introspection
package org.acm.afilippov;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
public class Chain {
private int i;
public int getI() {
@alf239
alf239 / Deadlock.java
Created January 16, 2012 13:47
Deadlock in Java
public class Deadlock implements Runnable {
private final Object a;
private final Object b;
private final static CountDownLatch latch = new CountDownLatch(2);
public Deadlock(Object a, Object b) {
this.a = a;
this.b = b;
}