Skip to content

Instantly share code, notes, and snippets.

View razhangwei's full-sized avatar

Wei Zhang razhangwei

  • Facebook
  • Bay Area
View GitHub Profile
@razhangwei
razhangwei / tee.sh
Last active May 9, 2019 14:15
save std output to local log file named with current datetime #Unix
# IDs: 1 for stdout, 2 for stderr -2>&1: redirect stderr to stdout; vice versa for 1>&2.
./some_command 2>&1 | tee $(date +"%Y%m%d%H%M").log
@razhangwei
razhangwei / insert_datetime.md
Last active April 19, 2022 19:59
Inserting Date & Time on MacOS #Mac #Automator
  1. Open Automator and create Quick Action.
  2. In the middle column, look for Run AppleScript
  3. On the right, choose no input for workflow receives
  4. input
on run {input, parameters}
    set dateString to do shell script "date +'(%m/%d/%y %H:%M %p)'"
    tell application "System Events"
    	keystroke dateString
 end tell
@razhangwei
razhangwei / .vimrc
Last active May 21, 2019 22:00
vim config file #Vim #Unix
" vundle initialization
" avoid modify this section, unless you are very sure of what you are doing
" no vi-compatible
set nocompatible
filetype off " required! for Vundle
" setting up vundle - the vim plugin bundler
let icanhazvundle=1
let vundle_readme=expand('~/.vim/bundle/vundle/README.md')
@razhangwei
razhangwei / printer.md
Last active May 15, 2019 17:12
Change printer default config on macOS #Mac
  1. In terminal, run cupsctl WebInterface=yes
  2. In a web browser, open
@razhangwei
razhangwei / presto.md
Last active October 12, 2024 00:13
Presto cheatsheet #Presto #SQL

Table/partition management

  • drop table: drop table table_name
  • rename: ALTER TABLE old_table RENAME TO new_table
  • delete certain partitions: delete from shop_mall_post_attributes where ds <= '2020-06-14';
  • insert rows: INSERT INTO table_name QUERY

Important Topics

  • UDFs
@razhangwei
razhangwei / key_repeat.md
Last active April 25, 2020 00:07
Enable Key Repeating in #macOS
  1. First, adjust Key Repeat and Delay Until Repeat in Keyboard setting.
  2. Disable press and hold.
defaults write -g ApplePressAndHoldEnabled -bool false
@razhangwei
razhangwei / ssh_key.md
Last active May 24, 2024 06:51
ssh key-based authorization
  1. On PC, Generate ssh key: ssh-keygen -t rsa -b 4096
  2. Add public keys to the server (recommend using ssh-copy-id)
ssh-copy-id -i .ssh/id_rsa user@hostname
@razhangwei
razhangwei / hive.md
Last active February 5, 2021 21:19
Hive / Spark SQL

Useful udf:

  • Use Daiquery 'interactive spark' to debug the query first.
  • HiveInsertOperatorWithSchema does not support CTE in select query; need to put it in preselect
  • empty map with types: FB_CAST(NULL, 'MAP<INT, ARRAY<DOUBLE>>')
  • array: FB_ARRAY_APPLY, FB_ARRAY_AGGREGATE, FB_ARRAY_GET, FB_ARRAY_SORT,
  • FB_PREV
  • aggregate: FB_COLLECT
  • sample:

DISTRIBUTE BY

@razhangwei
razhangwei / snippets.cson
Created June 5, 2019 23:23
atom snippets
'.source.python':
'import numpy':
'prefix': 'as np'
'body': 'import numpy as np'
'import pandas':
'prefix': 'as pd'
'body': 'import pandas as pd'
'import matplotlib.pylot':
'prefix': 'as plt'
@razhangwei
razhangwei / ps.sh
Created June 19, 2019 22:57
Wall clock time of a running process #Unix
PID=xxx
ps -p $PID -o etime