Skip to content

Instantly share code, notes, and snippets.

View crashtech's full-sized avatar
🛰️
Creating magic method by method

Carlos crashtech

🛰️
Creating magic method by method
View GitHub Profile
@crashtech
crashtech / bundle.log
Created August 14, 2015 12:15
Rbx-head (2.5.2) rake with clang++ (3.4.2) error.
[2015-08-14 01:29:48] /usr/local/rvm/wrappers/ruby-2.2.2@rubinius/bundle
current path: /usr/local/rvm/src/rbx-head
PATH=/usr/local/rvm/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
command(2): /usr/local/rvm/wrappers/ruby-2.2.2@rubinius/bundle install
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on
this machine.
Using rake 10.4.2
Using daedalus-core 0.5.0
Using redcard 1.1.0
Using rubinius-ast 2.3.2
@crashtech
crashtech / flatten.rb
Created February 14, 2017 19:53
Array flatten
# Transform a possible multi-dementional array into one-dimentional array
# It returns nil if the giver argument is not an array
def flatten(arr)
return nil unless arr.is_a?(::Array)
# Store the extracted values in the result
result = []
# Iterate over the elements appending or merging the parts
arr.each do |part|
@crashtech
crashtech / rvm-trace.txt
Last active April 12, 2017 03:13
RVM Trace erro CD
+ 1491966648.266378976 /scripts/cli : __rvm_parse_args() 749 > [[ -z '' ]]
+ 1491966648.271087905 /scripts/cli : __rvm_parse_args() 749 > [[ -n '' ]]
+ 1491966648.275022367 /scripts/cli : __rvm_parse_args() 752 > [[ error == '' ]]
+ 1491966648.278861310 /scripts/cli : __rvm_parse_args() 752 > [[ 0 -eq 1 ]]
+ 1491966648.282690210 /scripts/cli : __rvm_parse_args() 752 > [[ -n '' ]]
+ 1491966648.286148429 /scripts/cli : __rvm_parse_args() 15 > [[ -n use ]]
+ 1491966648.289327313 /scripts/cli : __rvm_parse_args() 17 > rvm_token=use
+ 1491966648.292945688 /scripts/cli : __rvm_parse_args() 19 > (( 1 > 0 ))
+ 1491966648.296664270 /scripts/cli : __rvm_parse_args() 21 > next_token=/home/poc.myadmin.dev/
+ 1491966648.300582448 /scripts/cli : __rvm_parse_args() 22 > shift
SELECT "orders"."id" AS t0_r0,
"orders"."customer_id" AS t0_r1,
"orders"."vendor_id" AS t0_r2,
"orders"."billing_address_id" AS t0_r3,
"orders"."shipping_address_id" AS t0_r4,
"orders"."status" AS t0_r5,
"orders"."partner_order_number" AS t0_r6,
"orders"."created_at" AS t0_r7,
"orders"."updated_at" AS t0_r8,
"orders"."description" AS t0_r9,
@crashtech
crashtech / cosine_distance.rb
Last active August 31, 2018 09:09
Similarity algorithms
def cosine_distance(this, that)
return 1.0 if this === that
a_vector = Hash.new(0).tap{ |v| this.each{ |e| v[e] += 1 } }
b_vector = Hash.new(0).tap{ |v| that.each{ |e| v[e] += 1 } }
a_mag = 0.0
product = a_vector.inject(0.0) do |total, (key, value)|
a_mag += value ** 2
total += value * b_vector[key]
@crashtech
crashtech / google-data-studio.sql
Created February 14, 2019 19:20
Google Data Studio Stories
SELECT "stories"."id" AS "Id",
"stories"."title" AS "Title",
"stories"."publication_id" AS "Publication Id",
"publications"."name" AS "Publication Name",
"story_authors"."authors" AS "Authors",
"stories"."date" AS "Date",
"stories"."media_type" AS "Media Type",
"stories"."url" AS "URL",
"stories"."length" AS "Length",
"stories"."solutions_3" AS "Solutions 3",
@crashtech
crashtech / RoR, from MVC to GraphQL.md
Last active May 29, 2023 22:42
RoR, from MVC to GraphQL

Ruby on Rails, from MVC to GraphQL

As a Ruby on Rails developer, I'm always looking for the best tools and practices to apply to my day-to-day development. This framework has a fantastic structure where all its inner parts communicate very well. But, as applications start growing, or developers want to start using more modern technologies, several things start getting out of control.

Recent versions of Rails implemented Webpack, facilitating the use of modern JavaScript frameworks, which added another level of robustness to everyone's applications. Not only is this becoming the new standard, but it also enables bigger code-bases without falling into madness.

Facebook, as the creator of ReactJS (one of these modern JS frameworks and the most popular one) introduced to the world another of its technologies, GraphQL. This tool, like any other tool, can be a great asset, as long as it's in the right hands, meaning that you first need to know what role it plays before exploring how to use it in your RoR appli

# app/models/topic.rb
class Topic < ApplicationRecord
self.table_name = 'topic'
## Associations
has_many :posts
## Validations
validates :name, presence: true
end
@crashtech
crashtech / find_aunt.rb
Created October 22, 2020 19:21
Able code interview
CHECKERS = {
'cats' => :>,
'trees' => :>,
'pomeranians' => :<,
'goldfish' => :<,
}
def find_aunt(criteria, input)
input.scan(/Sue (\d+): (.*)\n/).find do |(number, data)|
break number if data.scan(/(\w+): (\d+)/).all? do |(item, value)|
Small Crunchy Finger Basket
{"ref":"MenuItem:06129e99-923f-4e0d-8863-f4f295b5f419","id_field":"guid","pos_active":true,"title":"Small Crunchy Finger Basket","price":9.55,"image_url":"https://s3.amazonaws.com/toasttab/restaurants/restaurant-26036000000000000/menu/items/3/item-400000004246731573_1582403485.jpg","description":"3 fingers with 1 sauce and french fries.","tax_rate":15.5,"observation_flags":{"suspend_until_flags":{"sold_out_in_pos":"observed"},"alcohol_problems":{"observed_missing_alcohol_state_from_pos":"observed"}}}
Classic Fries
{"ref":"MenuItem:a9537c02-dc72-45a2-bddd-a8da9af5263d","id_field":"guid","pos_active":true,"title":"Classic Fries","price":4.45,"image_url":"https://s3.amazonaws.com/toasttab/restaurants/restaurant-26036000000000000/menu/items/2/item-400000004249845722_1582410894.jpg","description":"3/8th\" straight cut fries with crispy batter.","tax_rate":15.5,"observation_flags":{"suspend_until_flags":{"sold_out_in_pos":"observed"},"alcohol_problems":{"observed_missing_alcohol_state_f