Skip to content

Instantly share code, notes, and snippets.

@tommy351
tommy351 / gist:4961934
Created February 15, 2013 17:31
Quick sort
var sort = function(arr, left, right){
if (right <= left) return;
// 取中間值作為 pivot
var pivotIndex = parseInt((left + right) / 2),
pivot = arr[pivotIndex];
// pivot 移至最右方
swap(arr, pivotIndex, right);
var unique = function(arr){
var a = [],
l = arr.length;
for (var i = 0; i < l; i++){
for (var j = i + 1; j < l; j++){
if (arr[i] === arr[j]) j = ++i;
}
a.push(arr[i]);
}
return a;
var flatten = function(arr){
for (var i = 0, len = arr.length; i < len; i++){
var item = arr[i];
if (Array.isArray(item)){
len += item.length - 1;
[].splice.apply(arr, [i, 1].concat(item));
i--;
}
}
return arr;
@tommy351
tommy351 / gist:6315207
Last active December 21, 2015 13:49
Hexo gzip console plugin
hexo.extend.console.register('gzip', function(args, callback){
hexo.call('generate', function(err){
if (err) return callback(err);
// do gzip here...
});
});
@tommy351
tommy351 / gist:6408947
Last active September 28, 2017 12:11
Get scroll bar's width.
(function(window){
var cache = 0;
var scrollBarWidth = function(){
if (cache) return cache;
var elem = document.createElement('div');
elem.style.position = 'absolute';
elem.style.top = '-9999px';
elem.style.overflow = 'scroll';
import java.util.*;
public class s401631741HW1 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("i = ");
int number = scanner.nextInt();
Random random = new Random();
int[][] arr = new int[number][];
@tommy351
tommy351 / tku_wifi.sh
Last active August 29, 2015 13:57
TKU WiFi Utilities
#!/bin/sh
function find_gateway(){
gateway=$(netstat -nr | grep "default" | awk "{print \$2}")
if [[ "$(grep "163.13." <<< $gateway)" == "" ]]; then
echo "Gateway $gateway is not a valid TKU IP!"
exit 1
fi
}
line 1705: unknown code state: 0x7fff5fbfdf90
line 1708: unknown code state: /Users/SkyArrow/Dropbox/Projects/Hexo/hexo/node_modules/lodash/dist/lodash.js:10
line 1710: unknown code state: 0x100649000
line 1722: unknown code state: 0x7fff5fbfd3b0
line 3090: unknown code state: 0x7fff5fbf7348
Statistical profiling result from v8.log, (1634265 ticks, 222436 unaccounted, 0 excluded).
[Unknown]:
ticks total nonlib name
222436 13.6%
class Test {
public static void main(String[] args){
System.out.println("======= myGetChars =======");
String str = "test";
char[] arr1 = new char[4];
myGetChars(str, 0, 4, arr1, 0);
System.out.printf("copy %s => %s\n", str, new String(arr1));
char[] arr2 = new char[2];
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>留言板</title>
</head>
<body>
<% messages.forEach(function(line, i){ %>
<p>
<strong><%= line.author %></strong>: <%= line.content %>