Skip to content

Instantly share code, notes, and snippets.

View vikjam's full-sized avatar
💭
👨🏾‍💻

vikjam

💭
👨🏾‍💻
View GitHub Profile
@vikjam
vikjam / get.clip.r
Last active April 16, 2016 19:59
Get data from clipboard in R
get.clip <- function(header = TRUE, stringsAsFactors = FALSE, ...) {
read.table(pipe("pbpaste"), sep = "\t", header = header, stringsAsFactors = stringsAsFactors, ...)
}
@vikjam
vikjam / xtfill.r
Created April 30, 2016 00:37
Pads an imbalanced panel data set with missing values.
# via http://www.enoriver.net/2015/02/09/r-version-of-tsfill-and-xfill-combined/
xtill <- function(x) {
dt <- copy(x)
xtkeys <- c('zip.cd','cal.dt')
clkeys <- c('zip.cd','dma.cd')
xtfull <- CJ(unique(x[,zip.cd]),unique(x[,cal.dt]))
clfull <- unique(subset(x,select=c(zip.cd,dma.cd)))
setnames(xtfull,c('V1','V2'),xtkeys)
setkeyv(xtfull,xtkeys)
painting color_1 color_2 color_3 color_4 color_5
Adobe (Variant): Luminous Day by Josef Albers #D77186 #61A2DA #6CB7DA #b5b5b3 #D75725
Homage to the Square (La Tehuana) by Josef Albers #C00559 #DE1F6C #F3A20D #F07A13 #DE6716
Rainbow by Billy Apple #F24D98 #813B7C #59D044 #F3A002 #F2F44D
Spar by Per Arnoldi #C2151B #2021A0 #3547B3 #E2C43F #E0DCDD
Bicycle Rider By The Loire by Milton Avery #F3C937 #7B533E #BFA588 #604847 #552723
Cello Player by Milton Avery #E2CACD #2E7CA8 #F1C061 #DA7338 #741D13
The Swan by Hilma af Klint #D6CFC4 #466CA6 #D1AE45 #87240E #040204
Untitled (Black King Catch Scorpio) by Jean-Michel Basquiat #8CABD9 #F6A7B8 #F1EC7A #1D4D9F #F08838
DUSTHEADS by Jean-Michel Basquiat #C11432 #009ADA #66A64F #FDD10A #070707
@vikjam
vikjam / wav2mp3.sh
Last active May 4, 2016 18:39
.wav to .mp3 with album art.
# VBR (with loop)
for f in *.wav; do lame --ti "path/to/file/album_art.jpg" --vbr-new -V 3 "$f" "${f%.wav}.mp3"; done
# Non-VBR (no loop)
lame --ti "path/to/file/album_art.jpg" -h -b "wavfile.wav" "mp3file.mp3"
@vikjam
vikjam / flac2aac.sh
Created May 11, 2016 11:38
Convert FLAC to AAC
# Install ffmpeg with the right codec
brew install ffmpeg --with-fdk-aac
# Actual loop
for i in *flac;do of="${i/.flac/.m4a}"; ffmpeg -i "${i}" -c:a libfdk_aac -b:a 320k "${of}";done
@vikjam
vikjam / regress-vs-randomforest.r
Created August 9, 2016 15:27
Example of regression versus random forest predictions from StackExchange
# http://stats.stackexchange.com/questions/66757/random-forest-vs-regression
beta <- runif(5)
x <- matrix(rnorm(500), nc=5)
y <- drop(x %*% beta)
dat <- data.frame(y=y, x1=x[,1], x2=x[,2], x3=x[,3], x4=x[,4], x5=x[,5])
model1 <- lm(y~., data=dat)
model2 <- randomForest(y ~., data=dat)
pred1 <- predict(model1 ,dat)
pred2 <- predict(model2 ,dat)
@vikjam
vikjam / Preferences.sublime-settings
Created September 4, 2016 13:16
Preferences.sublime-settings
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_extra_bottom": 1,
"caret_extra_top": 1,
"caret_extra_width": 1,
"caret_style": "blink",
"color_scheme": "Packages/Material Theme/schemes/Material-Theme-Darker.tmTheme",
"fade_fold_buttons": false,
"font_face": "Source Code Pro",
@vikjam
vikjam / equal.with.NA.r
Last active January 11, 2017 01:01
Include NA in test
'%==%' <- function(a, b) {
equality.test <- (a == b)
equality.test[is.na(a) & is.na(b)] <- TRUE
equality.test[is.na(equality.test)] <- FALSE
return(equality.test)
}
@vikjam
vikjam / sampsi-vs-power.do
Created January 22, 2017 15:57
sampsi versus power in Stata
* Two-sample comparison of mean1 to mean2. Compute sample sizes with n2/n1 = 2:
sampsi 132.86 127.44, p(0.8) r(2) sd1(15.34) sd2(18.23)
power twomeans 132.86 127.44, p(0.8) nratio(2) sd1(15.34) sd2(18.23)
@vikjam
vikjam / split.sh
Created March 12, 2017 02:27
Split file into equal parts
awk 'NR%20==1 { file = FILENAME "_" sprintf("%04d", NR+19) } { print > file }' domains.xml