Skip to content

Instantly share code, notes, and snippets.

package main
import (
"fmt"
"strings"
)
func main() {
input := []string{"ass", "fuck", "car", "cat", "cucumber"}
package main
import (
"log"
"sync"
"time"
)
type Worker struct {
name string
@slavone
slavone / asdasd.rb
Created June 11, 2021 16:44
formatting
@fields ||=
Array.new(size) do |y|
Array.new(size) do |x|
Field.new(x: Chess::X[x], y: y + 1)
end
end
@slavone
slavone / benchmark.ex
Created May 1, 2018 10:47
Benchmarking using try/rescue agains function_exported? in elixir for handling unreliable function calls
defmodule Generator do
defmacro testing do
names = (1..10000)
|> Enum.map(fn(_) ->
:crypto.strong_rand_bytes(10) |> Base.url_encode64 |> binary_part(0, 10)
end)
|> Enum.map(&String.to_atom/1)
names
|> Enum.take_every(2)
require 'json'
require 'uri'
# how to use:
# ruby parse_har_file.rb filename_in_curr_dir pattern_to_match_correct_urls optional_param_accepted_statuses_separated_by_commas
filename = ARGV[0]
match_pattern = Regexp.compile(ARGV[1] || "")
accept_statuses = (ARGV[2] || "").split(',').map(&:to_i)
@slavone
slavone / 1.exs
Last active December 3, 2017 20:54
Advent of Code 2017 day two
input = """
3458 3471 163 1299 170 4200 2425 167 3636 4001 4162 115 2859 130 4075 4269
2777 2712 120 2569 2530 3035 1818 32 491 872 113 92 2526 477 138 1360
2316 35 168 174 1404 1437 2631 1863 1127 640 1745 171 2391 2587 214 193
197 2013 551 1661 121 206 203 174 2289 843 732 2117 360 1193 999 2088
3925 3389 218 1134 220 171 1972 348 3919 3706 494 3577 3320 239 120 2508
239 947 1029 2024 733 242 217 1781 2904 2156 1500 3100 497 2498 3312 211
188 3806 3901 261 235 3733 3747 3721 267 3794 3814 3995 3004 915 4062 3400
918 63 2854 2799 178 176 1037 487 206 157 2212 2539 2816 2501 927 3147
186 194 307 672 208 351 243 180 619 749 590
@slavone
slavone / task_one.exs
Last active December 3, 2017 17:08
Advent of Code 2017 Day One
input = """
4281224989975872839961169513979579335691369498483794171253625322698694611857431137339923313798564463624821296465562866115437565642757153598749248981134244727829747894643486262785329362288817862735862788865758282393667944292233174767223374243992399861536752759241133225618738143644513391869188134516852631928916271867698181287155957154445654445815146775218749359429135471217518516313733161224914715646977312989519895119172726843354634362182832619621586712666252991887645898145187935763756291638963496653129912857765951421462617922444757217829413647879689245378416985382884593551597839856381872546538518648745445848789991932426416118597567286346238534756384789237444715638456354681738241966843619342694594591242691968115129274426627615638243236217587858663914247786835991794478455959319285892559359532951119374312668153527813999672953893396261786641484155611753867259924697828887579425583621179386293691294397174274744168516281211916393556463942764518471311826524865614159428158187858845591934838781393518416333663
@slavone
slavone / validation_skipper.rb
Created November 29, 2017 14:38
Rails skip validation
module ValidationSkipper
def skips_validation(attribute, validator)
_validators[attribute]&.reject! { |v| v.is_a?(validator) }
_validate_callbacks.each do |callback|
next unless callback.raw_filter.is_a?(validator)
callback.raw_filter.attributes.delete(attribute)
end
end
end
@slavone
slavone / env_subst.sh
Last active May 1, 2017 10:14
basic static config templater in bash
#!/bin/sh
# Basic shell templater script for static configs in docker
# made to be run before container start inside entrypoint.sh
# reads $1 file, replaces all variables, enclosed into <%= VAR %>
# with values of env variable with that name
# writes the new file into $2
# Fails if any of the matched variables is empty
set -o errexit
@slavone
slavone / redis-dump.sh
Created February 10, 2017 08:14 — forked from zinovyev/redis-dump.sh
Redis dump in bash
#! /usr/bin/env bash
redis-cli KEYS "*" | awk "{print \"echo \\\"RESTORE \"\$1\" 0 \`redis-cli --csv DUMP \\\"\"\$1\"\\\"\` \\\" \"}" | bash > dump.bkp
# to restore use: cat dump.bkp | redis-cli