Total Pageviews
Thursday, December 8, 2011
Wednesday, December 7, 2011
Monday, December 5, 2011
Del key on MacBook PRO
On Macbook pro, the “delete” is actually backspace. To delete, you need Fn + delete
Sunday, December 4, 2011
Align image and text vertically
<div> <img style="width:30px;height:60px;vertical-align:middle"> <span style="">Text</span> </div>See also: http://stackoverflow.com/questions/489340/how-do-i-vertically-align-text-next-to-an-image-with-css
How to post XML or HTML code in your blog
If you want to post XML or HTML source code into your blog, try use the encoder/formatter/converter below:
Calculate MD5 hash
- On Mac OS X
md5 -s "string"
- On Linux
echo -n "string" | md5sum
- Use the online MD5 calculator: http://www.adamek.biz/md5-generator.php
Monday, November 21, 2011
HEX mode in VIM
- Enter hex edit mode:
%!xxd
- Exit hex edit mode:
%!xxd -r
Wednesday, November 16, 2011
Multiples of bytes
Multiples of bytes | |||
---|---|---|---|
SI decimal prefixes | IEC binary prefixes | ||
Name (Symbol) |
Value | Name (Symbol) |
Value |
kilobyte (kB) | 103 | kibibyte (KiB) | 210 = 1.024 × 103 |
megabyte (MB) | 106 | mebibyte (MiB) | 220 ≈ 1.049 × 106 |
gigabyte (GB) | 109 | gibibyte (GiB) | 230 ≈ 1.074 × 109 |
terabyte (TB) | 1012 | tebibyte (TiB) | 240 ≈ 1.100 × 1012 |
petabyte (PB) | 1015 | pebibyte (PiB) | 250 ≈ 1.126 × 1015 |
exabyte (EB) | 1018 | exbibyte (EiB) | 260 ≈ 1.153 × 1018 |
zettabyte (ZB) | 1021 | zebibyte (ZiB) | 270 ≈ 1.181 × 1021 |
yottabyte (YB) | 1024 | yobibyte (YiB) | 280 ≈ 1.209 × 1024 |
Convert byte size into human readable format in Java ( and GWT )
Java:
Orgin from here
public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp-1) + (si ? "" : "i"); return String.format("%.1f %sB", bytes / Math.pow(unit, exp), pre); }Java GWT:
public static String humanReadableByteCount(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return toFixed(bytes / Math.pow(unit, exp), 1) + " " + pre + "B"; } public static native String toFixed(double d, int fixed)/*-{ return d.toFixed(fixed); }-*/;
Orgin from here
JSNI function in GWT to format numbers
public class NumberUtil { public static native String toFixed(double d, int fixed)/*-{ return d.toFixed(fixed); }-*/; public static native String toPrecision(double d, int precision)/*-{ return d.toPrecision(precision); }-*/; }
see also this article.
Format numbers in javascript
var num = 1; var result = num.toFixed(2); // result = 1.00 num = 123.4567; result = num.toFixed(3); // result = 123.456 num = 123.4567; result = num.toPrecision(4); // result = 123.4 num = 123.4567; result = num.toPrecision(3); // result = 123 num = 555.55; result = num.toPrecision(2); // result will equal 5.6e+2
see also this article.
Sunday, November 13, 2011
GWT: JSNI function to validate URL
public native boolean isValidUrl(String url) /*-{ var pattern = /(http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/; return pattern.test(url); }-*/;
Java: use signed types to store unsigned values
short, int, long are always signed in Java. However, it only matters if you are doing math with it. Otherwise, you can store unsigned values using the signed types by utilizing the sign bit.
If you do need to do some math:
1) for unsigned short, us,
convert it to int by masking: int i = us & 0xffff;
Do all arithmetic with int operands, modulo 0xffff.
When you are done, cast the result back to int and transmit it.
2) for unsigned int, ui,
convert it to long by masking: long l = ui & 0xffffffffL;
Do all arithmetic with long operands, modulo 0xffffffffL.
When you are done, cast the result back to int and transmit it.
Subscribe to:
Posts (Atom)