Skip to content

Instantly share code, notes, and snippets.

View chinying's full-sized avatar
🙃

Seah Chin Ying chinying

🙃
View GitHub Profile
@chinying
chinying / postgres-best-practices.md
Created November 9, 2021 09:48 — forked from kyledcline/postgres-best-practices.md
Postgres Best Practices

PSQL CLI Client

Psql is a fully-fledged CLI client for Postgres, but most people are unaware of its many advanced features.

~/.psqlrc can be edited to persist any behavior or configuration settings you want between psql sessions. It behaves just like ~/.bashrc or ~/.vimrc, sourced at psql launch. See More out of psql for some interesting configurations.

If you have a long query to write and rewrite, you can use \e to edit your query in an editor.

Use \watch at the end of a query in order to automatically re-run the query every few seconds - great for monitoring while making changes elsewhere in your application architecture.

require "json"
hashes = Hash(String, FlattenedCountry).new
class CountryName
JSON.mapping(
common: String,
official: String
)
end
require "jwt"
require "json"
LOCATION_SG = Time::Location.load("Asia/Singapore")
# eg. 2019-11-21T08:24:24.702Z
VAULT_TIMESTAMP_FORMAT = "%Y-%m-%dT%H:%M:%S.%LZ"
alias SampleIdWithTimestamp = {Int32, String}
def get_file_lines(filename)
arr = Array(String).new
import csv
import random
def randTime(size=500):
timings = [700, 730, 800, 830, 900]
return (random.choices(timings, k=size))
def generate(contents, size=500):
r = [contents[(random.randint(0, len(contents)))]
for i in range(size * 2)]
@chinying
chinying / convert.py
Last active June 25, 2018 07:00
xy to latlng
from pyproj import Proj, transform
inProj = Proj(init='epsg:3414')
outProj = Proj(init='epsg:4326')
def swap(x, y):
return y, x
def xy_to_latlng(x, y):
return swap(*transform(inProj, outProj, x, y))
@chinying
chinying / tree.py
Created March 15, 2017 19:58
scrub level tree traversal stuff, for checking purposes mostly
def inOrder(self, node):
if (node.left):
self.inOrder(node.left)
print(node)
if (node.right):
self.inOrder(node.right)
def normalize(a : Array[Double]) : Array[Double] = {
a.map(v => v/math.sqrt(a.map(x => x*x).reduce(_ + _)))
}
def net(t1: Array[Double], t2: Array[Double]) : Double = {
t1.zip(t2).map(x => x._1 * x._2).reduce(_ + _)
}
@chinying
chinying / ppt.workflow
Created December 5, 2016 11:19
ppt to pdf automator
-- not my code, found on http://apple.stackexchange.com/a/217029
on run {input, parameters}
set theOutput to {}
tell application "Microsoft PowerPoint" -- work on version 15.15 or newer
launch
set theDial to start up dialog
set start up dialog to false
repeat with i in input
open i
set pdfPath to my makeNewPath(i)

Keybase proof

I hereby claim:

  • I am chinying on github.
  • I am chinying (https://keybase.io/chinying) on keybase.
  • I have a public key ASDMWiUE1DQYp_BvwzkTRS7rOusW3bcrcEa1FlxI0sYWlgo

To claim this, I am signing this object:

@chinying
chinying / java_params.py
Created October 21, 2016 01:10
because i hate using java IDEs for web, so here's something for when using sublime. largely WIP
from collections import defaultdict
filepath = ""
classname = ""
fo = open(filepath)
contents = fo.read().split("\n")
def find_constructors(contents):
contd = False # continue looking
tmp_constructor = ""
constructors, idxs = [], []