Skip to content

Instantly share code, notes, and snippets.

View hellojinjie's full-sized avatar
🏠
Working from home

hellojinjie hellojinjie

🏠
Working from home
View GitHub Profile
@hellojinjie
hellojinjie / sun.net.www.protocol.http.HttpURLConnection.java
Last active December 23, 2015 14:39
sun.net.www.protocol.http.HttpURLConnection.java 中一段很搞的代码。 内部匿名类无法访问外面的非 final 的变量。这里用数组的形式进行 workaround
final boolean result[] = {false};
java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
try {
InetAddress a1 = InetAddress.getByName(h1);
InetAddress a2 = InetAddress.getByName(h2);
result[0] = a1.equals(a2);
} catch (UnknownHostException e) {
} catch (SecurityException e) {
}
@hellojinjie
hellojinjie / hue_install_error.sh
Created September 23, 2013 11:07
hue_install_error.sh
jj@hellojinjie hue-2.5.0 :) $ python2.7 /home/jj/Workspaces/lib/hue-2.5.0/tools/virtual-bootstrap/virtual-bootstrap.py -qq --no-site-packages /home/jj/Workspaces/lib/hue-2.5.0/build/env
Traceback (most recent call last):
File "/home/jj/Workspaces/lib/hue-2.5.0/tools/virtual-bootstrap/virtual-bootstrap.py", line 1504, in <module>
main()
File "/home/jj/Workspaces/lib/hue-2.5.0/tools/virtual-bootstrap/virtual-bootstrap.py", line 547, in main
use_distribute=options.use_distribute)
File "/home/jj/Workspaces/lib/hue-2.5.0/tools/virtual-bootstrap/virtual-bootstrap.py", line 637, in create_environment
install_setuptools(py_executable, unzip=unzip_setuptools)
File "/home/jj/Workspaces/lib/hue-2.5.0/tools/virtual-bootstrap/virtual-bootstrap.py", line 379, in install_setuptools
_install_req(py_executable, unzip)
@hellojinjie
hellojinjie / LockWaitTimeout.java
Last active December 23, 2015 18:59
mysql lock wait timeout
106626 Lock wait timeout exceeded; try restarting transaction
106627 java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
106628 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1074)
106629 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
106630 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
106631 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
106632 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
106633 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
106634 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
106635 at com.mysql.jdbc.PreparedStatement.execute(PreparedStatement.java:1379)
@hellojinjie
hellojinjie / GenericUDAFCdnBytesLoaded.java
Created September 29, 2013 08:46
NullPointException in UDAF
package com.jaunty.hive.udf;
import java.util.Map;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDFArgumentLengthException;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.parse.SemanticException;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator;
import org.apache.hadoop.hive.ql.udf.generic.GenericUDAFEvaluator.AggregationBuffer;
[root@localhost ~]# hdparm -Tt /dev/sdb1
/dev/sdb1:
Timing cached reads: 25642 MB in 2.00 seconds = 12842.90 MB/sec
Timing buffered disk reads: 532 MB in 3.01 seconds = 176.98 MB/sec
[root@localhost ~]# mount
/dev/mapper/VolGroup-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
@hellojinjie
hellojinjie / TrafficGenerator.scala
Last active December 27, 2015 08:59
TrafficGenerator.scala
import scala.collection.mutable.LinkedList
import scala.collection.mutable.ListBuffer
import scala.compat._
import java.io._
import java.net._
import java.util._
import scala.util.Random
import java.nio.charset.Charset
import java.util.concurrent._
import java.util.concurrent.atomic._
@hellojinjie
hellojinjie / ErrorLogAnalyze.scala
Created December 5, 2013 08:39
ErrorLogAnalyze.scala
import scala.io._
import java.io._
import java.util.regex._
object ErrorLogAnalyze {
def main(args: Array[String]) = {
val files = if (args.length == 0) new File(".") else new File(args(0))
val lines = getLogs(files.listFiles.filter(_.getName.contains("error")).toList)
val errorAndHeartbeat = lines.partition(line => line.contains("ERROR") && line.contains("HEARTBEAT"))._1
@hellojinjie
hellojinjie / Utils.cs
Last active December 17, 2017 08:47
C# DataTable to JSON
public class Utils
{
public static object DataTableToObject(DataTable dataTable)
{
var list = new List<object>();
foreach (DataRow row in dataTable.Rows)
{
var pairList = new List<KeyValuePair<string, object>>();
foreach (DataColumn column in dataTable.Columns)
{
_.templateSettings = {
interpolate : /\{\{(.+?)\}\}/g, // print value: {{ value_name }}
evaluate : /\{%([\s\S]+?)%\}/g, // excute code: {% code_to_execute %}
escape : /\{%-([\s\S]+?)%\}/g // excape HTML: {%- <script> %} prints &lt;script&gt;
};
$.fn.smartFloat = function() {
var position = function(element) {
var top = element.position().top, pos = element.css("position");
$(window).scroll(function() {
var scrolls = $(this).scrollTop();
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.css({
position: "fixed",
top: 0