Skip to content

Instantly share code, notes, and snippets.

View monkeycycle's full-sized avatar

Michael Pereira monkeycycle

View GitHub Profile
@monkeycycle
monkeycycle / gist:20655e4c4cfe1285fc1e6f3e296bc159
Created December 12, 2017 16:36 — forked from ahamez/flightradar24.py
Read data from flightradar24
#! /usr/bin/env python
import json
import time
import shelve
import urllib
import urllib.request
DB = 'flights'
API = "http://www.flightradar24.com/zones/full_all.json"
@monkeycycle
monkeycycle / package.json
Created January 28, 2018 20:50
NPM build pipeline
{
"name": "npm builder",
"version": "1.0.0",
"description": "A basic npm build pipeline.",
"main": "index.html",
"author": "",
"license": "ISC",
"dependencies": {
"bourbon": "4.3.4",
"bourbon-neat": "2.0.0",
@monkeycycle
monkeycycle / r-markdown-heads.R
Created May 16, 2018 17:09
Print markdown within r notebook code chunks
# Needs `, results='asis'` and two spaces before the trailing newline
```{r occupations_by_vismin.R, echo=TRUE, message=FALSE, warning=FALSE, results='asis'}
for(thing in list_of_things){
cat("\n###", thing, "\n")
cat(" \n")
}
```
After editing .gitignore to match the ignored files, you can do git ls-files -ci --exclude-standard to see the files that are included in the exclude lists; you can then do git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached to remove them from the repository (without deleting them from disk).
Edit: You can also add this as an alias in your .gitconfig file so you can run it anytime you like. Just add the following line under the [alias] section:
apply-gitignore = !git ls-files -ci --exclude-standard -z | xargs -0r git rm --cached
(The -r flag in xargs prevents git rm from running on an empty result and printing out its usage message.)
Now you can just type git apply-gitignore in your repo, and it'll do the work for you!
@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)
}
@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'
##################################################
# 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 / 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
@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")
# OSX Finder junk
.DS_Store
# environment variables incl. credentials
.env
# python virtual environments
.venv
venv