Skip to content

Instantly share code, notes, and snippets.

View yangg's full-sized avatar

Brook yangg

  • ShenZhen, China
View GitHub Profile
@yangg
yangg / .update_filenametags.bat
Created June 28, 2011 09:40
udpate project ctags
cd $project
ctags -e -R --languages=php -f tags . E:/IDKin/iCoreServer/res/IDKin/PHP_Resources
find . -not -regex ".*\/\(\.svn\|images\|temp\)\/.*" -type f -printf "%f\t%p\t1\n" | sort -f >.filenametags
exit 0
# vim: ft=sh
@yangg
yangg / .vimrc
Created July 2, 2011 09:32
Compile JavaScriptLint
" add to .vimrc
function! Make()
if &modified | silent write | endif
if &makeprg == 'make' | return | endif
silent make
execute 'cw'
endfunction
autocmd Filetype javascript setlocal makeprg=jsl\ -nologo\ -nofilelisting\ -nosummary\ -nocontext\ -conf\ /etc/jsl.conf\ -process\ % |
@yangg
yangg / gist:1062232
Created July 3, 2011 13:41
Shell scripts(Ubuntu)
Mint
# screenlets
# Show bandwidth use oneliner
while true; do cat /proc/net/dev; sleep 1; done | awk -v dc="date \"+%T\"" '/eth0/{i = $2 - oi; o = $10 - oo; oi = $2; oo = $10; dc|getline d; close(dc); if (a++) printf "%s %8.2f KiB/s in %8.2f KiB/s out\n", d, i/1024, o/1024}'
# limit the cpu usage of a process
sudo cpulimit -p pid -l 50
# ubuntu root
@yangg
yangg / formatsize.cs
Created September 26, 2011 08:26
Format Filesize
// http://www.cnblogs.com/yaob/archive/2011/05/14/2046013.html
public string formatSize(long size)
{
if (size == 0) return "0";
string[] sizetext = new string[] { "B", "KB", "MB", "GB", "TB", "PB" };
int i = (int)Math.Floor(Math.Log(size, 1024));
return Math.Round(size / Math.Pow(1024, i), 2).ToString() + " " + sizetext[i];
}
@yangg
yangg / zswang.js
Created October 6, 2011 07:32
js正则匹配数组中不重复的元素
var arr=["a","b","c","a","ba","bc"];
alert(arr.join(",").match( /([^,]+)(?!.*,\1(,|$))/ig));
Array.prototype.deleteEle=function(){
var arr=this,o={},newArr=[],i;
for( i=0;i<arr.length;i++){
if(typeof(o[arr[i]])==="undefined"){
newArr[newArr.length]=arr[i]
}
@yangg
yangg / background.html
Created November 15, 2011 07:49
Open Frame in New Tab in Chrome
<!DOCTYPE HTML>
<html>
<script>
function createMenu() {
chrome.contextMenus.create({
title: "Open &Frame in New Tab",
onclick: function(info, tab) {
chrome.tabs.create({
url: info.frameUrl || info.pageUrl,
index: tab.index + 1,
@yangg
yangg / realpath.c
Created December 2, 2011 12:28
realpath
// realpath.c: display the absolute path to a file or directory.
// Adam Liss, August, 2007
// This program is provided "as-is" to the public domain, without express or
// implied warranty, for any non-profit use, provided this notice is maintained.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <libgen.h>
#include <limits.h>
@yangg
yangg / background.html
Created December 8, 2011 05:46
Media Logger
<!DOCTYPE HTML>
<html>
<script>
chrome.experimental.webRequest.onResponseStarted
.addListener(function(details) {
console.log(details.url);
}
, {urls: ["*://*/*.mp3", "*://*/*.mp4", "*://*/*.flv", "*://*/*.webm"]}
);
</script>
@yangg
yangg / sleep.cs
Created December 10, 2011 15:19
延时函数(不假死)
using System.Runtime.InteropServices;
[DllImport("kernel32.dll")]
static extern uint GetTickCount();
static void Delay(uint ms) {
uint start = GetTickCount();
while (GetTickCount() - start < ms) {
Application.DoEvents();
}
@yangg
yangg / strbuf.js
Created December 17, 2011 10:18
String Buffer Class for Javascript
/*!
* StrBuf: A javascript string buffer class
* @author uedsky (http://uedsky.com)
* Last Modified: Dec 17, 2011
*/
/**
* @class String concat
* @return {StrBuf/String}
* @constructor