This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) :' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rvm pkg libxml2 | |
bundle config build.libxml-ruby \ | |
--with-xml2-lib=${HOME}/.rvm/usr/lib \ | |
--with-xml2-include=${HOME}/.rvm/usr/include/libxml2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(".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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# *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} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% flash.each do |type, message| %> | |
<div class="alert <%= bootstrap_class_for(type) %> fade in"> | |
<button class="close" data-dismiss="alert">×</button> | |
<%= message %> | |
</div> | |
<% end %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
NewerOlder