Skip to content

Instantly share code, notes, and snippets.

View nyku's full-sized avatar

Nicolae Rotaru nyku

  • Chisinau, Moldova
View GitHub Profile
@nyku
nyku / resize_convert.sh
Last active August 1, 2024 22:38
Resize & Convert image -> webp
#!/bin/bash
# Usage:
# ./resize_and_convert.sh ~/Desktop/folder-with-images
# Check if the correct number of arguments is provided
if [ "$#" -ne 1 ]; then
echo "Usage: $0 source_path"
exit 1
fi
@nyku
nyku / rate_limit.rb
Created February 9, 2021 14:32
Simple rails rate limiter
require 'redis'
require 'digest'
class RateLimit
def initialize(app)
@app = app
end
def call(env)
redis = Redis.new
@nyku
nyku / benchmark_ezmetrics.rb
Created November 24, 2019 10:37
EZmetrics benchmark
require 'ezmetrics'
require 'benchmark'
require 'active_support/time'
def write_metrics(start, redis, seconds)
redis.flushdb
seconds.times do |i|
second = start - i
payload = {
@nyku
nyku / phoenix_vs_kemal.log
Last active March 7, 2017 22:56
Kemal vs phoenix [NO database interaction]
➜ work sh siege.sh
-------------------------------ELIXIR--------------------------------
** SIEGE 3.0.5
** Preparing 600 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 66070 hits
Availability: 100.00 %
Elapsed time: 9.82 secs
@nyku
nyku / siege.sh
Last active June 16, 2016 08:25
Siege stress test
# -c: 10 concurrent requests
# -r: 2 attempts
# -b: benchmark mode
# -v: verbose mode
# -H: header
# GET
siege -c 10 \
-r 2 \
-b \
@nyku
nyku / specs.sh
Created December 3, 2015 10:03
Run specs
ruby -e 'p `git status`.split("\n").select {|l|l.match("modified")}.map {|l|l.gsub(/\tmodified:\s+|app\/|\.rb/, "")}.delete_if {|l|l.match(/scss|yml|haml|_spec/)}.map {|l|"spec/#{l}_spec.rb"}.join(" ")' | xargs echo | xargs rspec
[
{
"name": "Afghanistan",
"code": "AF"
},
{
"name": "Albania",
"code": "AL"
},
{
@nyku
nyku / simple_serializer.rb
Created September 11, 2013 09:15
Simple way of testing ActiveModel Serializers
class SimpleSerializer < ActiveModel::Serializer
attributes :name, :code
end
@nyku
nyku / books
Last active December 18, 2015 13:09
kakto tak
### Ruby
Refactoring Ruby Edition
Ruby Best Practices
The RSpec Book
Design Patterns in Ruby
### Ruby on Rails
The Rails Way