Skip to content

Instantly share code, notes, and snippets.

View GongLe's full-sized avatar

Gongle GongLe

  • shanghai ideal
  • 中国
View GitHub Profile
@GongLe
GongLe / SaveImageFromUrl.java
Created February 14, 2017 06:19 — forked from chandu-io/SaveImageFromUrl.java
java :: save image from url
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.URL;
public class SaveImageFromUrl {
public static void main(String[] args) throws Exception {
String imageUrl = "https://www.google.com/images/srpr/logo3w.png";
@GongLe
GongLe / CountChar.java
Last active March 16, 2016 08:50
java统计字符串中包含中文字符、英文字符和数字字符
public static int countChar(String str) {
int abccount = 0;
int numcount = 0;
int spacecount = 0;
int othercount = 0;
char[] b = str.toCharArray();
for (int i = 0; i < b.length; i++) {
if (b[i] >= 'a' && b[i] <= 'z' || b[i] >= 'A' && b[i] <= 'Z') {
abccount++;
} else if (b[i] >= '0' && b[i] <= '9') {
@GongLe
GongLe / gist:2800aa2522614a7163f5
Last active August 29, 2015 14:24
java Url encodeURIComponent decodeURIComponent utils
public class UrlUtils {
public static final String ALLOWED_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.!~*'()";
public static String encodeURIComponent(String input) {
if(StringUtils.isEmpty(input)) {
return input;
}
int l = input.length();
StringBuilder o = new StringBuilder(l * 3);
@GongLe
GongLe / gist:9130391
Created February 21, 2014 07:57
感觉这种模式转换成seajs module,写法更加优美
(function (root, factory) {
//seajs module define
define(function(require, exports, module) {
var jQuery = require('jquery');
factory(jQuery);
});
}(this, function ($) {
//export module
return $;
}));
@GongLe
GongLe / gist:6278194
Created August 20, 2013 07:36
jQuery validation plugin 大陆电话验证.
// 电话号码验证
jQuery.validator.addMethod("isTel", function(value, element) {
var tel = /^\d{3,4}-?\d{7,9}$/; //电话号码格式010-12345678
return this.optional(element) || (tel.test(value));
}, "请正确填写您的电话号码");
// 联系电话(手机/电话皆可)验证
jQuery.validator.addMethod("isPhone", function(value,element) {
var length = value.length;
var mobile = /^(((13[0-9]{1})|(18[0-9]{1})|(15[0-9]{1}))+\d{8})$/;
@GongLe
GongLe / gist:6111771
Created July 30, 2013 10:10
JPA @onetomany 级联删除Many端
When we use JPA @oneToMany
if you remove a dependent object from a OneToMany collection it will not be deleted, JPA1.0 don’t support it itself, it requires that you explicitly call remove() on it.
In JPA2.0 ,you need do add “orphanRemoval” to “@OneToMany” ,
just like this:
@OneToMany(mappedBy = "A", orphanRemoval=true,cascade = CascadeType.ALL)
@GongLe
GongLe / gist:6111770
Created July 30, 2013 10:10
JPA @onetomany 级联删除Many端
When we use JPA @oneToMany
if you remove a dependent object from a OneToMany collection it will not be deleted, JPA1.0 don’t support it itself, it requires that you explicitly call remove() on it.
In JPA2.0 ,you need do add “orphanRemoval” to “@OneToMany” ,
just like this:
@OneToMany(mappedBy = "A", orphanRemoval=true,cascade = CascadeType.ALL)
@GongLe
GongLe / javascript 格式化字符串方法
Created July 18, 2013 05:19
javascript基于扩充String对象原型的格式化字符串方法.
/**
* 扩充String原型,字符串模板格式化
* <code>
* Array数据: '{0}'.format('hello world') ;
* json数据:'{name}'.format({'name':'hello world'});
* 输出结果:hello world
* </code>
* @author Gongle
* @date 2013年4月22日10:50:29
*/
@GongLe
GongLe / html iframe页面内无框架无滚动条
Created July 18, 2013 05:17
html iframe页面内无框架无滚动条
<iframe src="javascript:;" width="750" height="30" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" allowtransparency="yes"></iframe>
@GongLe
GongLe / javascript转换日期字符串为Date对象
Last active December 19, 2015 13:48
javascript转换日期字符串为Date对象
/**
日期格式字符串转为Date.getTime对象
@param str 日期格式字符串
@return Date time
<p>
eg: string2Date(2013-07-13 10:00:00' ) -> 1373700600000
</p>
**/
function string2Date(str){
return (new Date(Date.parse(str.replace(/-/g, "/")))).getTime() ;