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
maxim /
Last active Nov 19, 2019
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:

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/

maxim / gh-dl-release
Last active Nov 9, 2019
Download assets from private Github releases
View gh-dl-release
#!/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.
View barewords.rb
def plain_text_receipt # => Runtime: 5 sec, Network Timeout
Thank you for your order!
Product: #{name} - #{price} # => 2 DB queries
Tax: #{tax_amount} # => 1 DB query, 1 API call
Total: #{total_amount} # => 2 DB queries, 1 API call
maxim / git.rake
Created Sep 12, 2009
Rake tasks for managing git plugins with submodules.
View git.rake
# Rake tasks for managing git plugins with submodules.
# These tasks aim to make life simpler by automating all the boring work.
# What you get:
# - complete git integration (all you need to know is install, uninstall and update)
# - complete github integration (only use author name + plugin name)
# - rails plugin hooks (install.rb/uninstall.rb) are taken care of
# Available commands:
maxim / ecto_batch_stream.ex
Last active Oct 1, 2019
Similar to Rails `find_each`, but for Elixir's Ecto, using Stream
View ecto_batch_stream.ex
defmodule EctoBatchStream do
import Ecto.Query, only: [from: 1, from: 2]
@batch_size 1000
# Example:
# query = from u in MyApp.User, select:
# stream =, query)
# stream |> Stream.take(3) |> Enum.to_list # => […]
maxim / task.yml
Created Jun 12, 2014
Adding github to known_hosts with ansible
View task.yml
- name: ensure is a known host
dest: /root/.ssh/known_hosts
create: yes
state: present
line: "{{ lookup('pipe', 'ssh-keyscan -t rsa') }}"
regexp: "^github\\.com"
maxim / react.rb
Created Jun 28, 2019
Extending react-rails with styled components support
View react.rb
# config/initializers/react.rb
Rails.configuration.react.server_renderer = do
def render_from_parts(before, main, after)
js_code = compose_js(before, main, after)
maxim / tm2iterm.rb
Created Jun 10, 2012
Convert TextMate themes into iTerm 2 color schemes.
View tm2iterm.rb
#!/usr/bin/env ruby
# This script is an astonishing feat of top notch
# rockstar craftsmanship. It totally uses artificial
# intelligence to extract colors out of tmTheme and
# build an itermcolors scheme file for iTerm2.
# I know this sounds crazy, but it actually knows
# approximately what colors should be used in the
# ANSI list, and tries to find nearest colors from
View key_authorization.rb
def authorize_key_for_root(config, *key_paths)
[*key_paths, nil].each do |key_path|
if key_path.nil?
fail "Public key not found at following paths: #{key_paths.join(', ')}"
full_key_path = File.expand_path(key_path)
if File.exists?(full_key_path)
config.vm.provision 'file',
View stream_ext.ex
defmodule StreamExt do
@doc """
Stream records from Ecto in batches.
Supported options are
* batch_size - how many rows to fetch at once
* strategy - either :offset or :id
* :offset - uses SQL offset to fetch pages of results
This is slower, but works for any query.
You can’t perform that action at this time.