Skip to content

Instantly share code, notes, and snippets.

View a-chernykh's full-sized avatar

Andrey Chernykh a-chernykh

View GitHub Profile
@a-chernykh
a-chernykh / deploy.rb
Created August 1, 2012 11:46
Precompile only digest version of static assets (2 times faster compilation)
namespace :deploy do
namespace :assets do
task :precompile, :roles => assets_role, :except => { :no_release => true } do
run "cd #{latest_release} && #{rake} RAILS_ENV=#{rails_env} #{asset_env} assets:precompile:primary"
end
end
end
@a-chernykh
a-chernykh / default.rb
Created July 20, 2012 12:19
Easy way to edit configuration file with Chef
add_line = "config statement"
bash "add_to_config" do
code <<-EOH
grep '#{add_line}' /etc/config || echo '#{add_line}' >> /etc/config
EOH
end
@a-chernykh
a-chernykh / MY_Exceptions.php
Created April 3, 2012 13:54
CodeIgniter error notifications
<?php
class MY_Exceptions extends CI_Exceptions {
function My_Exceptions()
{
parent::CI_Exceptions();
}
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
@a-chernykh
a-chernykh / config
Created February 28, 2012 13:52
SSH on steroids (~/.ssh/config)
Host *
ControlPath ~/.ssh/master-socket/-%r@%h:%p
ControlMaster auto
ControlPersist 4h
@a-chernykh
a-chernykh / gist:1593447
Created January 11, 2012 06:53
Unicorn init script
#!/bin/sh
APP_ROOT=/var/www/current
PID=/var/www/current/tmp/pids/unicorn.pid
ENV=production
CMD="sudo -u ubuntu /opt/ruby-enterprise-1.8.7-2011.03/bin/bundle exec /opt/ruby-enterprise-1.8.7-2011.03/bin/unicorn_rails -E $ENV -c /var/www/current/config/unicorn.rb -D"
old_pid="$PID.oldbin"
cd $APP_ROOT || exit 1
@a-chernykh
a-chernykh / nginx
Created October 4, 2011 06:43
nginx init script
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
for (int i = 0; i < length; i += 4) {
blue = m_OriginalPixelBuf[i];
green = m_OriginalPixelBuf[i+1];
red = m_OriginalPixelBuf[i+2];
red = pow(red / 255.0f, 1.3f) * 255.0;
green = pow(green / 255.0f, 1.3f) * 255.0;
blue = pow(blue / 255.0f, 1.3f) * 255.0;
// Ensure that pixel is not more than 255
@a-chernykh
a-chernykh / avatar_uploader.rb
Created August 9, 2011 14:28
CarrierWave extension-aware remote file downloading
class AvatarUploader < CarrierWave::Uploader::Base
include CarrierWave::MiniMagick
def extension_white_list
model.skip_avatar_extension_check ? nil : %w(jpg jpeg gif png bmp)
end
end
@a-chernykh
a-chernykh / forum.rb
Created July 14, 2011 11:49
Mongoid counter cache
class Forum
include Mongoid::Document
include Mongoid::Timestamps
field :posts_count, :type => Integer, :default => 0
has_many_related :posts
end
@a-chernykh
a-chernykh / carrierwave.rb
Created July 1, 2011 12:50
Change image quality with carrierwave and mini_magick
# put this in config/initializers/carrierwave.rb
module CarrierWave
module MiniMagick
def quality(percentage)
manipulate! do |img|
img.quality(percentage)
img = yield(img) if block_given?
img
end
end