Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
@maxim
maxim / weird.rb
Last active August 29, 2015 13:57
class Foo
alias_method :bar,
def foo
:hello
end
end
Foo.new.bar # => :hello
@maxim
maxim / barney.rb
Last active December 29, 2015 11:59
Use case for refinements
module Barney
refine String do
def wait_for_it(ending)
replace(self + ending)
end
end
end
using Barney
"legen".wait_for_it "dary" # => "legendary"
@maxim
maxim / gist:6981675
Last active December 25, 2015 13:09
echo "девуш\xD0:" | selecta
/Users/max/Executables/selecta:124:in `=~': invalid byte sequence in UTF-8 (ArgumentError)
from /Users/max/Executables/selecta:124:in `block in matches'
from /Users/max/Executables/selecta:124:in `select'
from /Users/max/Executables/selecta:124:in `matches'
from /Users/max/Executables/selecta:144:in `render'
from /Users/max/Executables/selecta:134:in `render!'
from /Users/max/Executables/selecta:37:in `block in main'
from /Users/max/Executables/selecta:169:in `block in with_screen'
@maxim
maxim / rails_load_path_tips.md
Last active January 9, 2025 00:59
How to use rails load paths, app, and lib directories.

In Rails 3

NOTE: This post now lives (and kept up to date) on my blog: http://hakunin.com/rails3-load-paths

If you add a dir directly under app/

Do nothing. All files in this dir are eager loaded in production and lazy loaded in development by default.

If you add a dir under app/something/

+-----------------------+------------------+-----------------+
|                       | eager load paths | auto load paths |
+-----------------------+------------------+-----------------+
| Rails 3 (development) | auto loaded      | auto loaded     |
| Rails 4 (development) | auto loaded      | auto loaded     |
| Rails 3 (production)  | eager loaded     | auto loaded     |
| Rails 4 (production)  | eager loaded     | eager loaded    |
+-----------------------+------------------+-----------------+
>> def wat; 'wat' end
=> nil
>> wat = wat
=> nil
>> wat
=> nil
To workaround this elasticsearch issue while it's not merged yet:
https://github.com/elasticsearch/cookbook-elasticsearch/pull/103
1. Paste everything in recipe.rb into your recipe, AFTER including elasticsearch recipe
2. Replace MY_COOKBOOK with your cookbook name
3. Put elasticsearch.init.erb to the templates/default/elasticsearch.init.erb of your cookbook
When you run your runlist with this in place, it will fix things and restart elasticsearch.
require 'kitchen'
require 'tmpdir'
module Kitchen
class GzippedChefDataUploader < ChefDataUploader
def upload_path(scp, path, dir = File.basename(path))
if File.directory?(path)
tmp_root = Dir.mktmpdir('gzipped_chef_uploader')
gzip_path = "#{tmp_root}/#{dir}.tar.gz"
system "cd #{path} && tar -zcf #{gzip_path} ."
@maxim
maxim / .kitchen.yml
Last active February 21, 2018 21:32
A hack to easily launch and test multiple nodes with test kitchen 1.0
# We need each node defined as a separate platform in order to give them different ip addresses on the private network
---
driver_plugin: vagrant
driver_config:
require_chef_omnibus: true
box: opscode-ubuntu-12.04
box_url: https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box
@maxim
maxim / upload.sh
Created June 12, 2013 20:39
Install application cookbook into the kitchen
#!/usr/bin/env bash
die() {
echo >&2 "$@"
exit 1
}
[ "$#" -eq 1 ] || die "Single cookbook path argument required"
src_path=$1