Skip to content

Instantly share code, notes, and snippets.

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

tianchaijz tianchaijz

🏠
Working from home
View GitHub Profile
@tianchaijz
tianchaijz / postgres-json-cheatsheet.md
Created March 20, 2018 08:36 — forked from rmtsrc/postgres-json-cheatsheet.md
Using JSON in Postgres by example

PostgreSQL JSON Cheatsheet

Using JSON in Postgres by example.

Quick setup via Docker

  1. Download and install: Docker Toolbox
  2. Open Docker Quickstart Terminal
  3. Start a new postgres container:
    docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
@tianchaijz
tianchaijz / postgres-cheatsheet.md
Created March 15, 2018 03:14 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)

Postgres Cheatsheet

This is a collection of the most common commands I run while administering Postgres databases. The variables shown between the open and closed tags, "<" and ">", should be replaced with a name you choose. Postgres has multiple shortcut functions, starting with a forward slash, "". Any SQL command that is not a shortcut, must end with a semicolon, ";". You can use the keyboard UP and DOWN keys to scroll the history of previous commands you've run.

Setup

installation, Ubuntu

http://www.postgresql.org/download/linux/ubuntu/ https://help.ubuntu.com/community/PostgreSQL

@tianchaijz
tianchaijz / Makefile
Created May 19, 2017 02:15 — forked from kwk/Makefile
Compiling with Address Sanitizer (ASAN) with CLANG and with GCC-4.8
.PHONY: using-gcc using-gcc-static using-clang
using-gcc:
g++-4.8 -o main-gcc -lasan -O -g -fsanitize=address -fno-omit-frame-pointer main.cpp && \
ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=$(shell which llvm-symbolizer) ./main-gcc
using-gcc-static:
g++-4.8 -o main-gcc-static -static-libstdc++ -static-libasan -O -g -fsanitize=address -fno-omit-frame-pointer main.cpp && \
ASAN_OPTIONS=symbolize=1 ASAN_SYMBOLIZER_PATH=$(shell which llvm-symbolizer) ./main-gcc-static
@tianchaijz
tianchaijz / latency.txt
Created May 11, 2017 05:55 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
@tianchaijz
tianchaijz / gzstream.h
Created April 21, 2017 11:38 — forked from piti118/gzstream.h
Header-only version of gzstream
// ============================================================================
// gzstream, C++ iostream classes wrapping the zlib compression library.
// Copyright (C) 2001 Deepak Bandyopadhyay, Lutz Kettner
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
// License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful,
@tianchaijz
tianchaijz / 12306_cancel_zero_ticket.js
Created January 19, 2017 06:19 — forked from accelazh/12306_cancel_zero_ticket.js
When using "自动查询" + "自动提交" on 12306, frequently it pops out the auto commit window with zero ticket left. This is extremely distracting when trying to buy ticket for New Year Festival. Because You have to close the window, which waste your precious seconds, You cannot wait in peace for true tickets to come out, but have to be frequently disrupte…
function check_auto_buy() {
if (!$('#content_autosubmitcheckticketinfo').is(':visible')) {
// auto buy ticket window didn't show up
return false;
}
var all_zero = true;
$('#sy_ticket_num_id strong').each(function(i, val){
if (0 != $(val).text()) {
all_zero = false;
@tianchaijz
tianchaijz / autocheck.12306.js
Created January 19, 2017 06:07 — forked from anonymous/autocheck.12306.js
修复12306自动刷火车票中断的问题。
/*
* 使用方法:
* 1. 设置好自动查询
* 2. 打开控制栏
* windows下无论什么浏览器按快捷键F12
* Mac下按快捷键 Command + option + I
* */
function autoCheck(){
if($('#sear-result').width() || $('#qd_closeDefaultWarningWindowDialog_id').width()){
@tianchaijz
tianchaijz / tcpechod.cpp
Created November 30, 2016 11:48
tcpechod - Line oriented echo server with Linux epoll
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <clocale>
#include <cstring>
#include <cstdlib>
#include <csignal>
#include <ctime>
#include <cerrno>
@tianchaijz
tianchaijz / simple-vm.go
Created October 17, 2016 11:38 — forked from tomnomnom/simple-vm.go
Simple VM in Go
package main
import (
"fmt"
"log"
"strings"
)
// Ops
const (