Skip to content

Instantly share code, notes, and snippets.

@zloyrusskiy
zloyrusskiy / child.ts
Last active March 11, 2024 11:40
for Andrey async test
const delay = (ms: number) => {
return new Promise( resolve => setTimeout(resolve, ms) );
}
const someAsync = async() => {
await delay(5000)
if (Math.random() < 0.5) {
throw Error("ppc")
}
}
require 'rest-client'
require 'uri'
require 'json'
class TinkoffInvestClient
API_URL = 'https://api-invest.tinkoff.ru/openapi'
API_SANDBOX_URL = 'https://api-invest.tinkoff.ru/openapi/sandbox'
def initialize(token, sandbox = false)
@token = token
@zloyrusskiy
zloyrusskiy / fizzbuzz.rb
Created February 1, 2019 17:49
fizzbuzz enumerator
fizzbuzz = Enumerator.new do |y|
num = 0
loop do
y << case
when num % 15 == 0 then "FizzBuzz"
when num % 3 == 0 then "Fizz"
when num % 5 == 0 then "Buzz"
else num
end
num += 1
@zloyrusskiy
zloyrusskiy / gist:4795983f8494bbddbc093a203c2ebfa9
Last active January 8, 2019 13:07
keyboard layouts (ru/en)
MAC
§1234567890-=qwertyuiop[]asdfghjkl;'\`zxcvbnm,./
>1234567890-=йцукенгшщзхъфывапролджэё]ячсмитьбю/
±!@#$%^&*()_+QWERTYUIOP{}ASDFGHJKL:"|~ZXCVBNM<>?
<!"№%:,.;()_+ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЁ[ЯЧСМИТЬБЮ?
PC
@zloyrusskiy
zloyrusskiy / 1.ex
Last active May 21, 2017 13:48
elixir fizzbuzz
defmodule Fizzbuzz do
def solve(n) when n > 100, do: nil
def solve(n) do
IO.puts calc(n)
:timer.sleep(50)
solve(n + 1)
end
defp calc(n) do
cond do
var OUTPUT_DIR = 'pics';
var fs = require('fs');
if (!fs.exists(OUTPUT_DIR)) {
fs.makeDirectory(OUTPUT_DIR);
}
var casper = require('casper').create({
verbose: true,
var Benchmark = require('benchmark');
var suite = new Benchmark.Suite;
// add tests
suite.add('lowercase', function() {
let input = 'ai';
let dictionary = ['airplane','airport','apple','ball'];
var clean_str = input.replace(/[^a-z]+/gi,'').toLowerCase();
@zloyrusskiy
zloyrusskiy / bashrc-part.sh
Created April 28, 2016 11:03
my bash promt
PS1='\[\e[1;37m\]⌞ \[\e[1;32m\]\u\[\e[0;39m\]@\[\e[1;36m\]\h\[\e[0;39m\]:\[\e[1;33m\]\w\[\e[0;39m\]\[\e[1;35m\]$(__git_ps1 " (%s)")\[\e[0;39m\] \[\e[1;37m\]⌝\[\e[0;39m\]\n$ '
def more_than_medium string
words = string.split /\W+/
return [] if words.empty?
avg = words.inject(0) { |res, w| res += w.size; res } / words.size
words.select { |w| w.size > avg }
end
@zloyrusskiy
zloyrusskiy / detect_language.rb
Last active August 29, 2015 14:25
Denu detect words
def detect_language words
if Array(words).any? { |w| w =~ /\p{Cyrillic}/ }
364
elsif Array(words).any? { |w| w =~ /\p{Hangul}/ }
0 # тут корейский код, неебу какой
else
124
end
end