Skip to content

Instantly share code, notes, and snippets.

View trietphm's full-sized avatar
🍄
1 Up

Triet Pham trietphm

🍄
1 Up
View GitHub Profile
case get_format(conn) do
"json" ->
cond do
kind == :error ->
case reason.__struct__ do
Ecto.NoResultsError ->
error_view = "404.json"
App.Utils.Error.NotFound ->
error_view = "404.json"
{
"env": {
"GOPATH": "/home/windyzboy/project/go",
"GOROOT": "/usr/local/go"
},
"on_save":
[{
"cmd": "gs9o_open", "args": {
"run": ["clear"],
"focus_view": false
package views
import (
"encoding/json"
"time"
)
type Timestamp time.Time
func (t Timestamp) MarshalJSON() ([]byte, error) {
@trietphm
trietphm / indent_json_console.go
Created April 24, 2016 06:32
Log a json struct golang with indent in console
package main
import (
"encoding/json"
"fmt"
"os"
)
func main() {
type ColorGroup struct {
CREATE TABLE public.data_samples (
id serial PRIMARY KEY,
date_recruited timestamp NULL,
gender text NULL,
age int4 NULL,
province_normalize text NULL,
province text NULL,
country text NULL
);
WITH new_users AS (
SELECT DISTINCT ON (user_id) user_id, created_at
FROM purchases
ORDER BY user_id ASC, created_at ASC
), old_users AS (
SELECT DISTINCT ON (user_id) user_id, created_at
FROM purchases AS pc
WHERE exists (
SELECT 1 FROM purchases
WHERE date_trunc('month', created_at) < date_trunc('month', pc.created_at)
@trietphm
trietphm / date_generate.sql
Last active October 3, 2017 07:11
Generate date in range
WITH time_range AS (
select generate_series('2015-12-31 00:00:00', '2016-12-31 00:00:00', '1 day'::interval) AS day_d
),
select generate_series(CAST((NOW() + INTERVAL '-30 day') AS date), CAST((NOW() + INTERVAL '-0 day') AS date), '1 day'::interval) AS day_d
@trietphm
trietphm / freeswap.sh
Created June 11, 2017 17:24
Free swap to RAM
#!/bin/bash
free_data="$(free)"
mem_data="$(echo "$free_data" | grep 'Mem:')"
free_mem="$(echo "$mem_data" | awk '{print $4}')"
buffers="$(echo "$mem_data" | awk '{print $6}')"
cache="$(echo "$mem_data" | awk '{print $7}')"
total_free=$((free_mem + buffers + cache))
used_swap="$(echo "$free_data" | grep 'Swap:' | awk '{print $3}')"

Keybase proof

I hereby claim:

  • I am trietphm on github.
  • I am triet (https://keybase.io/triet) on keybase.
  • I have a public key whose fingerprint is FFF9 2B49 5B67 2716 D4D6 60F7 186B F1D1 8966 6477

To claim this, I am signing this object:

@trietphm
trietphm / blokada-xiaomi-blocklist
Created March 3, 2019 15:54
Blokada Xiaomi Blocklist
0.0.0.0 a.stat.xiaomi.com
0.0.0.0 abtest.mistat.intl.xiaomi.com
0.0.0.0 abtest.mistat.xiaomi.com
0.0.0.0 ad.mi.com
0.0.0.0 ad.xiaomi.com
0.0.0.0 ad1.xiaomi.com
0.0.0.0 adv.sec.miui.com
0.0.0.0 api.account.xiaomi.com
0.0.0.0 api.ad.xiaomi.com
0.0.0.0 api.admob.xiaomi.com