Skip to content

Instantly share code, notes, and snippets.

View ipvalverde's full-sized avatar

Israel Valverde ipvalverde

View GitHub Profile
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
# Use Rails directly from GitHub (main branch - nightly/edge)
gem "rails", github: "rails/rails", branch: "main"
#!/usr/bin/env ruby
# frozen_string_literal: true
# Reproduces a database deadlock in Rails with PostgreSQL/MySQL
#
# This script creates two threads that update records in opposite order,
# reliably causing a database deadlock.
#
# Usage:
# ruby deadlock_bug_report.rb
# Small simplification on the CSV part II blog post - https://www.sitepoint.com/guide-ruby-csv-library-part-2/
# Original code in the blog post
def load_guests
CSV.open('guests.csv', headers:true) do |guest|
guests = guest.each
guests.select do |row|
row['Times arrived'].to_i > 10
end
end
@ipvalverde
ipvalverde / read-string-to-array.cs
Created September 30, 2018 21:19
Read Console string converting to int array
int[] ar = Console.ReadLine()
.Split(' ')
.Where(token => !string.IsNullOrWhiteSpace(token))
.Select(token => Convert.ToInt32(token))
.ToArray();