This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
GITHUB_PAT_TOKEN=github_pat_xxx | |
REPO=myuser/myrepo | |
FILEPATH=online.txt | |
# echo -n '...' | base64 | |
INCREMENT='Li4u' | |
FILEINFO=$(curl \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark/ips' | |
def sum(x, y) | |
x + y | |
end | |
def nested_sum(x, y) | |
sum(x, y) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = '.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// расчет числа рабочих дней в промежутке дат | |
// $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 - воскресенье |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
func sortedChan(inputChans []<-chan int) <-chan int { | |
outChan := make(chan int) |