Skip to content

Instantly share code, notes, and snippets.

View ixti's full-sized avatar
😂
forever blowing bubbles

Alexey Zapparov ixti

😂
forever blowing bubbles
View GitHub Profile
class ExampleJob < ApplicationJob
STEPS = [
{ :band => "The Baboon Show" },
{ :band => "Blowfuse" },
{ :band => "CRIM" }
].each(&:freeze).freeze
def perform(options)
time = Time.at(options.fetch(:timestamp))
@ixti
ixti / lint_rubocop_config.rake
Created August 8, 2019 16:35
Rubocop configs linter.
namespace :lint do
task :rubocop_config do
errors = []
Dir[File.expand_path("../../../config/rubocop/*.yml", __dir__)].each do |f|
config = Psych.parse_file(f)&.children&.first
unless config.is_a? Psych::Nodes::Mapping
errors << "Invalid config: #{f}"
next
@ixti
ixti / bm.rb
Last active August 7, 2019 14:26
Benchmark Ruby string interpolations
# frozen_string_literal: true
require "benchmark/ips"
NAMED_TPL = "$%<value>d"
POSITIONAL_TPL = "$%d"
VALUE = 123.456
VALUE_PARAMS = { :value => VALUE }.freeze
Benchmark.ips do |x|
FILES_RE = %r{^(app|config|lib)/.*\.(rb|yml)$}
IO.popen(["git", "ls-files"]) do |io|
io.each_line do |file|
puts file if FILES_RE.match?(file)
end
end
IO.popen(["bundler", "list", "--paths"]) do |bundler_io|
bundler_io.each_line.to_a.each do |path|
@ixti
ixti / shellcheck-wrapper
Last active October 25, 2018 22:15
Simple shellcheck wrapper
#!/bin/bash
files=()
args=()
hashbang_regexp="^#\\!(/bin/|/usr/bin/env )?(sh|tcsh|csh|dash|bash)"
function lookup() {
while IFS= read -d $'\0' -r file; do
if [[ "${file}" =~ ^.*\.(ba|c|da|tc|z)?sh$ ]] \
|| head "${file}" -n 1 | grep -E -q "${hashbang_regexp}"; then
module AutocorrectThruDisableCuzWeSuckAtWritingGoodCode
def autocorrect(node)
->(corrector) do
until autocorrect_on.include? node&.type
node = node&.parent
return unless node
end
lines = node.source.lines
match = lines[0].match(/^(.*?)\s*((?<!\\)#(.*))?$/)
#!/usr/bin/env bash -x
# Creates RAM disk.
#
# SYNOPSIS
# create_ramdisk [size [label]]
#
# OPTIONS
# size: RAM disk size in megabytes. Default: 1024
# label: RAM disk volume label. Default: UUID
#!/usr/bin/ruby
$TESTING = false # rubocop: disable Style/GlobalVars
require "bundler/setup"
require "sidekiq/cli"
begin
cli = Sidekiq::CLI.instance
cli.parse
Codegen (bc+obj): 00:41:40.1161902 (1098.87MB)
Codegen (linking): x86_64-pc-linux-gnu-gcc -o "/var/tmp/portage/dev-lang/crystal-0.22.0/work/crystal-0.22.0/.build/crystal" "${@}" -Wl,-O1 -Wl,--sort-common -Wl,--as-needed -rdynamic /var/tmp/portage/dev-lang/crystal-0.22.0/work/crystal-0.22.0/src/llvm/ext/llvm_ext.o `/usr/bin/llvm-config --libs --system-libs --ldflags 2> /dev/null` -lstdc++ -lpcre -lm -lgc -lpthread /var/tmp/portage/dev-lang/crystal-0.22.0/work/crystal-0.22.0/src/ext/libcrystal.a -levent -lrt -ldl -L/usr/lib -L/usr/local/lib _main.o
fork: Cannot allocate memory
0x540b4e: ??? at ??
0x10fda55: ??? at ??
0x14fffc7: ??? at ??
0x14fef65: ??? at ??
0x1437a08: ??? at ??
0x1cb6645: ??? at ??
0x5a23f9: ??? at ??
@ixti
ixti / hstruct.rb
Last active January 23, 2017 22:29
Human-friendly Struct :D
module HStruct
def self.new(**props)
attrs = props.map { |s| ":#{s}" }.join(", ")
init = attrs.map { |s| "@#{s} = #{s}" }.join("\n")
args = props.map { |s| "#{s}: nil" }.join(", ")
Class.new do
class_eval <<-RUBY
attr_accessor #{attrs.map { |s| ":#{s}" }.join ", "}
def initialize(#{args})