Skip to content

Instantly share code, notes, and snippets.

View nazarhussain's full-sized avatar
🎯
Focusing

Nazar Hussain nazarhussain

🎯
Focusing
View GitHub Profile
#!/bin/bash
# Author: Chmouel Boudjnah <[email protected]>
# Not officially supported by Rackspace only as a best effort basis :)
# Define yes to make it to copy to url to clipboard (via a shortened url
# service) You need to have the software xclip installed in your system.
COPY_URL_TO_CLIPBOARD=yes
# Containers to ignore in the list
CONTAINERS_TO_IGNORE=".CDN_ACCESS_LOGS"
@nazarhussain
nazarhussain / check_boxes_with_hints.rb
Created August 29, 2012 21:02
Custom Collection Inputs Simple Form
module SimpleForm
class FormBuilder
def collection_check_boxes_with_hints(attribute, collection, value_method, text_method, options={}, html_options={})
rendered_collection = render_collection(
collection, value_method, text_method, options.merge({:item_wrapper_tag => nil}), html_options
) do |item, value, text, default_html_options|
default_html_options[:multiple] = true
builder = instantiate_builder(SimpleForm::ActionViewExtensions::CheckBoxBuilder, attribute, item, value, text, default_html_options)
label = builder.label(:class => 'inline checkbox checkbox_with_hints').split("</")
[
@nazarhussain
nazarhussain / sha1.rb
Created February 8, 2012 05:59
Custom Encryptor for Devise
module Devise
module Encryptors
class Sha1
def self.digest(password, user_salt)
string_to_hash = password + "abcdefgh" + user_salt
Digest::SHA1.hexdigest(string_to_hash)
end
def self.salt(username)
self.object_id.to_s + rand.to_s
@nazarhussain
nazarhussain / Readme
Created June 22, 2011 13:29
Enable conditional default_url for Paperclip, to set default url with some method in the model
In some cases you need to set the default_url of paper clip base on some condition. e.g. You want to set default image on basis of gender of user. For this purpose this gist can make it possible to use a method as default_url. Just copy paper_clip_default_url_fix.rb to initializers folder, and use default_url as mentioned in model.rb
module DataListHelper
def list_headers(args=[])
args = Array.new(args)
columns = []
args.map { |o| columns << content_tag(:li, o.split(":").first, :style=>"width:#{o.split(":").second}px;") }
content_tag(:ul, columns.join(" ").html_safe, :class=>"list-headers")
end
def data_list_for(object, headers=[], &block)
if object.is_a? Array