Skip to content

Instantly share code, notes, and snippets.

View mlitwiniuk's full-sized avatar

Maciej Litwiniuk mlitwiniuk

View GitHub Profile
def reorder
@menu_items = current_site.menu_items.by_position.all
respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @menu_items }
end
end
@mlitwiniuk
mlitwiniuk / carrierwave.rb
Created December 4, 2011 11:37
CarrierWave - video encoding with Voyeur - config/initializers/
dir = Rails.root.join('lib', 'carrierwave_processing')
$LOAD_PATH.unshift(dir)
Dir[File.join(dir, "*.rb")].each {|file| require File.basename(file) }
@mlitwiniuk
mlitwiniuk / video_uploader.rb
Created December 4, 2011 11:39
CarrierWave - video encoding with Voyeur - app/uploaders/
# encoding: utf-8
class VideoUploader < CarrierWave::Uploader::Base
include CarrierWave::VideoConverter
storage :file
version :mp4 do
process :encode_video => [:mp4]
def full_filename(for_file)
@mlitwiniuk
mlitwiniuk / video_converter.rb
Created December 4, 2011 11:40
CarrierWave - video encoding with Voyeur - lib/carrierwave_processing/
module CarrierWave
module VideoConverter
extend ActiveSupport::Concern
module ClassMethods
def encode_video(target_format)
process :encode_video => [target_format]
end
end
def encode_video(format='mp4')
@mlitwiniuk
mlitwiniuk / nginx_virtual_host
Created December 14, 2011 22:25 — forked from mrsweaters/nginx_virtual_host
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
upstream example-workers {
# fail_timeout=0 means we always retry an upstream even if it failed
# to return a good HTTP response (in case the Unicorn master nukes a single worker for timing out).
server unix:/tmp/example.co.uk.socket fail_timeout=0;
}
server {
listen 80; # default;
server_name example.co.uk;
root /home/example.co.uk/website/public;
@mlitwiniuk
mlitwiniuk / iam.permission
Created December 22, 2011 09:11
Amazon IAM user permission config for specific bucket
{
"Statement": [
{
"Action": [
"s3:ListAllMyBuckets"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::*"
},
{
@mlitwiniuk
mlitwiniuk / activesupport_load.rb
Created January 16, 2012 14:19
YAML in Rails - don't and do
json_object = ActiveSupport::JSON.decode(json_content)
@mlitwiniuk
mlitwiniuk / example-user.js
Created May 4, 2012 13:13 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9-_]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
@mlitwiniuk
mlitwiniuk / etc_init.d_unicorn_example.co.uk
Created August 26, 2012 19:48 — forked from rubysolo/etc_init.d_unicorn_example.co.uk
Ruby on Rails server setup on Ubuntu 11.04 with Nginx, Unicorn, Rbenv
#! /bin/bash
### BEGIN INIT INFO
# Provides: unicorn
# Required-Start: $local_fs $remote_fs $network $syslog
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the unicorn web server
# Description: starts unicorn