Skip to content

Instantly share code, notes, and snippets.

@cavedave
cavedave / wheatClor.py
Last active December 28, 2015 08:19
This is Python code to create a map of wheat producing counties int he US
import csv
from bs4 import BeautifulSoup
# Read in wheat production -----
wheat = {}
reader = csv.reader(open('aw98.csv'), delimiter=",")
#file has four lines of headers
next(reader, None)
next(reader, None)
next(reader, None)
@cavedave
cavedave / WorldWheat
Created November 14, 2013 22:53
Python code to colourize each country based on how much grin it produces
import csv
# Read in wheat production -----
wheat = {}
reader = csv.reader(open('psd_grains_pulses.csv'), delimiter=",")
#first line is the header
next(reader, None)
for row in reader:
@cavedave
cavedave / index.html
Last active December 28, 2015 16:39
US cereals grown over recent history. Data from http://www.fas.usda.gov/psdonline/psdDownload.aspx Graph uses d3.js to make a stacked area graph
<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font: 10px sans-serif;
}
.axis path,
.axis line {
@cavedave
cavedave / HandsOnNode
Last active December 31, 2015 20:39
Hands on node by Pedro Teixeira exercises. These are the Buffer exercises the first set. Emitters the second.
/*
Buffers
Exercise 1
Create buffer 100 bytes
ill it with 0 to 99
*/
var buffer1 = new Buffer(100);
for(var i=0; i<buffer1.length;i++){
@cavedave
cavedave / Stream adventure
Last active January 1, 2016 15:19
Node stream adventure code
/*
Part 1 Stream adventure
*/
console.log("beep boop");
/*
Part 2 Meet Pipe
*/
var fs = require('fs');
fs.createReadStream(process.argv[2]).pipe(process.stdout);
@cavedave
cavedave / gist:8304548
Last active February 4, 2016 20:55
node school functional javascript
/*
uppercase everything
*/
module.exports = function(input) {
return input.toString().toUpperCase();
}
/*
/* Fair Division Program
This is a program for dividing up items between people people.
So the minimum satisfaction of any of them is maximised. */
param people, integer,> 0;
/* number of people dividing stuff */
param divi, integer, >= 0;
param indiv, integer, >= 0;
/* number of items to be divided. divi divisible. indiv non divisible */
set I:= 1..people;
/* set of people */
@cavedave
cavedave / county population
Last active August 29, 2015 14:08
color map or Irish water protests
county population pop
Carlow 54 54000
Cavan 73 73000
Clare 117 117000
Cork 519 519000
Donegal 161 161000
Dublin 1273 1273000
Galway 250 250000
Kerry 145 145000
Kildare 210 210000
@cavedave
cavedave / IrishTree
Created March 3, 2015 23:23
Tree Ring Graph of Irish Life Expectancy
<!DOCTYPE html>
<html>
<body>
<canvas id="myCanvas" width="1000" height="1000"
style="border:1px solid #d3d3d3;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("myCanvas");
#Twitter now allows 10k characters in a direct message
#Below is the linux commands to convert Moby dick into
#1432 10k long direct messages
#It strips the Gutenberg header and footer as reading those would be odd
wget http://www.gutenberg.org/cache/epub/2701/pg2701.txt
sed '21745,22109d' mb.txt > mb-ft.txt
sed '1,537d' mb-ft.txt > mb-tr.txt
mkdir moby10k
split -b 10000 mb-tr.txt moby10k/