Skip to content

Instantly share code, notes, and snippets.

View kennir's full-sized avatar
🏠
Working from home

Ken Zhang kennir

🏠
Working from home
View GitHub Profile
@kennir
kennir / trim.h
Created July 5, 2016 05:34
trim string
// trim from start
static inline std::string &ltrim(std::string &s) {
s.erase(s.begin(), std::find_if(s.begin(), s.end(), std::not1(std::ptr_fun<int, int>(std::isspace))));
return s;
}
// trim from end
static inline std::string &rtrim(std::string &s) {
s.erase(std::find_if(s.rbegin(), s.rend(), std::not1(std::ptr_fun<int, int>(std::isspace))).base(), s.end());
return s;
@kennir
kennir / add_new_column.py
Last active July 5, 2016 05:44
Adds a new column where each entry is the list of two other columns
df= pd.DataFrame(np.random.randn(10,4))
df[4]= [[df[2][x],df[3][x]] for x in range(df.shape[0])]
@kennir
kennir / groupby_multindex.py
Last active July 5, 2016 05:45
Groupby MultiIndex level
In [26]: s
first second third
bar doo one 0.404705
two 0.577046
baz bee one -1.715002
two -1.039268
foo bop one -0.370647
two -1.157892
qux bop one -1.344312
@kennir
kennir / hide_code.py
Created July 5, 2016 05:46
在iPython Notebook中隐藏代码
from IPython.display import HTML
HTML('''<script>
code_show=true;
function code_toggle() {
if (code_show){
$('div.input').hide();
} else {
$('div.input').show();
}
@kennir
kennir / delete_column.sql
Created July 5, 2016 05:49
Delete column in sqlite3
BEGIN TRANSACTION;
CREATE TEMPORARY TABLE t1_backup(a,b);
INSERT INTO t1_backup SELECT a,b FROM t1;
DROP TABLE t1;
CREATE TABLE t1(a,b);
INSERT INTO t1 SELECT a,b FROM t1_backup;
DROP TABLE t1_backup;
COMMIT;
@kennir
kennir / rotate_around.cs
Created July 13, 2016 05:57
RotateAround in Unity
void Update () {
//this.transform.RotateAround(this.transform.parent.position, this.transform.parent.up, 1);
MyRotateAround(this.transform.parent.position, this.transform.parent.up, 1);
}
void MyRotateAround(Vector3 pos, Vector3 up, float degree)
{
Quaternion q = Quaternion.AngleAxis(degree, up);
this.transform.position = q * (this.transform.position-pos) + pos;
@kennir
kennir / CSVReader.cs
Created July 13, 2016 05:57
CSV Reader for unity
/*
CSVReader by Dock. (24/8/11)
http://starfruitgames.com
usage:
CSVReader.SplitCsvGrid(textString)
returns a 2D string array.
Drag onto a gameobject for a demo of CSV parsing.
Shader "Sprites/Gray"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
@kennir
kennir / SpritesClippedShader.shader
Created July 13, 2016 05:58
Clipping sprite shader for Unity
Shader "Sprites/Clipped"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_ClipX ("Clip X", Range(0.0, 2000.0)) = 0
_ClipY ("Clip Y", Range(0.0, 1000.0)) = 0
_Width ("Width", Range(0.0, 2000.0)) = 2000
@kennir
kennir / # protobuf250 - 2016-09-23_11-33-58.txt
Created September 23, 2016 03:35
protobuf250 (homebrew/versions/protobuf250) on macOS 10.12 - Homebrew build logs
Homebrew build logs for homebrew/versions/protobuf250 on macOS 10.12
Build date: 2016-09-23 11:33:58