Skip to content

Instantly share code, notes, and snippets.


Max Chernyak maxim

Block or report user

Report or block maxim

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View weird.rb
class Foo
alias_method :bar,
def foo
end # => :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
maxim / task.yml
Created Jun 10, 2014
ansible task for ensuring postgresql extension exists without skipping or perpetual "changed"
View task.yml
- name: ensure postgresql hstore extension is created
sudo: yes
sudo_user: postgres
shell: "psql {{ postgresql_database }} -c 'CREATE EXTENSION hstore;'"
register: psql_result
failed_when: >
psql_result.rc != 0 and ("already exists" not in psql_result.stderr)
changed_when: "psql_result.rc == 0"
View permissions_cheatsheet.txt
# 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
from jinja2 import contextfilter
class FilterModule(object):
''' Extra filters '''
def filters(self):
return {
'percent_of': self.percent_of,
'of_ram': self.of_ram
maxim / deps.rb
Created Jul 7, 2014
Show role hierarchy for Ansible
View deps.rb
#!/usr/bin/env ruby
require 'yaml'
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'] || []) : []
maxim / bug.rb
Last active Aug 29, 2015
Rails bug
View bug.rb
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source ''
gem 'rack', github: 'rack/rack'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
system 'bundle'
View gist:102892c03a7f4a34c61e
INFO[7bdf78e4] Running /usr/bin/env /home/deployer/ on
DEBUG[7bdf78e4] Command: /usr/bin/env /home/deployer/
DEBUG[7bdf78e4] fetching
DEBUG[7bdf78e4] fetching
DEBUG[7bdf78e4] From
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
View example.rb
class ApplicationController
helper_method :current_copywriting
def current_copywriting
@current_copywriting ||= Copywriting.find_by_request(request)
module SomeHelpers
def header_text
You can’t perform that action at this time.