Skip to content

Instantly share code, notes, and snippets.

View jjasont's full-sized avatar
🔍
on the pursuit of clean data

Jason Tan jjasont

🔍
on the pursuit of clean data
  • Singapore
View GitHub Profile
@jjasont
jjasont / baby_shark.py
Last active September 17, 2019 06:11
This gist is intended as a 'recreational' learning of understanding Python class inheritance via the nursery rhyme baby shark.
import re
class BabyShark:
def __init__(self):
self.generation = re.findall('[A-Z][^A-Z]*', self.__class__.__name__)[0]
self.entities = ' '.join(re.findall('[A-Z][^A-Z]*', self.__class__.__name__))
self.doo_line = ', '+ 4 * " Doo"
self.song_line = self.entities + self.doo_line
def swim(self):
print("{0!r} is swimming".format(str(self.entities)))
@jjasont
jjasont / collect_weather_data.py
Created December 20, 2018 15:30
Retrieve daily forecast weather data
# Import necessary package
import wget
import os
import json
from multiprocessing import Pool
import time
start_time = time.time()
# Initialize variable
root_store = '/content/gdrive/My Drive/Weather_Forecast_Data_Gathering/' # Change to local machine directory
@jjasont
jjasont / explode_array_in_pd_df.py
Last active January 7, 2020 09:22
Explode the array object in pandas DataFrame to multiple DataFrame record
# Reference:
# - https://stackoverflow.com/questions/32468402/how-to-explode-a-list-inside-a-dataframe-cell-into-separate-rows
# - Update 2019-07:
# https://github.com/pandas-dev/pandas/pull/27267
# https://stackoverflow.com/questions/53218931/how-to-unnest-explode-a-column-in-a-pandas-dataframe
# https://mikulskibartosz.name/how-to-split-a-list-inside-a-dataframe-cell-into-rows-in-pandas-9849d8ff2401
import pandas as pd
generic_dataframe = pd.read_csv("example.csv")
@jjasont
jjasont / README.md
Last active October 4, 2019 05:28 — forked from arikfr/README.md
Redash Query Export Tool

Setup

$ pip install click requests

Usage

$ python query_export.py --redash-url "https://app.redash.io/" --api-key ""
@jjasont
jjasont / Notes.md
Last active March 5, 2020 06:18
Superset API Endpoint

Superset API Endpoint List

Superset is based on Flask App Builder (FAB). Hence, certain model can be manipulated via Flask REST API. Further information about the API can be found in the official Flask App Builder documentation here

This noted was aspired from the Issue #4708

API Login

Login to API required before usages of any the API endpoint at /api/v1/security/login.

@jjasont
jjasont / Hexadecimal Checker.ipynb
Created December 30, 2019 02:04
Check for Hexadecimal
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jjasont
jjasont / gsheet_manipulation.py
Last active December 30, 2019 02:17
Programmatic Google Sheet Manipulation from Python
"""Direct Google Sheets Manipulation trial."""
from predictorcls import Predictor
from oauth2client.service_account import ServiceAccountCredentials
import gspread
# import time
# import random
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
@jjasont
jjasont / command.sh
Created January 16, 2020 03:10
Postgres Dump and Restore without Ownership
# To dump a database into a custom-format archive file
pg_dump -h <origin_postgres_host> \
-p <origin_port> \
-d <origin_postgres_db> \
-U <username_origin_postgres_rds_db> \
-W -Fc > <pg_dump_file>.psql
# To restore a database into a custom-format archive file with no owner:
pg_restore -h <target_postgres_host> \
-U <username_target_postgres_db> \
@jjasont
jjasont / convert.py
Last active February 13, 2020 03:12 — forked from rednebmas/convert.py
Convert sqlite3 dump to mysql importable statements (Python3) - To be Tested
import re, fileinput
print('SET FOREIGN_KEY_CHECKS=0;')
def main():
for line in fileinput.input():
process = False
for nope in ('BEGIN TRANSACTION','COMMIT',
'sqlite_sequence','CREATE UNIQUE INDEX'):
if nope in line: break
# Detect Lock
select a.txn_owner, a.txn_db, a.xid, a.pid, a.txn_start, a.lock_mode, a.relation as table_id,nvl(trim(c."name"),d.relname) as tablename, a.granted,b.pid as blocking_pid ,datediff(s,a.txn_start,getdate())/86400||' days '||datediff(s,a.txn_start,getdate())%86400/3600||' hrs '||datediff(s,a.txn_start,getdate())%3600/60||' mins '||datediff(s,a.txn_start,getdate())%60||' secs' as txn_duration
from svv_transactions a
left join (select pid,relation,granted from pg_locks group by 1,2,3) b
on a.relation=b.relation and a.granted='f' and b.granted='t'
left join (select * from stv_tbl_perm where slice=0) c
on a.relation=c.id
left join pg_class d on a.relation=d.oid
where a.relation is not null AND a.txn_owner='<db_username>';