Skip to content

Instantly share code, notes, and snippets.

View maxim's full-sized avatar
🛠️

Max Chernyak maxim

🛠️
View GitHub Profile
@maxim
maxim / gh-dl-release
Last active March 29, 2024 16:41
Download assets from private Github releases
#!/usr/bin/env bash
#
# gh-dl-release! It works!
#
# This script downloads an asset from latest or specific Github release of a
# private repo. Feel free to extract more of the variables into command line
# parameters.
#
# PREREQUISITES
#
@maxim
maxim / gist:1b88e10527b282022510
Last active August 29, 2015 14:23
Pin your monkey patches to certain gem version in rails
# in an early initializer
def PinMonkeypatch!(gem_name, expected_version)
if gem_spec = Gem.loaded_specs[gem_name]
actual_version = gem_spec.version.to_s
if actual_version != expected_version
raise "Monkeypatch for #{gem_name} requires version "\
"#{expected_version}, but current version is #{actual_version}"
end
else
@maxim
maxim / rails_autoload_issue.rb
Last active August 29, 2015 14:21
Problem with Rails autoload and classes used for directory namespacing
# If you have the following setup, Rails autoload will depend on load order in a hard-to-trace way:
# app/models/foo.rb
class Foo
def initialize(arg)
@arg = arg
end
end
# app/models/foo/bar.rb
# {{ 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
class ApplicationController
helper_method :current_copywriting
def current_copywriting
@current_copywriting ||= Copywriting.find_by_request(request)
end
end
module SomeHelpers
def header_text
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
@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'
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 / 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'] || []) : []
@maxim
maxim / tasks.yml
Created June 26, 2014 21:02
How to recursilvely chmod dirs and files (separately) with Ansible, without always seeing "changed" status.
- name: ensure all dir permissions are set correctly
shell: find /my/dir -type d -print0 | xargs -0 chmod -c 2755
register: chmod_result
changed_when: "chmod_result.stdout != \"\""
- name: ensure all file permissions are set correctly
shell: find /my/dir -type f -print0 | xargs -0 chmod -c 0650
register: chmod_result
changed_when: "chmod_result.stdout != \"\""