Skip to content

Instantly share code, notes, and snippets.

@tenthree
tenthree / alter_table_column_to_serial.sql
Created December 30, 2019 07:18
alter an exist column to serial (auto increment)
-- PSQL
CREATE SEQUENCE {tableName}_{tableColumn}_seq;
ALTER SEQUENCE {tableName}_{tableColumn}_seq OWNED BY {tableName}.{tableColumn};
ALTER TABLE {tableName}
ALTER COLUMN {tableColumn} SET DEFAULT nextval('{tableName}_{tableColumn}_seq'::regclass);
@tenthree
tenthree / .air.conf
Created December 19, 2019 06:39
air configuration, a live reload tool for go development
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
# Working directory
# . or absolute path, please note that the directories following must be under root
root = "."
# Optional! If `watch_dir` is empty, use `root`.
watch_dir = ""
tmp_dir = "tmp"
[build]
@tenthree
tenthree / csv2json.js
Last active December 13, 2019 09:49
convert simple csv formatted data to json
const fs = require('fs')
const NUM_EXP = /^(\+|-)?(\d+)(\.\d+)?$/
const PERCENT_EXP = /^(\+|-)?(\d+)(\.\d+)?%$/
const CSV_COLUMN_EXP = /^"(.*)"$/g
const NULL_VALUES = [ '' ]
const CSV_OPTIONS = {
flip: false,
@tenthree
tenthree / supportsPassive.js
Created September 12, 2019 10:45
detect passive event listener in browser
export let supportsPassive = false
if (typeof window !== 'undefined') {
supportsPassive = false
try {
var options = Object.defineProperty({}, 'passive', {
get () {
supportsPassive = true
},
})
@tenthree
tenthree / taiwan.topo.json
Created August 14, 2019 09:50
twaiwan topojson
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@tenthree
tenthree / .browserslistrc
Created July 23, 2019 09:35
browserlist config sample
> 1%
last 5 versions
not ie <= 8
@tenthree
tenthree / backup.js
Created June 24, 2019 08:27
project backup script
const fs = require('fs')
const path = require('path')
const ora = require('ora')
const chalk = require('chalk')
const mkdirp = require('mkdirp')
const globby = require('globby')
const archiver = require('archiver')
const clear = require('clear')
const pkg = require('./package.json')
@tenthree
tenthree / fake-images.js
Created June 24, 2019 08:22
fake-images middleware for local development
module.exports = function () {
//
// [ express middleware ]
// Generate a /fake/images route for testing images source
//
// images service origin:
// - PICSUM(https://picsum.photos)
// Created by David Marby & Nijiko Yonskai
// Having trouble? Poke @DMarby on Twitter
// Images from unsplash
@tenthree
tenthree / PhotoCompared.vue
Last active May 28, 2019 17:14
Vue.js PhotoCompared component
<template>
<div class="photo-compared" :class="className" @mousedown="onPointDown" @touchstart="onPointDown">
<div class="photo-compared__frame" :style="frameStyle"></div>
<div class="photo-compared__before" :style="beforeStyle"></div>
<div class="photo-compared__after" :style="afterStyle"></div>
<div class="photo-compared__handler" :style="handlerStyle"></div>
</div>
</template>
<script>
@tenthree
tenthree / hi.go
Created September 11, 2018 08:57
radio stream generator in go
package hi
import (
"crypto/md5"
"encoding/base64"
"encoding/json"
"fmt"
"io/ioutil"
"net/http"
"strconv"