Skip to content

Instantly share code, notes, and snippets.

View piclez's full-sized avatar

Peter WD piclez

View GitHub Profile
# 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
@nitishparkar
nitishparkar / number_to_words.rb
Created June 27, 2020 14:57
Convert a number into english words (Indian numbering system) in ruby
# 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",
@usutani
usutani / application.js
Last active January 17, 2021 04:43
Tailwind CSSの習作: Rails scaffold.scssの移植
// 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")
@boddhisattva
boddhisattva / setup_system_tests_with_rspec_devise_rails6.md
Last active November 9, 2023 20:58
Setup System tests to work with RSpec, Devise and Rails 6

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:
@wyy1234567
wyy1234567 / bst.rb
Created May 5, 2020 03:39
this is my implementation of binary search tree in Ruby
class TreeNode
attr_accessor :value, :left, :right
def initialize(value)
@value = value
@left = nil
@right = nil
end
end
// 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;
@terryupton
terryupton / modal.twig
Last active March 31, 2025 09:55
Ajax Loading a page into a modal with Alpine JS
<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',
},
})
@huladesign
huladesign / datepicker-with-tailwindcss-and-alpinejs.markdown
Created April 7, 2020 22:40
Datepicker with TailwindCSS and AlpineJS
@kigster
kigster / datadog.rb
Created February 21, 2020 22:18
Datadog Rails Configuration
# 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