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 / js_spirit2.cpp
Created July 20, 2018 17:32 — forked from jefftrull/js_spirit2.cpp
Attempted solution to "Boost Spirit vs. Flex/Bison" comparison
// Attempt at making a Boost grammar that successfully parses Jason Shankel's predicate logic language
// #define BOOST_SPIRIT_DEBUG
#include <boost/spirit/include/qi.hpp>
#include <boost/variant/recursive_variant.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/include/phoenix.hpp>
#include <boost/optional.hpp>
// start with the AST
@tianchaijz
tianchaijz / linalg.c
Created July 18, 2018 02:03 — forked from cloudwu/linalg.c
A linear algebra lua library
// C module for data stack manager
// See below for lua lib wrapper
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#define MINCAP 128
local account = "[email protected]" -- use your own gmail account
local password = "password" -- if you enable 2-phase authentication, you need to
-- generate and use a application-specific password here...
local sender_name = "Jon Snow"
local recipient = "[email protected]"
local recipient_name = "Arya Stark"
local mail_title = "This is a test mail"
local mail_body = [[<html><body><p>Mail Body...</body></html>]]
@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
local cjson = require "cjson.safe"
local js = require "lib.resty.jsonschema/compiler"
local g = js.new({type={"integer", "boolean"}})
-- print(g:code())
local g = js.new({enum = {"a", "b", cjson.null, "d"}})
-- print(g:code())
@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 / range.py
Created October 15, 2017 13:34
Range file
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
def gen_byte(path):
with open(path) as fd:
while True:
buf = fd.read(4096)
@tianchaijz
tianchaijz / ringbuffer.lua
Last active August 30, 2017 03:35
ring buffer
local pcall = pcall
local setmetatable = setmetatable
local ok, table_new = pcall(require, "table.new")
if not ok then
table_new = function(narr, nrec) return {} end
end
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include "zlib.h"
int gzip_compress(uint8_t *src, size_t srclen, uint8_t *dest, size_t *destlen,
int level) {
int rc, wbits, memlevel;
z_stream zstream;