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
Problem AWS DigitalOcean
Network isolation Private Cloud/Security Groups tinc / n2n / freelan
Node initialization CloudInit/User Data ?
Node discovery EC2 API Serf
Pull app on scale More Like This Serf
Distributed config etcd etcd

Upon launch of custom base box intended as app behind load balancer:

  1. [serf] join cluster, update lists
  2. update local iptables
  3. [serf] announce presence (already part of step 1?)
  4. provision self (chef/ansible/docker/etc)
  5. pull app (deploy to self from git, deb, docker, could be part of step 4?)
  6. [serf] announce online
# Permissions cheatsheet
`chmod [a]bcd`
* bit a — sticky:1/setgid:2/setuid:4 (optional, default: 0)
* bit b — owner | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
* bit c — group | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
* bit d — everyone | x:1/w:2/r:4 - xw:3/xr:5/wr:6/xwr:7
note: only file/dir owner can chmod it
@maxim
maxim / deps.rb
Created July 7, 2014 14:59
Show role hierarchy for Ansible
#!/usr/bin/env ruby
require 'yaml'
PLAYS_DIR = '.'
ROLES_DIR = './roles'
def deps_of(role)
dep_path = File.join(ROLES_DIR, "#{role}/meta/main.yml")
File.exists?(dep_path) ? (YAML.load_file(dep_path)['dependencies'] || []) : []
from jinja2 import contextfilter
class FilterModule(object):
''' Extra filters '''
def filters(self):
return {
'percent_of': self.percent_of,
'of_ram': self.of_ram
}
@maxim
maxim / bug.rb
Last active August 29, 2015 14:03
Rails bug
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rack', github: 'rack/rack'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
INFO[7bdf78e4] Running /usr/bin/env /home/deployer/deploy.sh on util1.example.org
DEBUG[7bdf78e4] Command: /usr/bin/env /home/deployer/deploy.sh
DEBUG[7bdf78e4] fetching
DEBUG[7bdf78e4] fetching
DEBUG[7bdf78e4] From github.com:example/example
DEBUG[7bdf78e4] fetching
DEBUG[7bdf78e4] 36d03e8..52fa872d feature/foo -> origin/feature/foo
DEBUG[7bdf78e4] fetching
DEBUG[7bdf78e4] 4372c38..79bba2b master -> origin/master
DEBUG[7bdf78e4] HEAD is now at 79bba2b Merge pull request #111 from example/fix/bar
class ApplicationController
helper_method :current_copywriting
def current_copywriting
@current_copywriting ||= Copywriting.find_by_request(request)
end
end
module SomeHelpers
def header_text
# {{ ansible_managed }}
require 'puma_worker_killer'
daemonize false
directory '/srv/{{ app_name }}'
threads {{ puma_threads_min }}, {{ puma_threads_max }}
workers {{ ansible_processor_vcpus }}
bind 'unix:///var/run/{{ app_name }}/{{ app_name }}.sock'
prune_bundler