Skip to content

Instantly share code, notes, and snippets.

View rajbacharya's full-sized avatar

Nataraja B rajbacharya

  • rajsoft
  • Bangalore
View GitHub Profile
@rajbacharya
rajbacharya / hash_deep_diff.rb
Created December 12, 2019 15:00 — forked from henrik/hash_deep_diff.rb
Recursively diff two Ruby hashes.
# Recursively diff two hashes, showing only the differing values.
# By Henrik Nyh <http://henrik.nyh.se> 2009-07-14 under the MIT license.
#
# Example:
#
# a = {
# "same" => "same",
# "diff" => "a",
# "only a" => "a",
# "nest" => {
@rajbacharya
rajbacharya / flatten_hash.rb
Last active September 25, 2019 12:04 — forked from abhishek77in/flatten_hash.rb
Flatten ruby hash, Could be used to convert nested ruby hash (or json) to csv
def flatten_hash(hash, results = {}, parent_key = '')
return results unless hash.kind_of?(Hash)
hash.keys.each do |key|
# current_key = "#{parent_key}[#{key}]" # uncomment this if you want to keep parent key as a partof key for flattened hash (csv column name)
current_key = key
if hash[key].kind_of?(Hash)
results = flatten_hash(hash[key], results, current_key)
else
if hash[key].kind_of?(Array)
@rajbacharya
rajbacharya / rails-jsonb-queries
Created June 18, 2019 14:46 — forked from mankind/rails-jsonb-queries
Rails-5 postgresql-9.6 jsonb queries
http://stackoverflow.com/questions/22667401/postgres-json-data-type-rails-query
http://stackoverflow.com/questions/40702813/query-on-postgres-json-array-field-in-rails
#payload: [{"kind"=>"person"}]
Segment.where("payload @> ?", [{kind: "person"}].to_json)
#data: {"interest"=>["music", "movies", "programming"]}
Segment.where("data @> ?", {"interest": ["music", "movies", "programming"]}.to_json)
Segment.where("data #>> '{interest, 1}' = 'movies' ")
Segment.where("jsonb_array_length(data->'interest') > 1")
@rajbacharya
rajbacharya / Errors Recieved
Created October 26, 2017 07:18 — forked from anonymous/Errors Recieved
Puma Sidekiq Configuration
With the size: attribute in your configure_* blocks removed =
ERROR: heartbeat: ERR max number of clients reached
app[worker.1]: 3 TID-ormcs1tts ERROR: ERR max number of clients reached
with the size attribute = " Sidekiq seems to run normally but mailers not moving from in enqueued.
# app/assets/javascripts/welcome.js.coffee
$ ->
$(document).on 'change', '#countries_select', (evt) ->
$.ajax 'update_cities',
type: 'GET'
dataType: 'script'
data: {
country_id: $("#countries_select option:selected").val()
}
@rajbacharya
rajbacharya / Procfile
Created July 21, 2017 09:42 — forked from winston/Procfile
Heroku + Rails + Sidekiq 4.0 Config
web: bundle exec puma -C config/puma.rb -p $PORT
worker: bundle exec sidekiq -e $RAILS_ENV -q default -q mailers
# By default, sidekiq only operates on the `default` queue
# So if you do `Mailer.new(...).deliver_later`, those are queued to the `mailers` queue
# Hence you need to explicitly tell Sidekiq to operate on `mailers` queue too
# You can also put this into sidekiq.yml
@rajbacharya
rajbacharya / rails-console.sh
Created April 3, 2017 18:06 — forked from clok/rails-console.sh
ElasticBeanstalk Rails Console and Rake Task Runners
#!/usr/bin/env bash
#
# Rails console script that can be run on AWS Elastic Beanstalk.
#
# Run this script from the app dir (/var/app/current) as root (sudo script/rails-console)
#
set -xe
EB_SCRIPT_DIR=$(/opt/elasticbeanstalk/bin/get-config container -k script_dir)
@rajbacharya
rajbacharya / gist:1681d163e9c310f7f1368391baad1772
Created March 15, 2017 08:41 — forked from trcarden/gist:3295935
Rails 3.2.7 SSL Localhost (no red warnings, no apache config)
# SSL self signed localhost for rails start to finish, no red warnings.
# 1) Create your private key (any password will do, we remove it below)
$ openssl genrsa -des3 -out server.orig.key 2048
# 2) Remove the password
$ openssl rsa -in server.orig.key -out server.key
@rajbacharya
rajbacharya / rails.rb
Created March 15, 2017 06:12
Use SSL in Rails development. First: to create a local SSL certificate and start a SSL webserver checkout *shell.sh*. Second: to configure Rails checkout *rails.rb*
# To enable SSL in Rails you could now simply use *force_ssl* in your
# ApplicationController but there is two more things to think about:
# In development our SSL webserver is running on port 3001 so we would
# actually need to use *force_ssl port: 3001* but then this wouldn't
# work for production.
# Also there is a good chance you might not always want to use SSL in development
# so it would be nice if we could just enable or disable SSL in the config.
# To make all this work first copy the file *ssl_with_configured_port.rb* to
# your *lib* directory. Second to enable SSL add *config.use_ssl = true*