Skip to content

Instantly share code, notes, and snippets.

View Ze1598's full-sized avatar

José Fernando Costa Ze1598

  • Porto, Portugal
View GitHub Profile
@Ze1598
Ze1598 / db_insertion.py
Last active July 22, 2020 21:06
psycopg2 tutorial: data insertion
from configparser import ConfigParser
import psycopg2
import psycopg2.extras as psql_extras
import pandas as pd
from typing import Dict
def load_connection_info(
ini_filename: str
) -> Dict[str, str]:
@Ze1598
Ze1598 / db_creation.py
Last active July 22, 2020 20:13
psycopg2 tutorial: database and table creation
from configparser import ConfigParser
import psycopg2
from typing import Dict
def load_connection_info(
ini_filename: str
) -> Dict[str, str]:
parser = ConfigParser()
parser.read(ini_filename)
@Ze1598
Ze1598 / unpivot_delimited_data_2.r
Last active July 14, 2020 13:58
Unpivot data with delimiters (R): count frequencies and plot
data_counts <- unpivot_wide_data %>%
group_by(`Used Social Networks`) %>%
summarize(Frequency = n())
# Order the data by descending order of the frequency
data_counts <- data_counts[
order(data_counts$Frequency, decreasing = TRUE)
,]
# Order the X axis by the current order of the values in the "Frequency" column
@Ze1598
Ze1598 / unpivot_delimited_data_1.r
Created July 14, 2020 12:04
Unpivot data with delimiters (R): split and unpivot
library(readr)
library(dplyr)
library(plotly)
library(tidyr)
library(stringr)
data <- read_csv("sample_data.csv")
max_split_cols <- max(mapply(str_count, data$`Used Social Networks`, ";"), na.rm = TRUE) + 1
@Ze1598
Ze1598 / unpivot_delimited_data.r
Last active July 14, 2020 12:04
Unpivot data with delimiters (R): complete script
library(readr)
library(dplyr)
library(plotly)
library(tidyr)
library(stringr)
data <- read_csv("sample_data.csv")
# Split and unpivot
# --------------------------------------
@Ze1598
Ze1598 / quotespy_advanced.py
Last active June 1, 2020 19:23
quotespy: advanced usage example
import quotespy.tweet_graphics.tweet_graphics as t
import os
# List of `tweet_info` dictionaries
USERNAME = "José Fernando Costa"
USERTAG = "@soulsinporto"
tweets = [
{
"tweet_name": "compare_to_others_sometimes",
"user_name": USERNAME,
@Ze1598
Ze1598 / quotespy_gen_tweets.py
Created June 1, 2020 19:13
quotespy: gen_tweets example
import quotespy.tweet_graphics.tweet_graphics as t
t.gen_tweets("samples\\tweets.json", {}, default_settings_format="light")
@Ze1598
Ze1598 / tweets.json
Created June 1, 2020 19:10
quotespy: tweets.json sample
[
{
"tweet_name": "mistakes",
"user_name": "José Fernando Costa",
"user_tag": "@soulsinporto",
"user_pic": "",
"tweet_text": "Some mistakes and, dare I say, failures may lead to results you had never thought you could achieve."
},
{
@Ze1598
Ze1598 / quotespy_tweet_graphics_custom_settings.py
Created June 1, 2020 19:04
quotespy: basic quotespy.tweet_graphics usage with custom graphic settings
import quotespy.tweet_graphics.tweet_graphics as t
tweet_info = {
"tweet_name": "mistakes",
"user_name": "José Fernando Costa",
"user_tag": "@soulsinporto",
"user_pic": "",
"tweet_text": "Some mistakes and, dare I say, failures may lead to results you had never thought you could achieve."
}
graphic_settings = {
@Ze1598
Ze1598 / quotespy_tweet_graphics_basic.py
Created June 1, 2020 18:59
quotespy: tweet_graphics basic usage
import quotespy.tweet_graphics.tweet_graphics as t
tweet_info = {
"tweet_name": "mistakes",
"user_name": "José Fernando Costa",
"user_tag": "@soulsinporto",
"user_pic": "samples\\user_photo.png",
"tweet_text": "Some mistakes and, dare I say, failures may lead to results you had never thought you could achieve."
}