Skip to content

Instantly share code, notes, and snippets.

View siberex's full-sized avatar
🛠️
Your stack will not be full without me

Stepan Legachev siberex

🛠️
Your stack will not be full without me
View GitHub Profile
@siberex
siberex / cancelot.sh
Last active July 14, 2022 03:03
Provides automation for cancelling previous ongoing Cloud Builds for the same branch/trigger
#!/usr/bin/env bash
# https://github.com/siberex/cancelot
#
# To download the latest version (if you trust running random bash scripts from the internets!):
# curl -L https://gist.github.com/siberex/bb0540b208019382d08732cc6dd59007/raw -o cancelot.sh && chmod +x cancelot.sh
#
# Provides automation for cancelling Cloud Builds
# Use as a first step to cancel previous builds currently in progress or queued for the same branch name and trigger id.
# Similar to: https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/cancelot
@siberex
siberex / verify-hits.sh
Created April 6, 2020 01:33
Verify number of remote hits from Bazel execution log
#!/usr/bin/env bash
# https://gist.github.com/siberex/1488492ceb193d936b6bd171fc1a879f
# Verify number of remote hits from execution log produced by:
# bazel build ... --execution_log_json_file=/tmp/execlog.json
# Usage:
# verify-hits.sh 123
# OR:
# verify-hits.sh 100 /tmp/execlog.json
@siberex
siberex / wait-for-file.sh
Last active May 28, 2020 15:12
Wait for file to become readable
#!/usr/bin/env bash
# https://gist.github.com/siberex/d1c07389333d9cdb1c9e6853ec70c98b
# Wait for file to become readable
# Similar to https://github.com/vishnubob/wait-for-it
# Usage:
# wait-for-file.sh -t 10 -p /tmp/something -- echo "ok"
WAITFORIT_cmdname=${0##*/}
@siberex
siberex / fix-execlog-json.sh
Last active April 1, 2020 00:54
Fix json file produced by Bazel’s --execution_log_json_file argument
#!/usr/bin/env bash
# https://gist.github.com/siberex/55f277071068179de026e6cf29c0584a
# Usage:
# bazel build //... --execution_log_json_file=/tmp/execlog.json
# fix-execlog-json.sh /tmp/execlog.json
# Exit script when command fails
set -o errexit
@siberex
siberex / Dockerfile
Last active March 31, 2020 21:57
Angular 9 Bazel build test
# https://hub.docker.com/r/sibli/bazel-test
FROM l.gcr.io/google/bazel:2.2.0 AS builder
# Add Bazelisk
RUN curl -L -o /usr/local/bin/bazel https://github.com/bazelbuild/bazelisk/releases/download/v1.3.0/bazelisk-linux-amd64 \
&& chmod +x /usr/local/bin/bazel
RUN curl -sL https://deb.nodesource.com/setup_12.x | bash -
@siberex
siberex / check_all_targets.sh
Last active February 26, 2020 20:11
Quickly check result for all Bazel targets within workspace
#!/usr/bin/env bash
# Executes build for all Bazel targets of specified kind ('rule' by default)
# and displays result alongside with the target
# Example:
# $ ./all_targets.sh ng_module
# SUCCESS //app/success/src:src
# FAILURE //app/failure/src:src
kind="${1:-rule}"
@siberex
siberex / random-files.sh
Last active January 30, 2020 00:22
Creates N files with random content and size, and prints out sizes and SHA256 checksums
#!/usr/bin/env bash
# Creates 10 files with random content and random size in /tmp
# And prints out sizes and SHA256 checksums
N=10
outDir="/tmp"
printf "FILENAME\tSHA256\tSIZE\n"
for (( i=1; i<=N; i++ )); do
fname=file$( printf %04d "$i" ).bin
size=$(( (RANDOM*1024) + 1024 ))
base64 /dev/urandom | head -c "$size" > "$outDir/$fname"
@siberex
siberex / !oh-my-zsh-macos.md
Last active September 3, 2020 16:47
Oh-My-Zsh MacOs setup
@siberex
siberex / float_to_int_clickhouse.sql
Last active May 28, 2020 15:11
ClickHouse Float to Int conversion saving precision
-- Yandex ClickHouse could give you unexpected results if you try to cast string to float
-- and then convert it to integer to do arithmetics or just to store it as int.
-- Because of IEEE 754, string casted to float and back will not resemble original string (depending on value).
-- Example:
SELECT toString(toFloat64('1.07787')) AS result
-- 1.0778699999999999
-- This will lead to loss of precision in some arithmetic operations:
SELECT toUInt64( toFloat64('1.07787') * exp10(5) ) AS result
@siberex
siberex / bmp.js
Last active June 26, 2018 16:03
Create BMP (windows bitmap) file with JavaScript using ArrayBuffer
"use strict";
const fs = require('fs')
, path = require('path')
;
const width = 1000
, height = 1000
, bpp = 24 // Bits per pixel
;