Skip to content

Instantly share code, notes, and snippets.

View pgilad's full-sized avatar
🔭

Gilad Peleg pgilad

🔭
View GitHub Profile
@pgilad
pgilad / script.js
Created December 2, 2018 13:19
Minimal compiler for typescript files
const ts = require('typescript');
const tsConfig = require('./tsconfig.json');
const config = tsConfig.compilerOptions;
function compile(fileNames, options) {
if (fileNames.filter(Boolean).length === 0) {
console.log('No files');
return;
}
@pgilad
pgilad / ExampleWebFilter.java
Last active June 17, 2021 08:02
Try to use WebFilter in Spring Boot Webflux in order to log request body
package com.blazemeter.dagger.config;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import org.springframework.web.server.WebFilter;
import org.springframework.web.server.WebFilterChain;
import reactor.core.publisher.Mono;
@pgilad
pgilad / Constants.java
Last active December 26, 2018 07:37
An example of a pre-set scheduler for paralleling reactive work
public static final Scheduler scheduler = Schedulers.fromExecutorService(new ThreadPoolExecutor(4, 10, 60, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>()))
@pgilad
pgilad / test.php
Created October 24, 2018 07:54
Php instance property mutation
<?php
class State {
public $foo = 0;
}
class Mutator {
public function mutateState(State $state) {
$state->foo = 4;
}
@pgilad
pgilad / Dockerfile
Last active March 18, 2024 04:37
Minimal Spring Boot 2 on Docker Alpine with Java 11 (Using Jigsaw modules)
FROM alpine:3.8 AS builder
WORKDIR /opt
ARG JDK_TAR=openjdk-11+28_linux-x64-musl_bin.tar.gz
ARG JDK_DOWNLOAD_PREFIX=https://download.java.net/java/early_access/alpine/28/binaries
RUN wget -q "$JDK_DOWNLOAD_PREFIX/$JDK_TAR" && \
wget -q "$JDK_DOWNLOAD_PREFIX/$JDK_TAR.sha256"
RUN cat $JDK_TAR.sha256 | xargs -I{} echo "{} $JDK_TAR" | sha256sum -c - && \
@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;
@pgilad
pgilad / main.go
Created August 8, 2018 17:58
Generate stable random name from string (used to generate docker tag from git branch)
package main
import (
"fmt"
"hash/fnv"
"math/rand"
"os"
"github.com/docker/docker/pkg/namesgenerator"
)
@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 / 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 / Instructions.md
Last active March 27, 2024 12:59
Generate SSL Certificate for use with Webpack Dev Server (OSX)

Generate private key

$ openssl genrsa -out private.key 4096

Generate a Certificate Signing Request

openssl req -new -sha256 \