What does a ||= b
mean?
What is the difference between a symbol and a string?
What is the difference between '
and "
in Ruby?
# This is a database of zipcodes and their time zones | |
# by Peter Hurford <http://www.peterhurford.com> | |
# Coded in an array as zitpime[<zip code>] = [<time offset from UTC>, <DST yes (1) or no (0)>] | |
# Daylight Savings is March 9 to November 2 | |
# Data retrieved from http://www.boutell.com/zipcodes/ (CSV and SQL available), which in turn retrieved data from the CivicSpace US ZIP Code Database. | |
# Here, I used Regex to sort the data into a Ruby hash. | |
# You are free to use this array for your own purposes, just provide attribution. |
What does a ||= b
mean?
What is the difference between a symbol and a string?
What is the difference between '
and "
in Ruby?
1a.) Why would one use a symbol instead of a string?
1b.) Why would someone use a string instead of a symbol?
2a.) What is the difference between a lambda, a block and a proc?
2b.) What does -> (a) {p a}["Hello world"]
do?
While reading Hadley's Advanced R book chapter on function operators (see our work on creating a set of answers here), I came across this fact about lazy evaluation:
The function operators we’ve seen so far follow a common pattern:
funop <- function(f, otherargs) { function(...) { # maybe do something res <- f(...) # maybe do something else
# Debugging in R is much better than many languages, but sometime it can be | |
# frustrating. Here's a function that makes it even more frustrating -- | |
# it only works when you try to debug it! | |
# The challenge: | |
### Write a function that, if the function has a browser in it, will execute | |
### every line correctly, but if it does not have a browser in it, it will | |
### error. | |
# The solution: |
The Fledgling Languages list has almost 100 programming languages that are up-and-coming but not widely popular. I looked at them all and here are a few of my favorites:
...This language looks so much like English! http://www.availlang.org/
...This language claims to have the speed of C++, the expressiveness of Python, and tons of additional safety with first-level contracts http://cobra-language.com/
...Code that looks exactly like Ruby, but is statically type-checked and compiled into efficient native code http://crystal-lang.org/
...What it would look like if Haskell and Clojure had a baby https://github.com/LuxLang/lux
Total kg per capita consumed of beef, veal, pork, poultry, and sheep meat by country in 2016, adapted from OECD Data on Meat Consumption. Per-animal breakdown is available as a CSV.
IND 2.944374911
BGD 3.358927799
ETH 4.449228451
NGA 6.061917778
TZA 6.986943733
MOZ 7.117845532
SSA 8.798326892
#' Calculate a dep_var for the iris dataset based on the iris dataset.
#'
#' @param by character. \code{length} to go by \code{Petal.Length} or \code{width} to go by \code{Petal.Width}.
iris_with_dep_var <- validations::ensure(pre = list(by %in% c("length", "width")),
function(by = "length") {
if (identical(by, "length")) {
plyr::ddply(iris, plyr::.(Species), summarize, dep_var = ifelse(any(Petal.Length >= 4), 1, 0))
} else {
plyr::ddply(iris, plyr::.(Species), summarize, dep_var = ifelse(any(Petal.Width >= 4), 1, 0))
Notes from reading through R Packages by Hadley Wickham. This is meant to review, not replace, a thorough readthrough. I mainly wrote this as a personal review, since writing summaries and attempting to teach others are some of the best ways to learn things.
Packages are used to organize code together so that it can be used repeatedly and shared with others.
A lot of work with packages is done via the devtools package.