Skip to content

Instantly share code, notes, and snippets.

@jtoll
jtoll / holidays.csv
Created October 1, 2014 16:42
Dates for the Jewish holidays of Rosh Hashanah and Yom Kippur from 1900 to 2020.

Description

A CSV data file with dates for the Jewish holidays of Rosh Hashanah and Yom Kippur from 1900 to 2020.

@jtoll
jtoll / divisible.hs
Created February 26, 2014 00:37
111 is divisible by 3. 111111111 is divisible by 9. For which N is the number composed of N 1s divisible by N?
-- https://twitter.com/jamestanton/status/438258919413387264
-- "111 is divisible by 3. 111111111 is divisible by 9.
-- For which N is the number composed of N 1s divisible by N?"
-- Version 1: very slow due to the construction of the numerator
numerator1 x = sum $ map (\y -> 10^y) [0..(x-1)]
test1 x = numerator1 x `rem` x == 0
@jtoll
jtoll / cryptoTools.py
Last active September 2, 2019 23:33
Simple functions for converting between string, hex, and int for a crypto course using Python
def str2hex (x):
return x.encode('hex')
def hex2str (x):
return x.decode('hex')
def str2int (x):
return map(ord, x)
@jtoll
jtoll / index.html
Last active December 30, 2015 17:19
A simple example of a javascript function to swap thumbnail images on click
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Title | index.html</title>
<script>
function showImg(x) {
@jtoll
jtoll / sourceGist.r
Created November 8, 2012 21:58
Source a Gist from R
# Example: Easily source a Gist from R using devtools
# 1) install devtools
if (!("devtools" %in% installed.packages()[, 1])) {
install.packages("devtools")
}
# 2) source
# library(devtools)
# source_gist("https://gist.github.com/4041561")
@jtoll
jtoll / machineEpsilon.r
Created November 8, 2012 20:59
Machine epsilon
# "Machine epsilon gives an upper bound on the relative
# error due to rounding in floating point arithmetic."
# http://en.wikipedia.org/wiki/Machine_epsilon
# ?.Machine
.Machine$double.eps
# [1] 2.220446e-16
# 2 ^ (-52)
@jtoll
jtoll / hexColorValues.r
Created November 6, 2012 01:12
Color palette hex values
# Extract the hexadecimal color values for a particular palette from
# the RColorBrewer package, as used by ggplot's scales package.
library("RColorBrewer")
brewer.pal(12, "Paired")
# [1] "#A6CEE3" "#1F78B4" "#B2DF8A" "#33A02C" "#FB9A99" "#E31A1C"
# [7] "#FDBF6F" "#FF7F00" "#CAB2D6" "#6A3D9A" "#FFFF99" "#B15928"