This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.Color | |
import java.awt.RenderingHints | |
import java.awt.image.BufferedImage | |
import java.io.File | |
import java.nio.file.Paths | |
import javax.imageio.ImageIO | |
fun proc(vararg cmd: String): Process { | |
val pb = ProcessBuilder(cmd.asList()) | |
pb.redirectError(ProcessBuilder.Redirect.INHERIT) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Maps base 256 to base 85 | |
val encoder = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.-:+=^!/*?&<>()[]{}@%$#" | |
.toCharArray() | |
// Maps base 85 to base 256 | |
// We chop off lower 32 and higher 128 ranges | |
val decoder = byteArrayOf( | |
0x00, 0x44, 0x00, 0x54, 0x53, 0x52, 0x48, 0x00, | |
0x4B, 0x4C, 0x46, 0x41, 0x00, 0x3F, 0x3E, 0x45, | |
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
0x08, 0x09, 0x40, 0x00, 0x49, 0x42, 0x4A, 0x47, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ian.json | |
fun exampleJSONUsage() { | |
var json = JSON.parseJSON("{a:5, b:'test', c: {d: 'xxxxxx', e: ['Hello','There','test','one']}}") | |
// pretty printed JSON | |
println(json) | |
// Should be same as previous | |
println(JSON.parseJSON(json.toString())) | |
// get a child JSON object | |
println(json.getJSONObject("c")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* Simulate tables *) | |
a = Table[{x, RandomReal[]}, {x, 1, 100, 2}]; | |
b = Table[{x, RandomReal[]}, {x, 1, 100, 3}]; | |
RJoin[a_, b_] := Block[{f}, | |
Do[ | |
f[x[[1]]] = x[[2]], | |
{x, a} | |
]; | |
Cases[b /. {x_, y_} -> {x, y, f[x]}, {_, _, _Real}] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* | |
Total possible number of items - n | |
Population size for collision probability - x | |
For 32 bit hash, collision prob = 0.5 when number of hashes is 77,162 | |
For 64 bit hash, collision prob = 0.5 when number of hashes is 5 billion. | |
Solve[CollisionProb[x, n] == 0.5, {x, n}] | |
n -> 0.721348 x^2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DateListPlot[ | |
Drop[Import["http://research.stlouisfed.org/fred2/data/OILPRICE.txt", | |
"Table", "HeaderLines" -> 12, | |
"DateStringFormat" -> {"Year", "Month", "Day"}], 5], | |
Joined -> True, PlotRange -> All] |