Skip to content

Instantly share code, notes, and snippets.

View artificemm's full-sized avatar
🥋
Training

Roberto Ruiz artificemm

🥋
Training
View GitHub Profile
@artificemm
artificemm / semantic-commit-messages.md
Created September 29, 2023 00:12 — forked from joshbuchea/semantic-commit-messages.md
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@artificemm
artificemm / rails-jsonb-queries
Created August 30, 2023 08:28 — forked from mankind/rails-jsonb-queries
Ruby on 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")
# 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]))
@artificemm
artificemm / navigable.rb
Created March 26, 2021 06:55
Nice navigation between records module
module Navigable
extend ActiveSupport::Concern
def next
self.class.where("id > ?", self.id).order(id: :asc).first
end
def previous
self.class.where("id < ?", self.id).order(id: :desc).first
end
@artificemm
artificemm / tinnova.rb
Last active March 31, 2021 22:08
Tinnova first set of exercises
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) {

Pry Cheat Sheet

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 session

Debugger

@artificemm
artificemm / gist:f5b66dce0c5ef6b5af6788023104b88b
Created March 28, 2019 16:19
Instrucciones para instalar Ruby en Linux(Debian/RedHat)
--- 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
@artificemm
artificemm / SOLID.markdown
Created February 22, 2017 21:13 — forked from emaraschio/SOLID.markdown
SOLID Principles with ruby examples

#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.

@artificemm
artificemm / loadJson.js
Created September 11, 2016 01:33 — forked from pwittchen/loadJson.js
Loading JSON file with JavaScript. Please note: it won't run as a "local" script. JavaScript does not allow to load local files due to security reasons. You should deploy it on the server in order to load JSON file.
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);
}