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
<?php
function getTaobaoURLFromShortURL($shortURL)
{
$contents = file_get_contents($shortURL);
$pattern = '/d="J_Url" value=\'(.+)\'>./';
preg_match($pattern, $contents, $matches);
return urldecode($matches[1]);
}
function getItemIdFromURL($itemURL)
@hellojinjie
hellojinjie / onlineview.sql
Created July 21, 2014 07:20
onlineview.sql
SELECT
d.parent_id, views, cdn,
from_unixtime(1405267200 + row_number * 60) as step_time
FROM
(SELECT
apptype_id, game_id, count(view_id) AS views, r.row_number,
sum(bytes_loaded_cdn1 + bytes_loaded_cdn2 + bytes_loaded_cdn3 + bytes_loaded_cdn4) /duration as cdn
FROM
(SELECT
@curRow:=@curRow + 1 AS row_number
@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 / 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._
[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 / 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;
@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 / 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 / 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 / guesspath.sh
Created September 10, 2013 07:34
神奇的一段 shell 代码用来判断当前脚本所在的位置,从 hadoop 的启动脚本里复制过来的
this="${BASH_SOURCE-$0}"
dir=$(cd -P -- "$(dirname -- "$this")" && pwd -P)