Skip to content

Instantly share code, notes, and snippets.

View piaoger's full-sized avatar

Piaoger piaoger

View GitHub Profile
@piaoger
piaoger / json_marshal.go
Last active August 29, 2015 14:06
json marshal in go
package main
import (
"fmt"
"encoding/json"
)
type js struct {
A map[string]interface{}
@piaoger
piaoger / nanovg_torus.cpp
Last active August 29, 2015 14:07
An OpenGL2 Exmaple: glew, glfw and nanovg.
// An OpenGL3 Exmaple: glew, glfw and nanovg.
// 2D and 3D in same scene. Torus is drawn with static display list.
#include <stdlib.h>
#include <math.h>
#include <stdio.h>
#include "GL/glew.h"
@piaoger
piaoger / rotating_torus.cpp
Created October 13, 2014 01:29
Draw rotating Torus with GLFW3
// Draw rotating Torus with GLFW3
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <GLFW/glfw3.h>
static void drawTorus(int numMajor, int numMinor, float majorRadius, float minorRadius)
{
static double PI = 3.1415926535897932384626433832795;
@piaoger
piaoger / copyfileSync.js
Created July 23, 2015 03:22
copyfileSync in node.js
function copyFileSync(srcFile, destFile) {
var BUF_LENGTH, buff, bytesRead, fdr, fdw, pos;
BUF_LENGTH = 64 * 1024;
buff = new Buffer(BUF_LENGTH);
fdr = fs.openSync(srcFile, 'r');
fdw = fs.openSync(destFile, 'w');
bytesRead = 1;
pos = 0;
while (bytesRead > 0) {
@piaoger
piaoger / jsfallback.html
Last active September 9, 2015 05:13
js fallback
<body>
<!-- from https://github.com/airbnb/airpal/blob/master/src/main/resources/assets/index.html >
<!-- to avoid being banded by GFW -->
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>window.jQuery || document.write('<script src="app/javascripts/vendor/jquery-1.9.0.min.js"><\/script>')</script>
</body>
@piaoger
piaoger / filehelper.scala
Created December 1, 2015 03:04
fileutils.scala
def deleteFile(dfile : File) : Unit = {
if(dfile.isDirectory){
val files = dfile.listFiles
if(files != null)
files.foreach{ f => deleteFile(f) }
}
dfile.delete
}
@piaoger
piaoger / git_clone_tag.sh
Last active December 30, 2015 18:49
git clone specific tag
# git clone will give you the whole repository.
# After the clone, you can list the tags with git tag -l;
# then checkout a specific tag: git checkout tags/<tag_name>
git clone <repo-address>
git tag -l
git checkout <tag-name>
@piaoger
piaoger / formatDate.js
Last active January 25, 2016 05:53
format date utc
// borrowed from http://www.cnblogs.com/duanhuajian/p/4485106.html
// change: use utc time instead
function formatDate (date, fmt) {
var o = {
"M+" : date.getUTCMonth()+1,
"d+" : date.getUTCDate(),
"h+" : date.getUTCHours()%12 == 0 ? 12 : date.getUTCHours()%12,
"H+" : date.getUTCHours(),
"m+" : date.getUTCMinutes(),
"s+" : date.getUTCSeconds(),
@piaoger
piaoger / reverseproxy.go
Created May 13, 2016 06:25
reverseproxy.go
package main
import (
"log"
"net/http"
"net/http/httputil"
"net/url"
)
type handle struct {
@piaoger
piaoger / clearcache.sh
Created June 23, 2016 08:30
clear cached memory in Linux
#!/bin/sh
# https://www.blackmoreops.com/2014/10/28/delete-clean-cache-to-free-up-memory-on-your-slow-linux-server-vps/
sync
sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"