Po pierwsze must-have alias w systemie (~/.bashrc
lub ~/.zshrc
)
alias g="git"
deduplicate_queue = fn queue, offset -> | |
{_, deleted_count} = | |
Verk.Queue.range!(queue, offset) | |
|> Enum.reduce({MapSet.new(), 0}, fn job, {seen, deleted_count} -> | |
if MapSet.member?(seen, {job.class, job.args}) do | |
case Verk.Queue.delete_job(queue, job) do | |
{:ok, true} -> {seen, deleted_count + 1} | |
_ -> {seen, deleted_count} | |
end | |
else |
#!/usr/bin/env ruby | |
require 'optparse' | |
require 'json' | |
require 'net/http' | |
options = {} | |
OptionParser.new do |opts| | |
opts.banner = "Usage: es_bench.rb [options]" | |
opts.on("-c COUNT", "--count=COUNT", "Number of requests") do |count| |
# Usage: | |
# | |
# redis = Redis.new(url: ENV["REDIS_URL"]) | |
# keys = redis.scan_each(match: 'foo*', count: 1_000) | |
# keys.extend(EachWithProgress) | |
# | |
# keys.each_with_progress do |key| | |
# redis.del(key) | |
# end |
class Buffer | |
def initialize(size = 1_000, &blk) | |
@size = size | |
@callback = blk | |
@queue = [] | |
@lock = Mutex.new | |
end | |
def <<(object) | |
@lock.synchronize do |
require 'hashie_walker' # https://github.com/monterail/hashie_walker | |
require 'active_support/inflector' | |
hash = { | |
"CamelCased" => { | |
"AnotherOne" => { | |
"Foo" => "Bar", | |
"FooFooFoo" => "Dupa" | |
} | |
} |
This gist shows buggy behavior of ==
in Ruby 1.8.7. This affects case equality (===
) too because by default ===
calls ==
internally unless redefined in specific class (like Range
or Regexp
).
class A
def ==(other)
puts "In A: calling == against #{other}"
super
end
end
#!/usr/bin/env bash | |
if ! which openssl > /dev/null; then | |
echo Install openssl | |
exit 1 | |
fi | |
if ! which curl > /dev/null; then | |
echo Install curl | |
exit 1 |
#!/bin/bash | |
# Filter requests to Rails application by IP address | |
# | |
# Usage: | |
# tail -f log/production.log | log_filter.sh [IP] | |
# | |
# By default tries to obtain current IP address from $SSH_CLIENT or by querying http://ifconfig.me | |
if [[ $# -eq 0 ]]; then | |
if [[ -z $SSH_CLIENT ]]; then | |
ip=$(curl -s http://ifconfig.me) |
# Finds equilibrium index of a sequence. | |
# Returns equilibrium index or -1 if no equilibrium exists. | |
def equi(arr) | |
left = sums(arr) | |
right = sums(arr.reverse) | |
for i in 1..(arr.length) do | |
return (i-1) if left[i-1] == right[-i] | |
end | |
-1 |