Skip to content

Instantly share code, notes, and snippets.

@c-l-nguyen
c-l-nguyen / employee_dept_icicle.csv
Created June 6, 2021 19:32
Data for icicle chart
ID Label Level Level ID Value
1 A HR 1 20
1 B IT 1 30
1 C Sales 1 15
1 D Finance 1 35
2 A1 HR 2 10
3 A2 HR 2 5
4 A3 HR 2 5
2 B1 IT 2 15
3 B2 IT 2 15
# append all DataFrames into one before writing to single table in Hyper
final_df = df1.append(df2).append(df3).reset_index(drop=True)
pantab.frames_to_hyper({"pokemon": final_df}, "hyper/all_pokemon_in_one.hyper")
# this produces the same result as above
pantab.frame_to_hyper(df1, "hyper/all_pokemon_append.hyper", table = "pokemon")
pantab.frame_to_hyper(df2, "hyper/all_pokemon_append.hyper", table = "pokemon", table_mode = "a")
pantab.frame_to_hyper(df3, "hyper/all_pokemon_append.hyper", table = "pokemon", table_mode = "a")
df1 = pd.read_csv("data/starter_pokemon_grass.csv")
df2 = pd.read_csv("data/starter_pokemon_fire.csv")
df3 = pd.read_csv("data/starter_pokemon_water.csv")
dict_df = {"grass": df1, "fire": df2, "water": df3}
pantab.frames_to_hyper(dict_df, "hyper/all_pokemon_separate.hyper")
import csv
from tableauhyperapi import HyperProcess, Telemetry, Connection, CreateMode, NOT_NULLABLE, NULLABLE, SqlType, \
TableDefinition, Inserter, escape_name, escape_string_literal, HyperException, TableName
with HyperProcess(telemetry=Telemetry.DO_NOT_SEND_USAGE_DATA_TO_TABLEAU) as hyper:
print("starting up Hyper Process")
with Connection(hyper.endpoint, 'hyper/pokemon_hyper_api.hyper', CreateMode.CREATE_AND_REPLACE) as connection:
print("creating or replacing pokemon_hyper_api.hyper")
poke_table = TableDefinition(TableName('public','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"))
# 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"))
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')])
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
@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
@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