Skip to content

Instantly share code, notes, and snippets.

View a-chernykh's full-sized avatar

Andrey Chernykh a-chernykh

View GitHub Profile
84091/0x9c28d: 29323312 20 7 mmap(0x0, 0x82000, 0x3, 0x1002, 0x3000000, 0x100000001) = 0x7760000 0
libSystem.B.dylib`__mmap+0xa
libSystem.B.dylib`large_malloc+0x471
libSystem.B.dylib`szone_malloc_should_clear+0xd3e
libSystem.B.dylib`szone_realloc+0x844
libSystem.B.dylib`malloc_zone_realloc+0x5c
libSystem.B.dylib`realloc+0xa9
ruby`ruby_xrealloc+0x86
ruby`str_buf_cat+0xcf
@a-chernykh
a-chernykh / application_controller.rb
Created June 22, 2011 19:43
devise force https for sign in and sign up routes
class ApplicationController < ActionController::Base
before_filter :ensure_proper_protocol
protected
def ssl_allowed_action?
(params[:controller] == 'users/sessions' && ['new', 'create'].include?(params[:action])) ||
(params[:controller] == 'users/registrations' && ['new', 'create', 'edit', 'update'].include?(params[:action])) ||
(params[:controller] == 'users/omniauth_callbacks')
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
@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 / 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
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 / 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
@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 / 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 / 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)
{