Skip to content

Instantly share code, notes, and snippets.

@pirey
pirey / arch-pacstrap.md
Last active August 23, 2020 04:04
personal note for arch linux installation guide
@pirey
pirey / select_all_count.sql
Created August 24, 2019 16:49
select row count for all tables in postgresql
SELECT schemaname,relname,n_live_tup
FROM pg_stat_user_tables
ORDER BY n_live_tup DESC;
@pirey
pirey / git-intro.md
Last active November 15, 2021 17:46
Yet another introduction to git

Keep track of our works (man git)

Git is a command line application, meaning it's an application that we run in the terminal / command prompt.

The purpose of git is to keep track of our works. As a programmer, what we usually do at work is write code. With git, we can see what are the things that we added, edited, or removed from our project's source code.

By default, git doesn't just track everything we do to our source code. Therefore we need to tell git which changes we made to the source code that we want to keep track later, as we discuss later.

Get a repo (git init, clone)

@pirey
pirey / auxiliary.js
Created December 2, 2018 16:26
Collection of javascript helper functions
// convert FormData to Object
export const fd2obj = (fd) => Array.from(fd.entries()).reduce((acc, i) => Object.assign({}, acc, { [i[0]]: (acc[i[0]] || Array.isArray(acc[i[0]])) ? [].concat(acc[i[0]]).concat(i[1]) : i[1] }), {})
@pirey
pirey / withRefs.ts
Last active November 11, 2018 05:29
React HOC to handle refs
import { withStateHandlers } from 'recompose'
import { ReactNode } from 'react';
type Ref = ReactNode
type RefsState = {}
type RefsHandlers = {
setRef: (fieldName: string, ref: Ref) => undefined
focusRef: (fieldName: string) => undefined
}
export type RefsProps = RefsHandlers & RefsState
@pirey
pirey / countries.json
Last active October 8, 2018 05:45
list of country names and codes
[
{
"name": "Afghanistan",
"number": "93",
"code": "AF"
},
{
"name": "Albania",
"number": "355",
"code": "AL"
@pirey
pirey / file-input.jsx
Last active October 27, 2023 18:09
react file input, convert File to source url, useful to preview image before uploading
import {readFileAsUrl} from './readFileAsUrl'
class Example extends React.Component {
constructor() {
this.state = {
previewUrl: ''
}
}
render() {
return (
/*
* convert ojbect into query params format
* used for request with content-type application/x-www-form-urlencoded
*
* e.g
* { param: "someVal", param2: "otherVal" }
*
* is converted into
*
* param1=someVal&param2=otherVal
@pirey
pirey / .zshrc
Created August 9, 2018 17:36
copy of my personal .zshrc
# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load. Optionally, if you set this to "random"
# it'll load a random theme each time that oh-my-zsh is loaded.
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
ZSH_THEME="robbyrussell"
const capitalize = (s) => s.toLowerCase().split(' ').map((w) => w.replace(/^\w/, (s) => s.toUpperCase())).join(' ')