Skip to content

Instantly share code, notes, and snippets.

View monkeycycle's full-sized avatar

Michael Pereira monkeycycle

View GitHub Profile
@monkeycycle
monkeycycle / r_libraries
Created September 15, 2023 16:03
R install and load necessary packages
# List of packages for session
package_list = c('devtools',
'here',
'tidyverse',
'janitor',
'magrittr',
'parsedate')
# Install CRAN packages (if not already installed)
@monkeycycle
monkeycycle / gist:0ab928bab4c354b44ee17e99a4c414f7
Last active January 10, 2020 05:46
Current node version to .nvmrc
node -v > .nvmrc
@monkeycycle
monkeycycle / generate_df_plots.R
Created January 9, 2020 04:05
R loop to generate dataframes and corresponding plots -- dirty but useful
# This loop generates a dataframe and plot for each offence
for(offence in cc_code_offences.l){
offence_slug <- slugify::slugify(offence, alphanum_replace = "", space_replace = "_", tolower = TRUE)
offence_slug <- gsub("__", "_", offence_slug, fixed=TRUE)
df_name <- paste(offence_slug, ".df", sep = "")
plot_name <- paste("p_", offence_slug, sep = "")
tmp.df <- filter_cc_offence(df=ywg_monthly_crime_data_2008_2019,
@monkeycycle
monkeycycle / .block
Created December 2, 2019 01:35 — forked from mbostock/.block
California Population Density II
license: gpl-3.0
height: 1100
border: no
# OSX Finder junk
.DS_Store
# environment variables incl. credentials
.env
# python virtual environments
.venv
venv
@monkeycycle
monkeycycle / change_timezone.R
Created March 14, 2019 20:46
R: change timezone
eth302_takeoff$time <- as.POSIXct(eth302_takeoff$time, format = "%Y-%m-%d %H:%M:%S", tz="GMT")
eth302_takeoff$time_EAT = with_tz(eth302_takeoff$time, tzone = "Africa/Addis_Ababa")
@monkeycycle
monkeycycle / gist:a0e87657cdbfa2c85d39dc36f28bf28a
Created November 19, 2018 01:26
gitignore for R projects
# History files
.Rhistory
.Rapp.history
# Session Data files
.RData
# Example code in package build process
*-Ex.R
##################################################
# Get sunrise, sunset and dusk times for a location
##################################################
days <- seq(from = as.POSIXct("2017-01-01"), to = as.POSIXct("2017-12-31"), by = "days")
# coordinates for Toronto
lat <- 43.6532
lon <- -79.3832
coord <- matrix(c(lon, lat), nrow = 1)
@monkeycycle
monkeycycle / sunrise-scraper.py
Created July 3, 2018 20:06
Sunrise Sunset Scraper
import requests
from bs4 import BeautifulSoup
import csv
from datetime import datetime
file_out = 'sunrise_sunset_toronto.csv'
base_url = 'https://www.timeanddate.com/sun/canada/toronto?month=5&year=2018'
base_city = 'toronto'
base_year = '2017'
root_el_id = 'as-monthsun'
@monkeycycle
monkeycycle / utils.R
Created May 30, 2018 09:48
Assorted R utilities
# Load required packages
load_requirements <- function(pkg){
new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if (length(new.pkg))
install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}