Skip to content

Instantly share code, notes, and snippets.

View pgilad's full-sized avatar
🔭

Gilad Peleg pgilad

🔭
View GitHub Profile
@pgilad
pgilad / word_count.hs
Created December 16, 2017 20:28
Dictionary word count in Haskell
import Data.List
import qualified Data.Map.Strict as Map
import Data.Ord (comparing)
wordFrequency :: (Ord a) => [a] -> Map.Map a Int
wordFrequency xs = foldr (\word acc -> Map.insertWith (+) word 1 acc) Map.empty xs
nBiggest :: Int -> Map.Map a Int -> [(a, Int)]
nBiggest n m = take n $ sortBy (comparing $ negate . snd) $ Map.toList m
@pgilad
pgilad / env.php
Created September 7, 2017 06:43
env.php
<?php
use Yosymfony\Toml\Toml;
ini_set('display_errors', false);
ini_set('display_startup_errors', true);
ini_set('newrelic.appname', 'gilad-dev');
error_reporting(E_ALL ^ E_STRICT ^ E_NOTICE ^ E_DEPRECATED ^ E_WARNING);
library(ggplot2)
library(MASS)
setwd('~/Downloads/jtls_and_more/')
jtl <- read_csv("~/Downloads/jtls_and_more/sample.jtl.csv")
df <- subset(jtl, jtl$lb == 'HomePage_01')
ggplot(jtl, aes(t)) +
facet_wrap( ~ lb, ncol = 3) +
geom_histogram(bins = 75) +
@pgilad
pgilad / percentiles.R
Created April 2, 2017 06:19
Percentiles plot using R
library("ggplot2")
sample.jtl <- read.csv("~/repos/work/csv-percentiles/sample.csv")
sample.jtl$ts <- as.POSIXct(sample.jtl$ts / 1000, origin="1970-01-01")
interval_size <- '5 sec'
wanted_percentiles <- c(0.5, 0.9, 0.95, 0.99)
get_quantiles <- function(items) {
yy <- quantile(items, wanted_percentiles)
@pgilad
pgilad / optim-log-likelihood.R
Last active December 9, 2016 08:39
Using R optim to find maximum log likelihood with a V(Theta) and gradient
setwd("~/Documents/MA Statistics/Statistical Models A/targil 4")
H <- matrix(c(0, 2, 4, 6, 8, 2, 0, 2, 4, 6, 4, 2, 0, 2, 4, 6, 4, 2, 0, 2, 8, 6, 4, 2, 0), byrow = TRUE, nrow = 5)
X <- as.matrix(read.table("./targ3dat.txt", quote = "\"", comment.char = ""))
n <- nrow(X)
d <- ncol(X)
S <- sum(apply(X, 1, crossprod))
calculate_V <- function(theta) {
psi <- theta[1:d]
@pgilad
pgilad / chi_square_min_sample.r
Last active April 15, 2018 10:28
Find minimum sample size to obtain minimum power test in non-centralized chi-square
u <- c(0.1, 0.3, 0.5)
chi_df <- 3
target_power <- 0.9
chi_base <- qchisq(0.95, chi_df)
get_power <- function(n) {
return (pchisq(q = chi_base, df = chi_df, ncp = n * u %*% u, lower.tail = FALSE))
}
get_power(20)
@pgilad
pgilad / gram-schmidt.r
Last active April 15, 2018 10:29
Gram-Schmidt on a subspace of vectors
cols <- c(
c(3, 9, 2, 3, 2),
c(8, 8, 1, 9, 0),
c(1, 9, 5, 9, 8),
c(8, 10, 7, 5, 3),
c(5, 8, 8, 0, 8),
c(5, 10, 4, 7, 2))
# prepare column vectors matrix
mat <- matrix(cols, byrow = FALSE, nrow = 5)
@pgilad
pgilad / worker.conf
Created October 10, 2016 08:17
Blazemeter worker and scheduled worker `.conf` for supervisord
[program:gilad-worker]
command=php /home/gilad/vol/www/a.blazemeter.com/vendor/kamisama/php-resque-ex/bin/resque
directory=/home/gilad/vol/www/a.blazemeter.com
autorestart=true
autostart=true
startretries=10000
stderr_logfile=/var/log/blazemeter/%(program_name)s-error.log
stdout_logfile=/var/log/blazemeter/%(program_name)s.log
:args `ag -l word`
:argdo %s/word/newWord/gc | w
@pgilad
pgilad / json-to-toml.py
Created May 16, 2016 12:56
Convert a json file to toml
#!/usr/bin/env python2
# don't forget to `pip install toml`
import json
import sys
import toml
if len(sys.argv) < 3: raise Exception('Usage is `json_to_toml.py input.json output.toml`')
json_file = sys.argv[1]