Skip to content

Instantly share code, notes, and snippets.

View bisusubedi's full-sized avatar

Bishnu Subedi bisusubedi

View GitHub Profile
@bisusubedi
bisusubedi / rails-jsonb-queries
Created June 15, 2018 08:12 — 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")
@bisusubedi
bisusubedi / mongo_db_delete_records_older_than_date.js
Last active May 10, 2016 08:00
Mongo db delete records older than date
/* delete records one by one */
cutoff_time = new Date();
removed_count = 0
/* findOne is less expensive so its impact on live data will be minimal */
while((row = db.collection.findOne({deleted_at: null, created_at: { $lt: cutoff_time }})) != null){
db.collection.remove({_id: row['_id']});
removed_count += 1;
print('\r Deleted:'+ removed_count);
}
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
@bisusubedi
bisusubedi / cf_cycling_event.geojson
Last active August 29, 2015 13:56
CF Cycling Event Detail
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bisusubedi
bisusubedi / ruby_rescue_retry.rb
Created August 16, 2013 03:38
Ruby rescue retry
tries = 0
begin
raise JobNotFoundError
rescue JobNotFoundError
tries += 1
retry if tries <= 3
puts "No jobs found!"
end
@bisusubedi
bisusubedi / ruby_custom_exception.rb
Created August 15, 2013 06:03
Ruby Custom Exception
class JobNotFoundError < StandardError
attr_accessor :message
def initialize(message = "")
@message = message
end
def to_s
return super if message == ""
super + ": #{message}"
end