Skip to content

Instantly share code, notes, and snippets.

View paulochf's full-sized avatar
⌨️

Paulo Haddad paulochf

⌨️
View GitHub Profile
@paulochf
paulochf / jupyter.service
Created April 18, 2018 01:42
Jupyter Notebook as service in Ubuntu
# After Ubuntu 16.04, Systemd becomes the default.
# It is simpler than https://gist.github.com/Doowon/38910829898a6624ce4ed554f082c4dd
# https://gist.github.com/whophil/5a2eab328d2f8c16bb31c9ceaf23164f
# PUT THIS IN /usr/lib/systemd/system
[Unit]
Description=Jupyter Notebook
[Service]
Type=simple
@paulochf
paulochf / moar_pandas.py
Last active April 26, 2018 18:45
More rows/columns/width in pandas table printings without truncation
import pandas as pd
pd.set_option("display.max_rows", 200)
pd.set_option("display.max_columns", 100)
pd.set_option("display.max_colwidth", 200)
## Reset to defaults
# pd.reset_option("^display")
@paulochf
paulochf / pandas_set_operation.ipynb
Last active July 25, 2018 17:44
Set intersection between pandas columns
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paulochf
paulochf / get_slack_threads.ipynb
Last active July 30, 2018 16:26
Get starred threads dialogs from Slack
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@paulochf
paulochf / urldecode.sql
Created March 11, 2016 19:10
URL decode for MySQL
-- Found at http://stackoverflow.com/a/17922821/597349
DROP TABLE IF EXISTS urlcodemap;
CREATE TABLE `urlcodemap` (
`id` INT(11) NOT NULL AUTO_INCREMENT,
`encoded` VARCHAR(128) NOT NULL,
`decoded` VARCHAR(128) NOT NULL,
UNIQUE KEY urlcodemapUIdx1(encoded),
PRIMARY KEY (`id`)
@paulochf
paulochf / s3fs_profile.py
Created March 24, 2018 00:03
Use python s3fs to connect to AWS using specific profile (already in ~/.aws/)
from s3fs.core import S3FileSystem
s3 = S3FileSystem(anon=False, profile_name="your-profile-name")
print(s3.ls("s3://your-bucket/some-folder"))
@paulochf
paulochf / strsplit.sql
Created February 10, 2015 20:20
MySQL split function: get nth splitted term from string separated value
-- Retrieved from http://dev.mysql.com/doc/refman/5.6/en/string-functions.html at 2015-feb-10 18:16
-- Working on MySQL version 5.6.19-0ubuntu0.14.04.1 (Ubuntu)
--
-- Posted by Chris Stubben on August 21 2008 3:49pm
-- Split delimited strings
CREATE FUNCTION
strSplit(x VARCHAR(255), delim VARCHAR(12), pos INT) RETURNS VARCHAR(255)
return
REPLACE(SUBSTRING(SUBSTRING_INDEX(x, delim, pos),
@paulochf
paulochf / redshift_dim_date.sql
Created September 2, 2022 00:21
Date dimension view for Redshift
-- Heavily inspired by this StackOverflow thread
-- https://stackoverflow.com/questions/47230534/how-do-i-create-a-dates-table-in-redshift
-- and tired of bumping my head in the wall after getting the generate_series() error.
DROP VIEW IF EXISTS public.dim_date;
CREATE VIEW public.dim_date AS
WITH
digit AS (
SELECT
0 AS D
@paulochf
paulochf / ipython_notebook_large_width.py
Last active September 22, 2022 22:22
IPython/Jupyter Notebook enlarge/change cell width
from IPython.display import display, HTML
display(HTML(data="""
<style>
div#notebook-container { width: 95%; }
div#menubar-container { width: 65%; }
div#maintoolbar-container { width: 99%; }
</style>
"""))
@paulochf
paulochf / countries.sql
Last active April 26, 2024 09:50 — forked from adhipg/countries.sql
Outdated. Used with discretion. Accepting updates.
CREATE TABLE IF NOT EXISTS `country` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`iso` char(2) NOT NULL,
`name` varchar(80) NOT NULL,
`nicename` varchar(80) NOT NULL,
`iso3` char(3) DEFAULT NULL,
`numcode` smallint(6) DEFAULT NULL,
`phonecode` int(5) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;