Skip to content

Instantly share code, notes, and snippets.

View twedl's full-sized avatar
💭
🦕

twedl twedl

💭
🦕
View GitHub Profile
@twedl
twedl / main.rs
Created September 26, 2021 17:15
Simple rust program to read lines of a short file
/*
run `cargo new your-project-name` in terminal
this is src/main.rs
input.txt is in the root dir of your-project-name
*/
use std::fs;
fn main() {
# Get 2016 Census data on major field of study by sex
library(tidyverse)
library(janitor)
census_url <- "https://www12.statcan.gc.ca/census-recensement/2016/dp-pd/dt-td/CompDataDownload.cfm?LANG=E&PID=110456&OFT=CSV"
# wherever works for you; this is good for MacOS
destination_file <- "~/Downloads/census_education.zip"
@twedl
twedl / download_world_trade_db.R
Created August 29, 2016 11:48
Download World Trade Database (R)
# Download the World Trade Database from http://cid.econ.ucdavis.edu/ucdstats.html
# From documentation: value is in thousands of current USD.
library(reshape2)
library(dplyr)
library(readr)
process_file <- function(f_name) {
# returns unzipped file.
# create tempfile to remove later.
tf <- tempfile(pattern="wtdb",fileext="zip")
# base. not even sure why or how this works.
temp=as.data.frame(as.matrix(unlist(by(asm$g,asm[,"year"],
FUN=quantile, prob=.025))))
colnames(temp)[1]="q2.5" # wut.
temp$year=rownames(temp) # wut.
asm=merge(asm,temp,by="year") # and slooow.
# dplyr. ez.
low = asm %>%
group_by(year) %>%
@twedl
twedl / README.md
Last active May 23, 2016 13:49
Production network example
  • Production network example.
@twedl
twedl / README.md
Last active April 10, 2016 17:32
Letter gravity

First attempt at the d3 force layout grammar heading words letters style.

@twedl
twedl / README.md
Last active April 10, 2016 10:34
Click to Display Flow

Add a flow info

@twedl
twedl / README.md
Last active April 26, 2016 12:02
Canadian Trade Map (Leaflet Version)

(Please click this link to open in new window.) Testing Bostock's leaflet.js tutorial, adding relevant Canadian stuff for the project.

@twedl
twedl / README.md
Last active April 26, 2016 11:59
Canadian Trade Map (Bundled Edges)

Map with bundled trade flows.

@twedl
twedl / README.md
Last active April 25, 2016 01:37
Canadian Trade Map (Choropleth)

Choropleth Map