Skip to content

Instantly share code, notes, and snippets.

View rishiip's full-sized avatar
🎯
Focusing

Rishi Pithadiya rishiip

🎯
Focusing
View GitHub Profile
module MyProject
module Mongoid
module Document
extend ActiveSupport::Concern
included do
include ::Mongoid::Document
include ::Mongoid::Timestamps
include ::Mongoid::DotNotation
include ::Mongoid::SearchForObject
end
@rishiip
rishiip / .irbrc
Last active May 20, 2020 07:40
This is my current irbrc file which contains lots of helpful things.
require 'irb/completion'
require 'rubygems'
ActiveRecord::Base.logger.level = 1 if defined?(ActiveRecord)
IRB.conf[:SAVE_HISTORY] = 1000
# IRB.conf[:ECHO] = false
# Overriding Object class
class Object
# Easily print methods local to an object's class
@rishiip
rishiip / kb.json
Created September 17, 2019 09:37 — forked from pkaminski/gist:1ea3df5301660ddc5b12
Custom key bindings for Reviewable
[
["n", "Next unreviewed file", "nextUnreviewedFile()"],
["p", "Previous unreviewed file", "prevUnreviewedFile()"],
["shift+n", "Next file", "nextFile()"],
["shift+p", "Previous file", "prevFile()"],
["x", "Mark file as reviewed / unreviewed", "toggleCurrentFileReviewed(); nextUnreviewedFile()"],
["j", "Next unreplied comment", "nextUnrepliedDiscussion()"],
["k", "Previous unreplied comment", "prevUnrepliedDiscussion()"],
["shift+j", "Next comment", "nextDiscussion()"],
["shift+k", "Previous comment", "prevDiscussion()"],
@rishiip
rishiip / gist:2eeef32fb087c0ecc18136df3c1f89b8
Created September 14, 2019 15:57 — forked from paulallies/gist:0052fab554b14bbfa3ef
Remove node_modules from git repo
#add 'node_modules' to .gitignore file
git rm -r --cached node_modules
git commit -m 'Remove the now ignored directory node_modules'
git push origin master
@rishiip
rishiip / install.sh
Created July 31, 2019 06:13 — forked from maanavshah/install.sh
Install and Configure Ruby on Rails, MongoDB, PostgreSQL, Git, Sublime Text, Oh-my-zsh and Deepin on Ubuntu
#!/bin/bash
sudo apt-get update
# To make sure we have everything necessary for Webpacker support in Rails, we're first going to start by adding the Node.js and Yarn repositories to our system before installing them.
sudo apt-get install curl
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update
method validation callbacks
save
save(validate: false)
update
update_attribute
update_attributes
update_all
set(for mongoid only)
@rishiip
rishiip / IndianCities.json
Created March 10, 2016 06:11 — forked from rishi-amura/IndianCities.json
Indian States and their Cities
{
"AP":[
"Adilabad",
"Anantapur",
"Chittoor",
"Kakinada",
"Guntur",
"Hyderabad",
"Karimnagar",
"Khammam",
@rishiip
rishiip / bson.rb
Created March 10, 2016 06:11 — forked from rishi-amura/bson.rb
Return mongo `_id` bson object as regular `id` within Rails application
Save below code to `bson.rb` file within `config/initializers` directory and restart the server
module BSON
class ObjectId
def as_json(*args)
to_s
end
end
end
def get_array_max(one_dim_array)
one_dim_array.inject([0, 0]) do |(max_so_far, max_up_to_here), x|
new_max_up_to_here = [max_up_to_here + x, 0].max
new_max_so_far = [max_so_far, new_max_up_to_here].max
[new_max_so_far, new_max_up_to_here]
end.first
end
sample = [-2, 1, -3, 4, -1, 2, 1, -5, 4]
p get_array_max(sample)
@rishiip
rishiip / gist:bd36c65f85031e66ee56
Created December 8, 2015 11:08 — forked from mistrikushal/Rspec private methods.txt
RSpec - Testing private methods of a model
# RSpec allows us to test private methods of a model.
for example,
class User
def is_active?
true
end
private :is_active?
end