Skip to content

Instantly share code, notes, and snippets.

@csiu
csiu / fibonacci.scala
Created February 12, 2018 01:31
scala - Fibonacci number
//Example of Recursive Function: Fibonacci number
def fib(n: Int): Int = {
def go(n: Int): Int = {
if (n == 1) 0 else if (n == 2) 1 else go(n-1)+go(n-2);
}
return go(n)
}
@csiu
csiu / README.md
Last active September 11, 2017 06:45
Reading data

Showing text from a file

I want to be able to read in data for D3.

The data set

But first, we need a dataset. As a Canadian, housing is a big concern (understatement). I therefore decided to explore the Homeowners' debt at a glance data tables from the Canada Mortgage and Housing Corporation website.

@csiu
csiu / README.md
Created September 11, 2017 06:16
DATASET: Homeowners' debt at a glance data tables

This "Average Value of New Mortgage Loans, Canada, Provinces, and CMAs 2012 Q3 to 2016 Q4" data set is downloaded from the Canada Mortgage and Housing Corporation website on Sep 10, 2017.

According to their notes:

Source: Equifax Canada Notes:

Seasonal effects have not been removed from the data

@csiu
csiu / README.md
Last active September 8, 2017 14:46
N items

Working with N items

Instead of have a defined set of items, I want to be able to vary this with N.

In this example, I

  • used variable n to represent any number of items in an array
  • and iterated over this array using .each()
@csiu
csiu / README.md
Last active September 7, 2017 06:06
Scaling color

Are these all the same length?

The default colors are nice, but I want to create my own custom color scale.

@csiu
csiu / README.md
Last active September 7, 2017 04:34
dot dot dot

Hello D3 JS!

I want to pick up D3. In this exercise, I

  • (1) created "circle" svg elements by binding data and
  • (2) filling these circles with colors
@csiu
csiu / this_script.scala
Last active June 3, 2017 08:47
Day98 of 100 Days of Code
import java.nio.file.{Paths, Files}
/*
Usage: scala <this_script> <data_file>
Function:
For each line in data_file, generate template code around each line.
If line matches some regular expression, do a few more things to the output.
*/
val input_file = args(0)
@csiu
csiu / 2017-05-09_emoji.png
Last active May 13, 2017 07:25
Day 77: Modularizing functionality & Better emoji displays
2017-05-09_emoji.png
@csiu
csiu / emoji-data-science-twitter.Rmd
Created May 11, 2017 07:52
Day 75: emoji count during bc 2017 elections
---
title: "Download twitter data"
author: "csiu"
output:
html_document:
keep_md: yes
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
@csiu
csiu / emoji-data-science-twitter.Rmd
Last active May 8, 2017 07:13
Doing emoji data science
---
title: "Download twitter data"
author: "csiu"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
eval=TRUE,
cache = TRUE )