Skip to content

Instantly share code, notes, and snippets.

@keating
keating / BiHashMap.java
Created June 1, 2012 08:10
bidirectional hashMap for java
import java.util.HashMap;
import java.util.Map;
/**
* bidirectional hashMap
* 双向的HashMap对应关系
*
* @author keating_andy_given
*/
@keating
keating / DtoHelp.java
Created June 1, 2012 08:14
build dto for a list (for MayFramework@BYHT)
import java.util.ArrayList;
import java.util.List;
import com.beiyanght.utils.dto.DtoException;
import com.beiyanght.utils.dto.DtoHelper;
/**
*
* @author keating_andy_given
*/
@keating
keating / CSHelp.java
Created June 1, 2012 08:20
Some helpers for Java Swing
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.table.TableColumnModel;
/**
* Swing helper for column of JTable
* @author keating_andy_given
@keating
keating / DateHelp.java
Created June 1, 2012 08:26
some helpers for java.util.Date
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* some helpers for java.util.Date
* @author keating_andy_given
*
*/
@keating
keating / FileOperater.java
Created June 1, 2012 08:27
some helpers for file operation
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
/**
* some helpers for file operation
@keating
keating / SequenceHelp.java
Created June 1, 2012 08:40
for building sequence
import static com.beiyanght.jpa.ThreadLocalEntityManager.em;
import java.math.BigDecimal;
/**
*
* @author keating_andy_given
*/
public class SequenceHelp {
@keating
keating / StringHelp.java
Created June 1, 2012 08:41
helpers for Java String
import com.beiyanght.masterdata.common.exception.DataNotFoundException;
/**
* helpers for String
*
* @author keating_andy_given
*/
public class StringHelp {
private enum Flag{
@keating
keating / gist:2881867
Created June 6, 2012 13:30 — forked from samqiu/railscasts.rb
download railscast video
#!/usr/bin/ruby
require 'rss'
p 'Downloading rss index'
rss_string = open('http://feeds.feedburner.com/railscasts').read
rss = RSS::Parser.parse(rss_string, false)
videos_urls = rss.items.map { |it| it.enclosure.url }.reverse
videos_filenames = videos_urls.map {|url| url.split('/').last }
@keating
keating / crawl.rb
Created July 15, 2012 15:32
crawl a website
#encoding: utf-8
require "nokogiri"
require "open-uri"
domain = 'http://sample.com&page='
begin
1.upto 1000 do |i|
html = open(domain + i.to_s, :proxy => "http://127.0.0.1:8087", :read_timeout => 1).read
html.force_encoding("gbk")
@keating
keating / 给关联关系赋值,发生了什么?.rb
Created September 14, 2012 02:11
给关联关系赋值,发生了什么?
# 给关联关系赋值,发生了什么?
@sme = Sme.find(params[:id])
@sme.sme_inspections = @sme.build_inspections params[:inspections]
# @sme.sme_inspections的class是个array,@sme.build_inspections params[:inspections] 只不过构造了一个sme_inspection的数组,并且数组中sme_inspection的sme_id为空
# 但接下来发生了这些
#SmeInspection Load (0.7ms) SELECT "sme_inspections".* FROM "sme_inspections" WHERE "sme_inspections"."sme_id" = 29