This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dao dao = ioc.get(Dao.class); | |
for (Class<?> klass : Scans.me().scanPackage("net.wendal.tb.bean")) //改成你自己的package!! | |
if (klass.getAnnotation(Table.class) != null) | |
dao.create(klass, false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- from http://stackoverflow.com/questions/132397/get-back-the-output-of-os-execute-in-lua | |
function os.capture(cmd, raw) | |
local f = assert(io.popen(cmd, 'r')) | |
local s = assert(f:read('*a')) | |
f:close() | |
if raw then return s end | |
s = string.gsub(s, '^%s+', '') | |
s = string.gsub(s, '%s+$', '') | |
s = string.gsub(s, '[\n\r]+', ' ') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class JSON2Java { | |
private static final ScriptEngine jsonParser; | |
static { | |
try { | |
String init = read(JSON2Java.class.getResource("json2java.js")); | |
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript"); | |
engine.eval(init); | |
jsonParser = engine; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## {{{ http://code.activestate.com/recipes/491264/ (r4) | |
import socket | |
class DNSQuery: | |
def __init__(self, data): | |
self.data=data | |
self.dominio='' | |
tipo = (ord(data[2]) >> 3) & 15 # Opcode bits | |
if tipo == 0: # Standard query |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.nutz.dao; | |
import java.lang.reflect.Field; | |
import java.sql.Connection; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.ArrayList; | |
import java.util.List; | |
import org.nutz.castor.Castors; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ListList { | |
private List<Object[]> list = new ArrayList<Object[]>(); | |
public void add(Object ...objs) { | |
list.add(objs); | |
} | |
public String toJson(JsonFormat format) { | |
return Json.toJson(list, format); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "database/sql" | |
import _ "code.google.com/p/go-mysql-driver/mysql" | |
import "encoding/json" | |
import "fmt" | |
type User struct { | |
User string `json:"user"` | |
Password string `json:"password"` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0 *ast.File { | |
1 . Package: 2:1 | |
2 . Name: *ast.Ident { | |
3 . . NamePos: 2:9 | |
4 . . Name: "main" | |
5 . } | |
6 . Decls: []ast.Decl (len = 3) { | |
7 . . 0: *ast.FuncDecl { | |
8 . . . Name: *ast.Ident { | |
9 . . . . NamePos: 3:6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws Throwable { | |
Enumeration<URL> urls = SimpleDaoTest.class.getClassLoader().getResources("META-INF/MANIFEST.MF"); | |
while (urls.hasMoreElements()) { | |
URL url = (URL) urls.nextElement(); | |
System.out.println(url); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class DaoTest { | |
@Test | |
public void test_insert_after_del() { | |
dao.create(Pet.class, true); | |
dao.insert(Pet.create("wendal")); | |
Trans.exec(new Atom() { | |
public void run() { | |
dao.execute(Sqls.create("delete from t_pet")); | |
dao.insert(Pet.create("wendal")); | |
} |