Skip to content

Instantly share code, notes, and snippets.

View pgilad's full-sized avatar
🔭

Gilad Peleg pgilad

🔭
View GitHub Profile
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 / 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);
@pgilad
pgilad / create-temp-dir.yml
Created October 27, 2015 15:08
Create a temp dir cross-platform in ansible
- name: create a local temp directory
local_action:
module: command mktemp -d "{{ lookup('env', 'TMPDIR') | default('/tmp/') }}ansible.XXXX"
register: mktemp_output
@pgilad
pgilad / gulpfile.js
Last active November 27, 2017 21:44
gulpfile regular flow
var path = require('path');
var gulp = require('gulp');
var streamqueue = require('streamqueue');
var $gulp = require('gulp-load-plugins')({
lazy: false
});
var prependBowerPath = function (package) {
return path.join('./src/bower_components/', package);
};
@pgilad
pgilad / Builder.js
Created March 20, 2018 19:16
A builder for requests
export class Request {
ajax = $.ajax;
baseURL = API_BASE_URL;
contentType = 'application/json';
data = null;
dataType = 'json';
global = true;
method = 'GET';
params = null;
paramsSerializer = defaultParamsSerializer;
@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 / 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 / build.gradle
Created June 20, 2018 18:02
Modern build.gradle
buildscript {
ext {
springBootVersion = '2.0.2.RELEASE'
}
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
@pgilad
pgilad / percentiles.java
Created September 19, 2018 11:29
Percentiles
@GetMapping("/percentiles-distribution")
public Flux<PercentilesDistribution> getAggregatePercentiles(
@RequestParam @Positive long masterId,
@RequestParam(defaultValue = "0") @Min(-1) long from,
@RequestParam(defaultValue = "0") @Min(-1) long to,
@RequestParam(defaultValue = "ALL") @Size(max = Constants.MAX_LOCATIONS) ArrayList<String> locationId,
@RequestParam(defaultValue = "") @Size(max = Constants.MAX_SCENARIOS) ArrayList<String> scenarioId,
@RequestParam(defaultValue = "") ArrayList<String> labelIds
) {
final int interval = 60;