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
# Generate the models Estado and Cidade: | |
# rails generate Estado sigla:string nome:string | |
# rails generate Cidade estado:references nome: string | |
# rails db:migrate | |
# Put this code on your db/seeds.rb of your Ruby On Rails application | |
# rails db:seed | |
Estado.destroy_all |
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
# https://stackoverflow.com/a/43522719 + couple of fixes | |
def number_to_words(num) | |
numbers_to_name = { | |
10_000_000 => "crore", | |
100_000 => "lakh", | |
1000 => "thousand", | |
100 => "hundred", | |
90 => "ninety", | |
80 => "eighty", |
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
// This file is automatically compiled by Webpack, along with any other files | |
// present in this directory. You're encouraged to place your actual application logic in | |
// a relevant structure within app/javascript and only use these pack files to reference | |
// that code so it'll be compiled. | |
require("@rails/ujs").start() | |
require("turbolinks").start() | |
require("@rails/activestorage").start() | |
require("channels") | |
require("./application.scss") |
Setting this up took quite a bit of time and research for me, so just thought of sharing the learnings along the way that led to a working setup.
-
Initial error that I was getting with running System tests in Rails 6
System test integration requires Rails >= 5.1 and has a hard dependency on a webserver and `capybara`, please add capybara to your Gemfile and configure a webserver (e.g. `Capybara.server = :webrick`) before attempting to use system tests.
- since the error above says specify
Capybara
in the Gemfile, a part of my Gemfile looked like below:
- since the error above says specify
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 TreeNode | |
attr_accessor :value, :left, :right | |
def initialize(value) | |
@value = value | |
@left = nil | |
@right = nil | |
end | |
end |
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
// source - https://www.hackerrank.com/challenges/new-year-chaos/problem | |
// video - https://youtu.be/vfcALtCXAwQ | |
function minimumBribes(q) { | |
const TOO_CHAOTIC = "Too chaotic"; | |
let total = 0; | |
for(let current_pos = 0; current_pos < q.length; current_pos++){ // O(n) | |
// getting original position using 0 indexing (starts at 0) | |
const original_pos = q[current_pos] - 1; | |
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
<section x-data="{showModal: false, showLoading: false, html: ''}"> | |
<button | |
@click="html='loading...'; showLoading = true; showModal = !showModal; | |
fetch('{{ entry.url }}', { | |
method: 'GET', | |
headers: { | |
'X-Requested-With': 'XMLHttpRequest', | |
}, | |
}) |
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
# config/initializers/datadog.rb | |
require 'ddtrace' | |
require 'redis' | |
Datadog::Tracer.log = Logger.new(nil) | |
# This is the port we have configured in the /etc/datadog/datadog.yml (apm_config) | |
Datadog.tracer.configure(port: 9126, enabled: true) | |
# TODO: change me |