Skip to content

Instantly share code, notes, and snippets.

View piaoger's full-sized avatar

Piaoger piaoger

View GitHub Profile
@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 / maxstacksize.html
Created March 21, 2014 02:32
Get max call stack size in browser
<!-- A script to get max call stack size in browser
In my Macbook pro
Firefox 28:
maxStackSize = 350801 (dynamic, but always above 300000)
error: InternalError: too much recursion
Safari 7.0.2
maxStackSize = 58034
error: RangeError: Maximum call stack size exceeded.
Chrome 33:
@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 / test_mmap_ios.m
Last active July 8, 2020 18:34
mmap on ios
// It's tested on ios 8.2 ..
// Apple document about virtual memory:
// Both OS X and iOS include a fully-integrated virtual memory system that you cannot turn off; it is always on.
// https://developer.apple.com/library/mac/documentation/Performance/Conceptual/ManagingMemory/Articles/AboutMemory.html
// Discussing mmap on ios:
// http://stackoverflow.com/questions/13425558/why-does-mmap-fail-on-ios
// http://stackoverflow.com/questions/9184773/is-there-a-practical-limit-on-the-number-of-memory-mapped-files-in-ios
#include <sys/mman.h>
@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 / setfiletime.js
Created August 24, 2015 03:40
Set file time in node.js
// set file add/mode time
var fs = require('fs')
function setFileTime(filePath, atime, mtime) {
fs.utimesSync(filePath, atime, mtime);
}
var date = new Date('Thu Aug 20 2015 15:10:36 GMT+0800 (CST)');
setFileTime('/tmp/scache/fdf/admin.log', date, date);
@piaoger
piaoger / git-sync-all-branches.sh
Created August 31, 2015 01:34
git-sync-all-branches
# fetch all branches
# From: http://stackoverflow.com/questions/10312521/how-to-fetch-all-git-branches
#!/bin/bash
for branch in `git branch -a | grep remotes | grep -v HEAD | grep -v master`; do
git branch --track ${branch##*/} $branch
done
git fetch --all
@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>