This file contains 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
module Mongoid | |
module CounterCache | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# Use Case: | |
# | |
# keep a cached count of embedded collections in the parent collection(s) | |
# | |
# for example, if a Post embeds many Comments, and there have been 2 |
This file contains 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
module MyProject | |
module Mongoid | |
module Document | |
extend ActiveSupport::Concern | |
included do | |
include ::Mongoid::Document | |
include ::Mongoid::Timestamps | |
include ::Mongoid::DotNotation | |
include ::Mongoid::SearchForObject | |
end |
This file contains 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
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 |
This file contains 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
[ | |
["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()"], |
This file contains 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
#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 |
This file contains 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
#!/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 |
This file contains 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
method | validation | callbacks | |
---|---|---|---|
save | ✔ | ✔ | |
save(validate: false) | ✘ | ✔ | |
update | ✔ | ✔ | |
update_attribute | ✘ | ✔ | |
update_attributes | ✔ | ✔ | |
update_all | ✘ | ✘ | |
set(for mongoid only) | ✘ | ✘ |
This file contains 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
{ | |
"AP":[ | |
"Adilabad", | |
"Anantapur", | |
"Chittoor", | |
"Kakinada", | |
"Guntur", | |
"Hyderabad", | |
"Karimnagar", | |
"Khammam", |
This file contains 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
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 |
This file contains 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
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) |