Skip to content

Instantly share code, notes, and snippets.

View nathanchen's full-sized avatar

Nathan nathanchen

View GitHub Profile
@nathanchen
nathanchen / jQuery: Mouse FocusIn and Blur to change background color.js
Created August 1, 2012 02:11
jQuery - Mouse FocusIn and Blur to change background color
$(':text').focusin(function () {
$(this).css('background-color', 'yellow');
});
$(':text').blur(function () {
$(this).css('background-color', '#fff');
});
@nathanchen
nathanchen / jQuery: buttonDoubleClickDisable.js
Created August 1, 2012 02:13
jQuery - Once button was clicked, change its value to 'Please wait...' and disable it
$(':submit').click(function () {
$(this).attr('value', 'Please wait...');
$(this).attr('disabled', 'true');
});
@nathanchen
nathanchen / jQuery: getNumOfTags.js
Created August 1, 2012 02:15
jQuery - get number of tags
var count = $('*').length;
alert(count);
@nathanchen
nathanchen / JAVA: 比较两个字节数组.java
Created August 2, 2012 14:12
JAVA - 比较两个字节数组
public int compareTo(byte[] buffer1, int offset1, int length1, byte[] buffer2, int offset2, int length2)
{
if(buffer1 == buffer2 && offset1 == offset2 && length1 == length2)
return 0;
int end1 = offset1 + length1;
int end2 = offset2 + length2;
for(int i = offset1, j = offset2; i < end1 && j < end2;
@nathanchen
nathanchen / jQuery - fadein.js
Created August 3, 2012 01:57
jQuery - fadein
$(document).ready(function () {
$('#message').fadeIn('slow');
});
@nathanchen
nathanchen / jQuery - Change Text color and background color.js
Created August 3, 2012 02:12
jQuery - Change Text color and background color
$(':button').click(function () {
$('p').css('background-color', '#000').css('color', '#fff');
});
@nathanchen
nathanchen / Java - 验证Object是否为数组
Created August 13, 2012 15:05
JAVA - 验证Object是否为数组
Object o;
StringBuffer sbuf;
if(! o.getClass().isArray())
{
safeObjectAppend(sbuf, o);
}
private static void safeObjectAppend(StringBuffer sbuf, Object o)
@nathanchen
nathanchen / snippet.java
Created August 14, 2012 04:55
JAVA - 不能为null值
public static <T> T checkNotNull(T reference)
{
if(reference == null)
throw new NullPointerException();
return reference;
}
public static <T> T checkNotNull(T reference, @Nullable Object errorMessage)
{
if(reference == null)
@nathanchen
nathanchen / snippet.java
Created August 14, 2012 04:56
JAVA - 数组元素格式化输出
@visibleForTesting static String format (String template, @Nullable Object... args)
{
template = String.valueOf(template);
StringBuffer builder = new StringBuffer(template.length() + 16 * args.length);
int templateStart = 0;
int i = 0;
while(i < args.length)
{
int placeholderStart = template.indexOf("%s", templateStart);
@nathanchen
nathanchen / snippet.java
Created August 14, 2012 05:18
JAVA - 查看String是否为null或者空
public static String nullToEmpty(@Nullable String string)
{
return (string == null) ? "" : string;
}
public static @Nullable String emptyToNull(@Nullable String string)
{
return isNullOrEmpty(string) ? null : string;
}