Skip to content

Instantly share code, notes, and snippets.

View coolsnow02's full-sized avatar

Neha Gujar coolsnow02

  • Cleartrip
  • India
View GitHub Profile
@coolsnow02
coolsnow02 / contiguous_sub_array_problem.rb
Created December 17, 2015 12:08
contiguous sub-array problem
class ContiguousSubArrayProblem
def initialize
puts 'Enter the elements in the array (comma separated)'
@arr = gets.chomp.split(',').map { |val| val.to_i }
puts 'Largest sub-array'
puts 'start index (default - 0) :'
@start_index = gets.chomp.to_i rescue 0
puts 'sub-array length (default - 3) :'
@coolsnow02
coolsnow02 / libxml-ruby
Created March 17, 2015 12:42
libxml-ruby installation work around
rvm pkg libxml2
bundle config build.libxml-ruby \
--with-xml2-lib=${HOME}/.rvm/usr/lib \
--with-xml2-include=${HOME}/.rvm/usr/include/libxml2
@coolsnow02
coolsnow02 / print.js.coffee
Created August 7, 2013 12:17
coffeescript to print a selected div on a page.
$(".print_page").click ->
divToPrint = document.getElementById("divToPrint")
popupWin = window.open("", "_blank", "width=300,height=300")
popupWin.document.open()
head = $("head")
popupWin.document.write "<html><head>"+head.html()+"</head><body onload=\"window.print()\">" + divToPrint.innerHTML + "</html>"
popupWin.document.close()
#Command to force restart a rails server in case of Webbrick server not being shut down properly.
rails s -p3001 -P tmp/pids/server2.pid
@coolsnow02
coolsnow02 / coffee_stylesheet.rb
Last active December 18, 2015 02:39
helper method to create controller wise coffeescript files and stylesheets.
# app/helpers/application_helper.rb
#Add these to your application.haml file...
# = stylesheet_link_tag controller_stylesheet if controller_stylesheet
# = javascript_include_tag controller_asset if controller_asset
def controller_asset
js = params[:controller]
Rails.application.assets.find_asset(params[:controller]+".js") || Rails.application.assets.find_asset(params[:controller]+".js.coffee") ? js : nil
end
@coolsnow02
coolsnow02 / activity_log.rb
Last active December 18, 2015 00:28
Using Observer for logging activities/changes on selected attributes of a model. In this case - logging creation/updation of address model and selected attributes of profile model of a parking lot.
# *app/models/activity_observer.rb
def after_create(profile)
person = (current_person || Admin.new(email: "console@dpr.com"))
ActivityLog.create(performer: person, target: profile, action: "create", description: "%s has created a Parking Lot Profile named %s", change: "profile") if profile.kind_of? ParkingLotProfile
end
#Note: Creates an entry in the ActivityLog on updating name, address, contact number, allocated spots and pricings of a Parking Lot Profile
def after_update(obj)
changes = obj.changes.map{|i, v| i}
# 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|
<virtualhost *:80>
ServerName app.com
ServerAlias www.app.com
DocumentRoot /var/www/html/blog/public # <-- be sure to point to 'public'!
setenv RAILS_ENV production
<Directory /var/www/html/blog/public>
AllowOverride All
RailsEnv production
</Directory
ErrorLog /var/log/apache2/blog_error_log
<% flash.each do |type, message| %>
<div class="alert <%= bootstrap_class_for(type) %> fade in">
<button class="close" data-dismiss="alert">×</button>
<%= message %>
</div>
<% end %>
# MySQL. Versions 4.1 and 5.0 are recommended.
#
# Install the MySQL driver:
# gem install mysql2
#
# And be sure to use new-style password hashing:
# http://dev.mysql.com/doc/refman/5.0/en/old-client.html
development:
adapter: mysql2
encoding: utf8