See how a minor change to your commit message style can make you a better programmer.
Format: <type>(<scope>): <subject>
<scope> is optional
| 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") |
| # from_cte_sql = ::Namespace::From.where_clause | |
| # .. | |
| from_table = Arel::Table.new(:from_lane) | |
| to_table = Arel::Table.new(:to_lane) | |
| rates_table = Arel::Table.new(:rates) | |
| rates_table | |
| .join(from_table).on(rates_table[:from_id].eq(from_table[:id])) |
| require 'set' | |
| # Solved exercises | |
| # Roberto Ruiz | |
| # For Tinnova | |
| # 1: | |
| input = [{ "name": 'eggs', "price": 1 }, { "name": 'coffee', "price": 9.99 }, { "name": 'rice', "price": 4.04 }] | |
| def sort_hash_by_price(ary) |
| function calculateDistance(rssi) { | |
| var txPower = -59 //hard coded power value. Usually ranges between -59 to -65 | |
| if (rssi == 0) { | |
| return -1.0; | |
| } | |
| var ratio = rssi*1.0/txPower; | |
| if (ratio < 1.0) { |
Command Line
pry -r ./config/app_init_file.rb - load your app into a pry session (look at the file loaded by config.ru)pry -r ./config/environment.rb - load your rails into a pry sessionDebugger
| --- Debian | |
| sudo apt-get --ignore-missing install build-essential git-core curl openssl libssl-dev libcurl4-openssl-dev zlib1g zlib1g-dev libreadline6-dev libyaml-dev libsqlite3-dev libsqlite3-0 sqlite3 libxml2-dev libxslt1-dev libffi-dev software-properties-common libgdm-dev libncurses5-dev automake autoconf libtool bison postgresql postgresql-contrib libpq-dev pgadmin3 libc6-dev nodejs -y | |
| curl -sSL https://rvm.io/mpapis.asc | gpg --import - | |
| curl -sSL https://get.rvm.io | bash -s stable | |
| source ~/.rvm/scripts/rvm | |
| rvm install 2.6.2 | |
| rvm use 2.6.2 --default |
#SOLID Principles with ruby examples
##SRP - Single responsibility principle A class should have only a single responsibility.
Every class should have a single responsibility, and that responsibility should be entirely encapsulated. All its services should be narrowly aligned with that responsibility, this embrace the high cohesion.
##OCP - Open/closed principle Software entities should be open for extension, but closed for modification.
| function loadJson(callback) { | |
| var XmlHttpRequest = new XMLHttpRequest(); | |
| XmlHttpRequest.overrideMimeType("application/json"); | |
| XmlHttpRequest.open('GET', 'file.json', true); | |
| XmlHttpRequest.onreadystatechange = function () { | |
| if (XmlHttpRequest.readyState == 4 && XmlHttpRequest.status == "200") { | |
| // .open will NOT return a value | |
| // but simply returns undefined in async mode so use a callback | |
| callback(XmlHttpRequest.responseText); | |
| } |