Skip to content

Instantly share code, notes, and snippets.

Avatar

Janusz Mordarski januszm

View GitHub Profile
@januszm
januszm / ruby_benchmark.rb
Created Jul 9, 2020
Ruby quick benchmark
View ruby_benchmark.rb
# alternatively use benchmark/ips
n = 100_000
data = "..."
Benchmark.ips do |benchmark|
benchmark.report("include?") do
n.times { data.to_s.downcase.include?('windows') }
end
benchmark.report("match?") do
@januszm
januszm / wait_until.rb
Created Mar 30, 2019 — forked from metaskills/wait_until.rb
Never sleep() using Capybara!
View wait_until.rb
# Have you ever had to sleep() in Capybara-WebKit to wait for AJAX and/or CSS animations?
describe 'Modal' do
should 'display login errors' do
visit root_path
click_link 'My HomeMarks'
within '#login_area' do
fill_in 'email', with: 'will@not.work'
fill_in 'password', with: 'test'
@januszm
januszm / grafana.ini
Created Aug 7, 2018 — forked from xlson/grafana.ini
Modifying grafana.ini of a running docker container
View grafana.ini
[database]
log_queries = true
@januszm
januszm / convert_wkb_to_geojson.rb
Created Mar 15, 2018
Convert WKB data from PostGIS to GeoJSON
View convert_wkb_to_geojson.rb
result = ActiveRecord::Base.connection.execute("select * from my_shapes_table limit 1;")
shape = parser.parse result.values.first.last # .first row , .last column
RGeo::GeoJSON.encode(shape).to_json
# => "{\"type\":\"MultiPolygon\",\"coordinates\":[[[[...]]]]}"
View profiler_wrapper.rb
# Gemfile
# gem "ruby-prof"
# gem "ruby-prof-flamegraph"
# gem "stackprof"
require "ruby-prof"
require "stackprof"
module ProfilerWrapper
def self.stackprof(name)
@januszm
januszm / change_eb_ruby_version.sh
Last active Oct 5, 2021
Change Ruby minor version in AWS Elastic Beanstalk
View change_eb_ruby_version.sh
# Currently (2017/2018) it's not possible to change the Ruby 'minor' version (eg. 2.3 => 2.4) using the web console
# However, it's possible using the 'awscli' tool.
brew install awscli # pip install awscli
aws elasticbeanstalk update-environment \
--solution-stack-name "64bit Amazon Linux 2017.09 v2.6.1 running Ruby 2.4 (Puma)" \
--environment-name "myappenv1" --region "us-east-2" \
--version-label "app-1234-210000_120123"
# For Amazon Linux 2
@januszm
januszm / gist:d4ce6dc36a257960dd7acb5c6b1ef6e8
Created Dec 30, 2017 — forked from giannisp/gist:ebaca117ac9e44231421f04e7796d5ca
Upgrade PostgreSQL 9.6.5 to 10.0 using Homebrew (macOS)
View gist:d4ce6dc36a257960dd7acb5c6b1ef6e8
After automatically updating Postgres to 10.0 via Homebrew, the pg_ctl start command didn't work.
The error was "The data directory was initialized by PostgreSQL version 9.6, which is not compatible with this version 10.0."
Database files have to be updated before starting the server, here are the steps that had to be followed:
# need to have both 9.6.x and latest 10.0 installed, and keep 10.0 as default
brew unlink postgresql
brew install postgresql@9.6
brew unlink postgresql@9.6
brew link postgresql
@januszm
januszm / graphite_grafana.sh
Last active Jan 20, 2020 — forked from mmb/graphite_grafana.sh
graphite/statsd/grafana setup on new Amazon Linux instance
View graphite_grafana.sh
# graphite/statsd/grafana setup on new Amazon Linux instance
# add http://graphite/ to grafana as a data source
sudo su
yum update --assumeyes
yum install --assumeyes docker
service docker start
docker \
run \
@januszm
januszm / _mina_puma_apache.conf
Last active Jul 21, 2016
Deply Rails App with Puma and Apache via Mina
View _mina_puma_apache.conf
<VirtualHost *:80>
ServerName www.esdb.cn
ServerAlias esdb.cn
DocumentRoot /home/ubuntu/apps/xxx.com/current/public
<Directory /home/ubuntu/apps/xxx.com/current/public>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>