Skip to content

Instantly share code, notes, and snippets.

View nazarhussain's full-sized avatar
🎯
Focusing

Nazar Hussain nazarhussain

🎯
Focusing
View GitHub Profile
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
@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
@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 / 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("</")
[
#!/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 / theme.css
Created October 15, 2015 20:21
jenkins-atlassian-theme
@-webkit-keyframes inprogress{0%{opacity:1}50%{opacity:.1}100%{opacity:1}}@-moz-keyframes inprogress{0%{opacity:1}50%{opacity:.1}100%{opacity:1}}Keyframes inprogress{0%{opacity:1}50%{opacity:.1}100%{opacity:1}}img[src$="blue.png"],img[src$="blue.gif"],img[src$="blue_anime.gif"],img[src$="yellow.png"],img[src$="yellow.gif"],img[src$="yellow_anime.gif"],img[src$="red.png"],img[src$="red.gif"],img[src$="red_anime.gif"],img[src$="grey.png"],img[src$="grey.gif"],img[src$="grey_anime.gif"],img[src$="disabled.png"],img[src$="disabled.gif"],img[src$="disabled_anime.gif"],img[src$="nobuilt.png"],img[src$="nobuilt.gif"],img[src$="nobuilt_anime.gif"],img[src$="aborted.png"],img[src$="aborted.gif"],img[src$="aborted_anime.gif"]{content:url('data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==');-webkit-border-radius:50%;-moz-border-radius:50%;padding:0;border-radius:50%;background:rgba(0,0,0,.1)}img[src*="blue.png"],img[src*="blue_anime.gif"]{background:#56a556!important}img[src*="yellow.png"],img[s
@nazarhussain
nazarhussain / node-http-parser.js
Created February 29, 2016 07:51 — forked from threez/node-http-parser.js
In this example I played with the internal node http parser. This might be useful to folks that have to parse HTTP manually. For more info look at: https://github.com/joyent/node/blob/master/lib/_http_client.js
var HTTPParser = process.binding('http_parser').HTTPParser;
var parser = require("http").parsers.alloc();
parser.reinitialize(HTTPParser.RESPONSE);
parser.onBody = function(body) {
console.log(body.toString());
}
parser.onIncoming = function(response) {
console.log(response.headers);
console.log(response.statusCode);
@nazarhussain
nazarhussain / heap_diff.rb
Created May 19, 2017 18:02
Ruby Heap Diff
require 'set'
require 'json'
if ARGV.length != 2
puts "Usage: detect_leaks [FIRST.json] [SECOND.json]"
exit 1
end
first_addrs = Set.new
second_addrs = Set.new
@nazarhussain
nazarhussain / pet_store_2_0.yml
Last active October 12, 2017 14:22
Swagger 2.0 vs OAS3.0
swagger: '2.0'
info:
description: This is a sample server Petstore server.
version: 1.0.0
title: Swagger Petstore
host: virtserver.swaggerhub.com
basePath: /nazarhussain/Swagger2/1.0.0
schemes:
# app/admin/email_previews.rb
ActiveAdmin.register_page 'Email Previews' do
content do
div '.'
end
sidebar 'Mail Previews' do
Dir['app/mailer_previews/*_preview.rb'].each do |preview_path|
preview_mailer = File.basename(preview_path, '.rb')