Skip to content

Instantly share code, notes, and snippets.

View coolsnow02's full-sized avatar

Neha Gujar coolsnow02

  • Cleartrip
  • India
View GitHub Profile
@vparihar01
vparihar01 / server_static_assets_with_nginx.conf
Created July 10, 2014 18:31
Its very costly to server assets from application server like Passenger or Unicorn or Puma. In this case we would prefer to server our statics directly from nginx. This will help application performance and decrease down the memory consumption.
# if the request is for a static resource, nginx should serve it directly
location ~ ^/(images|javascripts|stylesheets|system|assets|jwplayer)/* {
root /var/www/www.example.com/current/public;
add_header Last-Modified "";
add_header ETag "";
expires max;
break;
}
@vparihar01
vparihar01 / sanitize_params.rb
Created April 26, 2013 05:38
Controllers should sanitize params before performing any other logic.
class ExampleController < ActionController::Base
def create
Example.create(sanitized_params)
end
def update
Example.find(params[:id]).update_attributes!(sanitized_params)
end
protected
# gem install taglib-ruby
# http://robinst.github.io/taglib-ruby/
require 'taglib'
require 'fileutils'
module Musix
def self.extract(dir, tag_name)
Dir.foreach(dir) do |x|
file = (dir.split("").last=="/" ? dir : dir+"/") + x
if !File.directory?(file) && file.match(/.mp3$/)
TagLib::FileRef.open(file) do |fr|
@roberto
roberto / _flash_messages.html.erb
Created August 13, 2012 22:47
Rails flash messages using Twitter Bootstrap
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>