Skip to content

Instantly share code, notes, and snippets.

@wenchy
wenchy / mapread.c
Created August 18, 2020 13:09 — forked from marcetcheverry/mapread.c
mmap and read/write string to file
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
@wenchy
wenchy / timezone.cpp
Last active July 16, 2019 00:31
Get timezone offset with cache optimization.
#include <time.h>
#include <iostream>
#include <limits>
int TimeZoneOffsetSecond()
{
// cache, need compute only once
static int offset = std::numeric_limits<int>::min();
if (offset != std::numeric_limits<int>::min())
{
[user]
name = yourname
email = yourname@xxx.com
[push]
default = simple
[diff]
tool = vimdiff
[difftool]
prompt = false
[credential]
@wenchy
wenchy / shell_cheatsheet.md
Last active June 28, 2018 06:53
CheatSheet

shell变量的子串的删除/替换

${#string} 返回$string的长度

${string:position} 在$string中,从$position位置之后开始提取子串

${string:position:length} 在$string中,从$position位置之后开始提取$length长度的子串

@wenchy
wenchy / form.py
Last active April 23, 2018 05:24
HTML form generator
#!/usr/bin/python
# coding: utf-8
import json
import inspect
def html_form(func):
argspec = inspect.getargspec(func)
default_start = len(argspec[0]) - len(argspec[3])
index = 0
args = {}
@wenchy
wenchy / colored_logger.py
Created April 20, 2018 07:26
Python Colored Logger
########## Encapsule Colored Logger Begin ##########
LOG_FORMAT = "%(asctime)s|%(filename)s:%(lineno)d|%(levelname)s|%(funcName)s|%(message)s"
class LoggerFactory:
def __init__(self, name, path=""):
self.__name = name
self.__path = path
timestr = time.strftime('%Y%m%d', time.localtime(time.time()))
self.__logfile = path + name + "_" + timestr + ".log"
def get_normal_logger(self):
@wenchy
wenchy / .vimrc
Last active August 18, 2016 06:53
A simple and useful VIM configuration with no plugins but only a solarized colorscheme
""""""""""""""""""""""""""""""""""""""""""
""" Pre: Get the solarized colorscheme
""" mv solarized.vim ~/.vim/colors/
""""""""""""""""""""""""""""""""""""""""""
""" Be iMproved
set nocompatible
syntax enable
" syntax on
@wenchy
wenchy / Makefile
Last active January 16, 2024 15:36
Compile all .cpp files into one target under the current directory.
CC := g++
CFLAGS := -Wall -g
TARGET := test
# $(wildcard *.cpp /xxx/xxx/*.cpp): get all .cpp files from the current directory and dir "/xxx/xxx/"
SRCS := $(wildcard *.cpp)
# $(patsubst %.cpp,%.o,$(SRCS)): substitute all ".cpp" file name strings to ".o" file name strings
OBJS := $(patsubst %.cpp,%.o,$(SRCS))
all: $(TARGET)
@wenchy
wenchy / Makefile
Last active January 7, 2016 08:12 — forked from isaacs/Makefile
A Makefile introduction and some useful snippets.
# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
@wenchy
wenchy / Vertex Array Object (VAO).md
Created January 6, 2016 07:06
A Vertex Array Object (VAO) is an OpenGL Object that stores all of the state needed to supply vertex data.

VAOs act similarly to VBOs and textures with regard to how they are bound. Having a single VAO bound for the entire length of your program will yield no performance benefits because you might as well just be rendering without VAOs at all. In fact it may be slower depending on how the implementation intercepts vertex attribute settings as they're being drawn.

The point of a VAO is to run all the methods necessary to draw an object once during initialization and cut out all the extra method call overhead during the main loop. The point is to have multiple VAOs and switch between them when drawing.

In terms of best practice, here's how you should organize your code:

initialization:
    for each batch
 generate, store, and bind a VAO