This file contains hidden or 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
| There is no way to store an empty object/array/null value. | |
| There are also no actual arrays. Array values get stored as objects with integer keys. | |
| (If all keys are integers, it will be returned as an array.) | |
| Basically, it's one giant tree of hashes with string keys. | |
| Simply write a value to any location, and the intermediary locations will automatically come into existance. | |
| ── Classes ── | |
| DataSnapshot : Container for a subtree of data at a particular location. |
This file contains hidden or 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
| repo(){ | |
| cd "$HOME/Dropbox/Personal/src/$1" | |
| echo -en "\033]0;$1\a" | |
| PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]${PWD#/home/ofer/Dropbox/Personal/src/}\[\033[01;33m\] \$ \[\033[00m\]' | |
| } |
This file contains hidden or 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 self.configure_class(table:, filter: {}, &block) | |
| ds = db[table] | |
| ds = ds.filter filter unless filter.blank? | |
| ds = ds.filter &block if block_given? | |
| set_dataset(ds) | |
| fixture_keys.each { |k| FixtureDependencies.class_map[k] = self } | |
| end | |
| def self.fixture_keys | |
| # PorcIO::ID::Models::User -> [ :user, :porc_io/id/models/user ] |
This file contains hidden or 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 'colorize' | |
| class CLogger < Logger | |
| def info(message) | |
| color = case message | |
| when Regexp.union(%w[CREATE ALTER DROP]) | |
| :light_blue | |
| when Regexp.union(%w[INSERT UPDATE DELETE]) | |
| :light_yellow | |
| else |
This file contains hidden or 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
| # (I recommend understanding the basics of this first: http://sequel.jeremyevans.net/rdoc/files/doc/object_model_rdoc.html) | |
| # Extending the underlying dataset (http://sequel.jeremyevans.net/rdoc/files/README_rdoc.html#label-Extending+the+underlying+dataset) | |
| # The recommended way to implement table-wide logic by defining methods on the dataset using dataset_module: | |
| class Post < Sequel::Model | |
| dataset_module do | |
| def posts_with_few_comments | |
| where{num_comments < 30} |
This file contains hidden or 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
| class ModelBase | |
| # depends on Dirty plugin: http://www.rubydoc.info/gems/sequel/Sequel/Plugins/Dirty | |
| def validates_unchanged(attribute) | |
| errors.add(attribute, 'cannot be modified') if !new? and column_changed?(attribute) | |
| end | |
| end | |
| class Model < ModelBase | |
| def validate | |
| validates_unchanged :username |
This file contains hidden or 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
| irb(main):010:0> Sequel::Model.instance_eval do | |
| irb(main):011:1* def fixture_key | |
| irb(main):012:2> singularize(underscore(demodulize(name))).to_sym | |
| irb(main):013:2> end | |
| irb(main):014:1> end | |
| => :fixture_key | |
| irb(main):015:0> Sequel::Model.fixture_key | |
| => :model |
This file contains hidden or 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
| root@a16708715370:/tmpdev# ruby -e 'puts $LOADED_FEATURES.sort' | |
| /usr/local/lib/ruby/2.2.0/monitor.rb | |
| /usr/local/lib/ruby/2.2.0/unicode_normalize.rb | |
| /usr/local/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so | |
| /usr/local/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so | |
| /usr/local/lib/ruby/2.2.0/x86_64-linux/rbconfig.rb | |
| /usr/local/lib/ruby/2.2.0/x86_64-linux/thread.so | |
| /usr/local/lib/ruby/site_ruby/2.2.0/rubygems.rb | |
| /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/basic_specification.rb | |
| /usr/local/lib/ruby/site_ruby/2.2.0/rubygems/compatibility.rb |
This file contains hidden or 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
| class MembershipLevel | |
| include Comparable | |
| include ActiveModel::Validations | |
| ## Constants | |
| MONTHLY = 10 | |
| ANNUAL = 20 | |
| LIFETIME = 30 |
This file contains hidden or 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
| d = moment('2015-03-01') | |
| Object { _isAMomentObject: true, _i: "2015-03-01", _f: "YYYY-MM-DD ", _isUTC: false, _pf: Object, _locale: Object, _d: Date 2015-03-01T05:00:00.000Z } | |
| d.format('YYYY-MM-DD') | |
| "2015-03-01" |