Skip to content

Instantly share code, notes, and snippets.

Andrey Chernih andreychernih

Block or report user

Report or block andreychernih

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 gist:1016728
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
@andreychernih
andreychernih / application_controller.rb
Created Jun 22, 2011
devise force https for sign in and sign up routes
View application_controller.rb
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
@andreychernih
andreychernih / carrierwave.rb
Created Jul 1, 2011
Change image quality with carrierwave and mini_magick
View carrierwave.rb
# 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
@andreychernih
andreychernih / forum.rb
Created Jul 14, 2011
Mongoid counter cache
View forum.rb
class Forum
include Mongoid::Document
include Mongoid::Timestamps
field :posts_count, :type => Integer, :default => 0
has_many_related :posts
end
@andreychernih
andreychernih / avatar_uploader.rb
Created Aug 9, 2011
CarrierWave extension-aware remote file downloading
View avatar_uploader.rb
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
View ImageFilter.m
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
@andreychernih
andreychernih / nginx
Created Oct 4, 2011
nginx init script
View nginx
#!/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
@andreychernih
andreychernih / gist:1593447
Created Jan 11, 2012
Unicorn init script
View gist:1593447
#!/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
@andreychernih
andreychernih / config
Created Feb 28, 2012
SSH on steroids (~/.ssh/config)
View config
Host *
ControlPath ~/.ssh/master-socket/-%r@%h:%p
ControlMaster auto
ControlPersist 4h
@andreychernih
andreychernih / MY_Exceptions.php
Created Apr 3, 2012
CodeIgniter error notifications
View MY_Exceptions.php
<?php
class MY_Exceptions extends CI_Exceptions {
function My_Exceptions()
{
parent::CI_Exceptions();
}
function show_error($heading, $message, $template = 'error_general', $status_code = 500)
{
You can’t perform that action at this time.