Skip to content

Instantly share code, notes, and snippets.

$('#image_image').change(function()
{
form=document.getElementById('new_image')
data=new FormData(form)
var xhr = new XMLHttpRequest();
xhr.open("POST", "images");
xhr.send(data);
});
def create
@post = Post.find_by_slug(params[:post_id])
@image = @post.images.build(params[:image])
if @image.save
respond_to do |format|
format.js
end
end
end
@kapkaev
kapkaev / 0. nginx_setup.sh
Created August 5, 2012 11:10 — forked from mikhailov/0. nginx_setup.sh
Nginx + secure pseudo-streaming
# Nginx can serve FLV/MP4 files by pseudo-streaming way without any specific media-server software.
# To do the custom build we use 2 modules: --with-http_secure_link_module --with-http_flv_module
# This module "secure-link" helps you to protect links from stealing away.
#
# NOTE: see more details at coderwall: http://coderwall.com/p/3hksyg
$ cd /usr/src
$ wget http://nginx.org/download/nginx-1.2.2.tar.gz
$ tar xzvf ./nginx-1.2.2.tar.gz && rm -f ./nginx-1.2.2.tar.gz
@kapkaev
kapkaev / 0. nginx_setup.sh
Created August 5, 2012 11:22 — forked from mikhailov/0. nginx_setup.sh
Nginx+Unicorn
# Nginx+Unicorn best-practices congifuration guide.
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
@kapkaev
kapkaev / gist:3952451
Created October 25, 2012 13:09 — forked from alloy/gist:1281203
ActiveRecord::Relation#merge example
class Edition < ActiveRecord::Base
scope :published, where(arel_table[:published_at].not_eq(nil))
scope :generated, where(arel_table[:generated_at].not_eq(nil))
scope :available, published.generated
end
class Magazine < ActiveRecord::Base
# This is where #merge works its magic, by allowing you to merge scopes from other models.
scope :with_available_editions, includes(:editions).merge(Edition.available)
end
@kapkaev
kapkaev / 0-readme.md
Created December 3, 2012 21:49 — forked from amrnt/0-readme.md
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@kapkaev
kapkaev / using-ruby-1.9.3-p327.md
Created December 3, 2012 21:49 — forked from juno/using-ruby-1.9.3-p327.md
Using ruby-1.9.3-p327 with ruby-env and ruby-build

Using ruby-1.9.3-p327 with ruby-env and ruby-build

Prerequisite

  • Mac OS X Mountain Lion (10.8.2)
  • Homebrew
  • readline
  • rbenv

Install or update ruby-build

@kapkaev
kapkaev / Gemfile
Created February 3, 2013 08:19 — forked from pirj/Gemfile
source 'https://rubygems.org'
gem 'sinatra'
gem 'sinatra-contrib', require: 'sinatra/streaming'
group :development do
gem 'thin'
gem 'pry-rails'
end
# Nginx+Unicorn best-practices congifuration guide. Now with SPDY!
# We use latest stable nginx with fresh **openssl**, **zlib** and **pcre** dependencies.
# Some extra handy modules to use: --with-http_stub_status_module --with-http_gzip_static_module
#
# Deployment structure
#
# SERVER:
# /etc/init.d/nginx (1. nginx)
# /home/app/public_html/app_production/current (Capistrano directory)
#
@kapkaev
kapkaev / zsh.md
Created June 18, 2013 20:24 — forked from tsabat/zsh.md

Getting zsh to work in ubuntu is weird, since sh does not understand the source command. So, you do this to install zsh

wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | zsh

and then you change your shell to zsh

chsh -s `which zsh`

and then restart