Skip to content

Instantly share code, notes, and snippets.

View lucianghinda's full-sized avatar

Lucian Ghinda lucianghinda

View GitHub Profile
@lucianghinda
lucianghinda / benchmark_ruby_array_bsearch.rb
Created September 7, 2022 06:51
Benchmark Ruby Array#bsearch
# frozen_string_literal: true
require "benchmark"
require "benchmark/ips"
array = Array.new(1000) { Random.rand(100) }.sort
n = 50_000
Benchmark.bmbm do |benchmark|
benchmark.report("bsearch") do
# Code Summary
# 📖 https://paweldabrowski.com/articles/public-private-and-protected-in-ruby
# Part 1/5: Common way of defining private methods
class Person
def name; end
private
def age; end
@lucianghinda
lucianghinda / testing-and-op.rb
Created April 21, 2022 04:35
What does ruby && operator return
# nil and Truthy => nil
x = nil
y = Object.new
puts "when x=#{x.class} and y=#{y.class} then x && y returns #{(x && y).inspect} => x"
x = nil
y = true
puts "when x=#{x.class} and y=#{y.class} then x && y returns #{(x && y).inspect} => x"
# nil and falsy => nil
@lucianghinda
lucianghinda / using-include-vs-extend.rb
Created March 22, 2022 04:03
Example of using include and extend in Ruby
module WithInstanceMethod
def whoami
puts self.inspect
end
end
class One
include WithInstanceMethod
end
@lucianghinda
lucianghinda / .licensed.yml
Created July 26, 2020 20:06
Example of .licensed.yml file to be used with licensed gem
sources:
bundler: true
npm: true
allowed:
- mit
- apache-2.0
- bsd-2-clause
- bsd-3-clause
- isc
@lucianghinda
lucianghinda / .verify-licenses.yml
Created July 26, 2020 20:03
Github Actions Workflow to verify if included packages licenses are allowed
name: Verify Licenses
on: [push]
jobs:
licenses:
name: Verify Gem Licenses
runs-on: ubuntu-latest
@lucianghinda
lucianghinda / .vimrc
Created July 3, 2020 08:28
VIM Plugins useful for Ruby on Rails + Vue/Stimulus + TailwindCSS
" Please go through Readmine for every plugin and add needed configuration
Plug 'itchyny/lightline.vim'
Plug 'airblade/vim-gitgutter'
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-rails'
Plug 'ngmy/vim-rubocop'
Plug 'vim-ruby/vim-ruby'
@lucianghinda
lucianghinda / .licensed.yml
Last active June 22, 2020 14:02
Example of Licensed configuration file sample for a Ruby on Rails project
sources:
bundler: true
allowed:
- mit
- apache-2.0
- bsd-2-clause
- bsd-3-clause
- isc
- cc0-1.0
@lucianghinda
lucianghinda / signup.spec.js
Created February 24, 2020 09:30
Test Case for verifying signup form with valid data - written in Javascript using Cypress.io
/// <reference types="Cypress" />
const faker = require("faker");
describe("Signup", function() {
it("it should work with valid data", function() {
let first_name = faker.name.firstName();
let password = faker.random.uuid();
let date = new Date();
let timestamp = date.getTime();
let email = "first_name@" + faker.internet.domainName();
@lucianghinda
lucianghinda / signup_test.exs
Last active February 24, 2020 09:26
Test Case for verifying Signup Form with valid data - written in Elixir
defmodule SignupTest do
use ExUnit.Case
use Hound.Helpers
alias Ecto.Adapters.SQL.Sandbox
hound_session()
setup do
:ok = Sandbox.checkout(App.Repo)