Skip to content

Instantly share code, notes, and snippets.

View vkryukov's full-sized avatar

Victor vkryukov

  • Sunnyvale, CA
  • 17:20 (UTC -08:00)
View GitHub Profile
@vkryukov
vkryukov / gist:4d53f84080bf088f087b
Created June 30, 2014 20:27
go.enmime library example
package main
import (
"bytes"
"fmt"
"log"
"net/mail"
enmime "github.com/jhillyerd/go.enmime"
)
@vkryukov
vkryukov / display_board.m
Created April 23, 2014 02:29
Display boards filled with black and white stone in Mathematica
randomPoints[n_] := RandomSample[Block[{nn = Ceiling[Sqrt[n]]},
Flatten[Table[{i, j}, {i, 1, nn}, {j, 1, nn}], 1]], n];
(* n is number of moves = 2 * number of points *)
randomBoard[n_] := Module[
{points = randomPoints[2 n]},
Join[
Take[points, n] /. {x_, y_} -> black[x, y],
Take[points, -n] /. {x_, y_} -> white[x, y]
]]
@vkryukov
vkryukov / database_table_sizes.R
Created March 24, 2014 19:02
Calculate MS SQL database table sizes in R
tables <- SQLQuery("
select TABLE_NAME as table_name
from cs_reporting.information_schema.tables
where table_type = 'BASE TABLE'")
sizes <- rbindlist(lapply(tables$table_name, function(x) SQLQuery(paste0("sp_spaceused [", x, "]"))))
StripKB <- function(x) as.integer(str_replace_all(x, ' KB', ''))
sizes[, reserved := StripKB(reserved)]
library(digest)
LoadRDataIfExists <- function(fn) {
# Calls _fn_ and caches the result on disk, unless the cache already exists
#
# _fn_ should be a function with signature _fn(filename, ...)_
# If cache file exists and is recent, load data from it.
# Otherwise call the original function.
function (filename, ...) {
param.hash = digest(c(fn, list(...))) # Cache file names depends on params/fn def