Skip to content

Instantly share code, notes, and snippets.

View sagarbommidi's full-sized avatar

Sagar Bommidi sagarbommidi

View GitHub Profile
#!/bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@sagarbommidi
sagarbommidi / class_eval_trick.rb
Last active December 15, 2015 12:29
Tricks and tips for meta programming in Ruby
# Usage of class_eval method
class Sample
end
s = Sample.new
Sample.class_eval do
def say_hello

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "[email protected]"
@sagarbommidi
sagarbommidi / rspec_model_testing_template.rb
Created February 7, 2016 19:21 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
D, [2016-07-26T20:14:20.297579 #48336] DEBUG -- : SOLR Request (7.3ms) [ path=select parameters={fq: ["type:Artist", "({!join from=artist_id_i to=id_i}show_name_s:Sample OR {!join from=artist_id_i to=id_i}show_time_d:[* TO 2016-05-20T21:00:00Z])"], start: 0, rows: 30, q: "*:*"} ]
RSolr::Error::Http: RSolr::Error::Http - 400 Bad Request
Error: 'org.apache.solr.search.SyntaxError: Cannot parse \'show_time_d:[*\': Encountered "<EOF>" at line 1, column 14.
URI: http://localhost:8982/solr/development/select?wt=ruby
Request Headers: {"Content-Type"=>"application/x-www-form-urlencoded; charset=UTF-8"}
Request Data: "fq=type%3AArtist&fq=%28%7B%21join+from%3Dartist_id_i+to%3Did_i%7Dshow_name_s%3ASample+OR+%7B%21join+from%3Dartist_id_i+to%3Did_i%7Dshow_time_d%3A%5B*+TO+2016%5C-05%5C-20T21%5C%3A00%5C%3A00Z%5D%29&start=0&rows=30&q=*%3A*"
Backtrace: /Users/sagarb/.rvm/gems/ruby-2.2.2@magnifi_gt/gems/rsolr-1.1.1/lib/rsolr/client.rb:288:in `adapt_response'
/Users/sagarb/.rvm/gems/ruby-2.2.2@magnifi_gt/gems/rsolr-1.1.1/
class Array
def my_map
result = []
return to_enum :my_map unless block_given?
each { |s| result << yield(s) }
result
end
end
a = [1, 2, 3, 4]
class Array
def my_map
return to_enum :my_map unless block_given?
inject([]) { |result, value| result << yield(value) }
end
end
a = [1, 2, 3, 4]
b = a.my_map do |x|
x + 1
class Seat
attr_accessor :person
def initialize(position)
@position = position
@person = nil
end
end
class AirPlane
attr_reader :seating_matrix
@sagarbommidi
sagarbommidi / remove_log_files.rb
Created November 20, 2018 02:33
It will find all the log files from the specified folder recursively and also their size, and asks the user whether to delete it or not.
require 'find'
def format_mb(size)
conv = [ 'b', 'kb', 'mb', 'gb', 'tb', 'pb', 'eb' ];
scale = 1024;
ndx = 1
if( size < 2*(scale**ndx) )
return "#{(size)} #{conv[ndx-1]}"
end