Skip to content

Instantly share code, notes, and snippets.

View leonid-shevtsov's full-sized avatar
🇺🇦
Help Ukraine Win

Leonid Shevtsov leonid-shevtsov

🇺🇦
Help Ukraine Win
View GitHub Profile
require 'concurrent/atomic/read_write_lock'
require 'benchmark/ips'
require 'active_support/core_ext/string'
rw = Concurrent::ReadWriteLock.new
Benchmark.ips do |x|
x.report("with_read_lock") do
rw.with_read_lock do
Math.sqrt(4)
end
#!/bin/sh
GITHUB_PAT_TOKEN=github_pat_xxx
REPO=myuser/myrepo
FILEPATH=online.txt
# echo -n '...' | base64
INCREMENT='Li4u'
FILEINFO=$(curl \
@leonid-shevtsov
leonid-shevtsov / monitor_online_status.ts
Created December 3, 2022 21:35
Автоматично повідомляй команду про наявність звʼязку за допомогою Firebase
// 1. Set up Firebase app
// 2. Set up Slack webhook
// 3. Configure slack.webhook_url in the app
// 4. Deploy functions
// 5. Note the `canary` function URL
// 6. Make sure to GET the `canary` endpoint once an hour.
// 7. That's all!
import * as admin from "firebase-admin";
import * as functions from "firebase-functions";
require 'benchmark/ips'
def sum(x, y)
x + y
end
def nested_sum(x, y)
sum(x, y)
end
@leonid-shevtsov
leonid-shevtsov / fish_prompt.fish
Last active September 3, 2022 12:45
Minimal fish prompt for VSCode
function fish_prompt
if not set -q VSCODE_WS; or test $VSCODE_WS = '${workspaceFolder}'
# not vscode or no active workspace
set shortpath (prompt_pwd)
else
set shortpath (realpath --relative-to $VSCODE_WS .)
if test (string sub --length 2 $shortpath) = ".."
# working dir is outside of workspace
set shortpath (printf "🌍 %s" (prompt_pwd))
else if test $shortpath = '.'
@leonid-shevtsov
leonid-shevtsov / sqs.hsl
Created May 27, 2020 06:05
Send data to AWS SQS (Simple Queue Service) from Halon MTA (with signature)
function signedHeaders($headers) {
return array_join(array_sort(function ($a, $b) { return $a < $b; }, array_map(function($key) { return str_lower($key); }, array_keys($headers))), ";");
}
function canonicalRequest($method, $uriPath, $queryString, $headers, $signedHeaders, $requestBody) {
$headersString = array_join(array_sort(function ($a, $b) { return $a < $b; }, array_map(function($key) closure($headers) { return str_lower($key) . ":" . $headers[$key]. "\n"; }, array_keys($headers))));
$payloadHash = sha2($requestBody, 256);
return $method . "\n" . $uriPath . "\n" . $queryString . "\n" . $headersString . "\n" . $signedHeaders . "\n" . $payloadHash;
}
<?
// расчет числа рабочих дней в промежутке дат
// $start_day = 1 марта 2020, $total_days = 12
function workday_count($start_day_as_timestamp,$total_days)
{
//$weekday 0 = Sun 1 = Mon ...
$weekday = date('w',$start_day_as_timestamp);
// $weekday = 0: 1 марта 2020 - воскресенье
import * as React from 'react';
export type ToggleChildProps = {
toggle: () => void;
};
type WithToggleChildProps<P extends object> = ToggleChildProps &
Pick<P, Exclude<keyof P, 'viewComponent' | 'editComponent'>>;
type ToggleProps<P extends object> = {
require 'set'
require 'benchmark/ips'
Benchmark.ips do |x|
array = (1..50000).to_a
shuffled_array = array.shuffle
set = array.to_set
hash = array.zip([false]*50000).to_h
x.report("with array") { array.include?(Random.rand(50000)) }
x.report("with shuffled array") { shuffled_array.include?(Random.rand(50000)) }
package main
import (
"fmt"
"math/rand"
"time"
)
func sortedChan(inputChans []<-chan int) <-chan int {
outChan := make(chan int)