Skip to content

Instantly share code, notes, and snippets.

#data from http://www.modestinsights.com/analyzing-the-billboard-hot-100/ 'Instead I’ve uploaded all the raw data here, in PSV format '
#library used is ggjoy from https://github.com/clauswilke/ggjoy
data<-read.csv("all_billboard_data.csv", header=TRUE, sep="\t")#this is the psv where ive swapped \| for \t. I probably didnt need to.
library(lubridate)
library(devtools)
install_github("clauswilke/ggjoy")
library(ggplot2)
library(ggjoy)
#Code is a copy of 'It brings me ggjoy' http://austinwehrwein.com/data-visualization/it-brings-me-ggjoy/
#Data from met.ie http://www.met.ie/climate-request/
dublin.raw<-read.csv('dublinairportNoHead.csv', sep=',', header=TRUE)
head(dublin.raw)
library(lubridate)
library(dplyr)
library(ggjoy)
library(ggplot2)
oxford<-read.csv('oxforddata.csv', sep=',', header=TRUE)
options(digits=2)
oxford$min <- as.numeric(as.character(oxford$tmin))
oxford$tmax <- as.numeric(oxford$tmax)
oxford <- oxford %>% mutate(average = (tmax+min)/2)
mins<-min(oxford$average)
maxs<-max(oxford$average)
oxford <- oxford %>% mutate(month =month.abb[mm])
oxford$months<-factor(rev(oxford$month),levels=rev(unique(oxford$month)))
setwd("/Users/davidcurran/Documents/monthlyEngland")
readLines("cetml1659on.dat",
n=10)
#Start of borrowed bit
## from https://gist.github.com/gavinsimpson/b52f6d375f57d539818b
CET <- url("http://www.metoffice.gov.uk/hadobs/hadcet/cetml1659on.dat")
cet <- read.table("cetml1659on.dat", sep = "", skip = 6, header = TRUE,
fill = TRUE, na.string = c(-99.99, -99.9))
@cavedave
cavedave / AnimatedDemographics.r
Last active August 26, 2017 15:08
Animated heatmap of the world income and life expectancy. Original idea from NFL heatmap http://noahveltman.com/nflplayers/ I did one for NBA players https://gist.github.com/cavedave/21c6beff2d371e9df323c292b1dc3afa image at http://i.imgur.com/dobmMWM.gifv Image for this demographics at http://i.imgur.com/PvUS4Kr.gif
library(gapminder)
library(ggplot2)
library(devtools)
install_github("dgrtwo/gganimate")
library(gganimate)
library(dplyr)
mydata <- dplyr::select(gapminder, country,continent,year,lifeExp,pop,gdpPercap)
#bin years into 5 year bins
mydata$lifeExp2 <- as.integer(round((mydata$lifeExp-2)/5)*5)
@cavedave
cavedave / createModel.js
Last active September 5, 2017 10:58
This is code to add to Watson's Speech to Text service to improve its accuracy. Blogpost explaining this is at https://watson-tricks.blogspot.ie
var SpeechToTextV1 = require('watson-developer-cloud/speech-to-text/v1');
var speech_to_text = new SpeechToTextV1 ({
username: 'username',
password: 'password'
});
var params = {
name: 'DC Example model',
'base_model_name': 'en-US_BroadbandModel',
description: 'Example custom language model'
<?xml version="1.0" encoding="UTF-8"?>
<tmx version="1.4">
<header creationtool="" creationtoolversion=""
segtype="sentence" o-tmf="" adminlang="EN"
srclang="en" datatype="rtf" o-encoding="UTF-8" />
<body>
<tu>
<tuv xml:lang="en">
<seg>Exchange</seg>
</tuv>
import turtle
import random
random.seed(42)
i=0
#file = open("emil.txt", "r")
#file = open("pi1000000.txt", "r")
file = open("sqrt2.txt", "r")
text=file.read()
pi = list(text)
pi = list(map(int, pi))
@cavedave
cavedave / PrimeFractals
Created October 1, 2017 21:29
Python code to make a logo turtle move. it reads the digits of Smarandache–Wellin numbers if the digit is 0 move a step right. 1 36 degrees to the right of that. etc
#!/usr/bin/python3
import turtle
#the number of digits to use
numDigits = 1000000
changeColorInc = numDigits / 10
colors = iter(["#a6cee3", "#1f78b4", "#b2df8a", "#33a02c", "#fb9a99", "#e31a1c", "#fdbf6f", "#ff7f00", "#cab2d6", "#551A8B"])
#scale = 0.99 1k
#scale = 0.199#10k
@cavedave
cavedave / sameSizeFractals.py
Created October 5, 2017 12:35
Python Logo Turtle code to draw paths with numbers based on numbers. A picture made of all, odd, even and prime numbers can be made with this code
# !/usr/bin/python3
import turtle
import numpy as np
import math
#the number of digits to use
numDigits = 1000000
changeColorInc = numDigits / 10
colors = iter(["#a6cee3", "#1f78b4", "#b2df8a", "#33a02c", "#fb9a99", "#e31a1c", "#fdbf6f", "#ff7f00", "#cab2d6", "#551A8B"])