Skip to content

Instantly share code, notes, and snippets.

@c-l-nguyen
c-l-nguyen / data-melt.py
Last active January 17, 2021 17:16
Melt pandas DataFrame from wide, fat format to long, skinny format
import pandas as pd
df = pd.read_csv("Global Temperature Anomalies.csv")
print(df.columns)
# parameter values
id_vars = ['Hemisphere', 'Year']
cols_to_pivot = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'J-D', 'D-N', 'DJF', 'MAM', 'JJA',
'SON']
@c-l-nguyen
c-l-nguyen / up-in-the-airbnb-stopwords.py
Last active January 23, 2020 05:06
stopwords used for wordcloud
# define stopwords to remove in word cloud
# some of these words were not useful in describing an area
# others were just so obvious that they appeared too much to be useful
stopwords = set(STOPWORDS)
unigram_stopwords = ["clean", "nice", "perfect", "austin", "great", "place", "stay", "definitely",
"would", "host", "house", "location", "home", "beautiful", "highly", "recommend",
"comfortable", "space", "would", "us", "everything", "'s", "bed", "amazing",
"room", "apartment", "ing", "really", "loved", "wonderful", "good", "needed",
"time", "thank", "need", "ed"]
@c-l-nguyen
c-l-nguyen / clean_git_repo.sh
Created February 1, 2020 23:25
clean large repo
# find top 10 largest files
git rev-list --objects --all | grep -f <(git verify-pack -v .git/objects/pack/*.idx| sort -k 3 -n | cut -f 1 -d " " | tail -10)
# clean repo
git filter-branch --index-filter 'git rm --cached --ignore-unmatch *.mov' -- --all
rm -Rf .git/refs/original
rm -Rf .git/logs/
git gc --aggressive --prune=now
# push changes
@c-l-nguyen
c-l-nguyen / init.lua
Last active February 28, 2021 10:55
Hammerspoon virtual numpad for macOS
k = hs.hotkey.modal.new('ctrl-shift', 'n')
function k:entered() hs.alert'Virtual Numpad' end
function k:exited() hs.alert'Exit Virtual Numpad' end
k:bind('ctrl-shift', 'n', function() k:exit() end)
hs.fnutils.each({
{ key='j', padkey='pad1'},
{ key='k', padkey='pad2'},
{ key='l', padkey='pad3'},
{ key='u', padkey='pad4'},
@c-l-nguyen
c-l-nguyen / macOS_commands.sh
Created February 20, 2020 19:21
Various macOS shell commands collection
#### macOS startup chime
# 1. Enter macOS Recovery
# 2. Launch Terminal
# 3. Copy paste this command and press ENTER: nvram StartupMute=%00
# 4. Reboot
# Note that you must unmute your Mac in macOS to hear the chime.
#### To fix Messages not staying open
defaults write -g NSDisableAutomaticTermination -bool yes
@c-l-nguyen
c-l-nguyen / mac_oracle.md
Last active March 31, 2020 16:14
Set up Oracle client on Mac
1. Download basic instant client (and maybe the SQL*Plus package) at
https://www.oracle.com/database/technologies/instant-client/macos-intel-x86-downloads.html#ic_osx_inst
2. Unzip downloads
3. Mostly follow this tutorial: https://www.talkapex.com/2013/03/oracle-instant-client-on-mac-os-x/
	a. But create an /oracle folder in /usr/local folder instead
	b. Move the unzipped folders to /usr/local/oracle
	c. Put lines in .zshrc file if on macOS Catalina and set zsh as default shell
4. Get the tnsnames.ora file (and maybe the sqlnet.ora file) and move to
/usr/local/oracle/instantclient_19_3/network/admin
5. Go into Datagrip and set up an Oracle connection
import pandas as pd
import pantab
from tableauhyperapi import TableName
df = pd.read_csv("data/starter_pokemon_grass.csv")
# save DataFrame output to .hyper file
pantab.frame_to_hyper(df, "hyper/pokemon_public.hyper", table = "pokemon")
# save to schema other than public
print(pantab.frames_from_hyper("hyper/pokemon_public.hyper").keys())
# dict_keys([TableName('public', 'pokemon')])
print(pantab.frames_from_hyper("hyper/pokemon_extract.hyper").keys())
# dict_keys([TableName('Extract', 'pokemon')])
# this errors out with message "HyperException: Specified table does not exist: pokemon."
pantab.frame_from_hyper("hyper/pokemon_extract.hyper", table = "pokemon")
# need to specify schema to read table from
pantab.frame_from_hyper("hyper/pokemon_extract.hyper", table = TableName("Extract", "pokemon"))
# these two are equivalent
pantab.frame_from_hyper("hyper/pokemon_public.hyper", table = "pokemon")
pantab.frame_from_hyper("hyper/pokemon_public.hyper", table = TableName("public", "pokemon"))