Skip to content

Instantly share code, notes, and snippets.

@lysu
lysu / gist:2900771
Created June 9, 2012 12:13
Java:Create enum at runtime
Constructor con = Test.class.getDeclaredConstructors()[0];
Method[] methods = con.getClass().getDeclaredMethods();
for (Method m : methods) {
if (m.getName().equals("acquireConstructorAccessor")) {
m.setAccessible(true);
m.invoke(con, new Object[0]);
}
}
Field[] fields = con.getClass().getDeclaredFields();
// ==UserScript==
// @name jQuery For Chrome (A Cross Browser Example)
// @namespace jQueryForChromeExample
// @include *
// @author Erik Vergobbi Vold
// @description This userscript is meant to be an example on how to use jQuery in a userscript on Google Chrome.
// ==/UserScript==
// a function that loads jQuery and calls a callback function when jQuery has finished loading
function addJQuery(callback) {
@lysu
lysu / generateSql.pl
Created December 8, 2012 10:16
Generate sql from file
my @ctypes=qw/0 1 0 1 1/;
while(<>) {
chop;
@F=split('\|', $_);
print "insert into table values(";
foreach my $col (@F) {
my $type=shift(@ctypes);
print ($type == 1 ? '"'.$col.'"' : $col);
print ",";
@lysu
lysu / diffColumn.awk
Created December 8, 2012 12:19
Compare 2ed Column and select exist in file2 but not in file1
awk 'FNR==NR {A[$2];next;} !($2 in A)' file1 file2
@lysu
lysu / log4j.properties
Created December 12, 2012 10:39
mybatis open logger
log4j.logger.com.ibatis=ALL
log4j.logger.com.ibatis.common.jdbc.SimpleDataSource=ALL
log4j.logger.com.ibatis.common.jdbc.ScriptRunner=ALL
log4j.logger.com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate=ALL
log4j.logger.java.sql.Connection=ALL
log4j.logger.java.sql.Statement=ALL
log4j.logger.java.sql.PreparedStatement=ALL
log4j.appender.ibatis.File = /home/robiplus/logs/ibatis.log
log4j.appender.ibatis.layout = org.apache.log4j.PatternLayout
log4j.appender.ibatis.layout.ConversionPattern = %p %d{yyyy-MM-dd HH:mm:ss} - %m%n
@lysu
lysu / hotelBindAccountSqlGen.pl
Last active December 10, 2015 02:58
genSql.pl
#! /usr/bin/perl
#
# Generate init hotel bind user data sql.
# author: robiplus
#
# usage:
#
use strict;
@lysu
lysu / monitorTreeDelete.pl
Created January 15, 2013 08:08
send mail in perl
#! /usr/bin/perl
use strict;
use warnings;
use POSIX;
use Net::SMTP;
sub sendMail;
@lysu
lysu / unchunk.clj
Last active December 13, 2015 18:58
mark from from plumbing.core
(defn unchunk
"Takes a seqable and returns a lazy sequence that
is maximally lazy and doesn't realize elements due to either
chunking or apply.
Useful when you don't want chunking, for instance,
(first awesome-website? (map slurp +a-bunch-of-urls+))
may slurp up to 31 unneed webpages, wherease
(first awesome-website? (map slurp (unchunk +a-bunch-of-urls+)))
is guaranteed to stop slurping after the first awesome website.
@lysu
lysu / unicode2utf8.pl
Created February 16, 2013 07:14
unicode to utf8
perl -e 'binmode STDOUT,":utf8"; while(<>){s/\\u(....)/(pack("U", hex($1)))/eg; print ;}'

the problem:

subl somefile
zsh: correct 'subl' to 'ul' [nyae]? n

node -v
zsh: correct 'node' to 'od' [nyae]? n
v0.8.16