Skip to content

Instantly share code, notes, and snippets.

View karmatr0n's full-sized avatar

Alejandro Juárez karmatr0n

View GitHub Profile
@karmatr0n
karmatr0n / .sql
Last active January 18, 2025 00:58
.psqlrc
\set ON_ERROR_ROLLBACK interactive
\set COMP_KEYWORD_CASE upper
\set HISTFILE ~/.psql_history- :USER - :HOST - :PORT - :DBNAME
\set PROMPT1 '%M:%[%033[1;31m%]%>%[%033[0m%] %n@%/%R%#%x '
\pset pager off
\pset null '(null)'
@karmatr0n
karmatr0n / .gemrc
Created January 17, 2025 19:13
.gemrc
---
# The paths in which to look for gems
# :gempath:
# Force specification of gem server host on push
# disable_default_gem_server:
# A YAML array of remote gem repositories to install gems from
# :sources:
@karmatr0n
karmatr0n / .irbrc
Last active January 18, 2025 15:04
irbrc
def load_gems!
%w[irb/completion irb/history irb/color rubygems].each do |gem|
require gem
end
return unless Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.7.0')
require 'irb/easter-egg'
end
@karmatr0n
karmatr0n / http_redirect.tgz
Created November 10, 2023 13:32
Http Redirect based on Rack
H4sIANouTmUAA+1aQW/bNhT2BgzDuPN25rqDXaChKYqSbAPO4CRuEyBJMyfdGhRFIMu0LUSWHEqKkxYbdtxp52HXAbvuPOx37LjjjvsPIyXLiby4TgDFbW19gSL5ie/xUdR77yPtfhAMTzjr2JxZQblwL8AYG5oGo7MenzGh8XkMqFCNqJQYKtEhVqhh4ALU7sedNEI/MLlw5dTkAzPg2J3RTjTrdt9gZzyOyfk9QT81/+jE8tyu3UM8zLAP8Tx0SmfPP6FqPP8qxbqhifk3MCEFiDP0YSZWfP4LH33+ceHDQmHPtODTQ/gcjiFlhU/EQcRxJg75+dfbmWwcHbXGl1LjZ3F8OtXkgyv5Z5Y3QOZw6DA05N45c03XYrLBH/v//P3TL789z2CQOWYhHf8H5sU2MzuMl7PMA3PjX8Hp+CdY00T+v8ig77lY8fhXMRwE9oDVFb1a1apUr2jIoFWjQg2FAs2Auzsbjdbm9s43TXRhBgFHN4VrvfF1oxE+Mxz1WDeHTg/QKjwUSrvHb1K6FuPgbT+HVUU6/u+j+s+PfyyE6fqv69jI6/8iwNlZKOZevAKOGdjnDBZTb0QR8NCF20LUGkuQy0Zv2+kcmWGa/6c+I97Ooo9b839KdAUTWf9VHefxvxDk/H+lMYv/Z5kHbs3/J/EvJHrO/xeBFP/XiVLVKJIJWcFVtZrz/6VHOv7vo/rPj39K9en6r2h5/V8IxvwfFrlpnRaB5Zi+n+L7AMIO60LLdJwSc88fAskOhBasw5ZQqdVawgLzo3XBVQPL9JlshYZm0D+x3a4XiUd95sKy4/W8MCiDmGm8UDF5BF8XHc8SKxDPLcL6erwK8Wvl8mg0Qj3P64nMIXJIjVK17DOTW/2vzupCsfjdI/ji5cvIFHN8ltgkGEubYj0bMDdYCy6HLLYbsAv5mg+cSLO4zRzHg13uDaLRfFFMbLkdEP+XxxJnp2n+/4QNurbDMu3jLvv/IgfI9T/V8/X/YvDu8v9///zhd3Xjrx8zGGSOWZjF
@karmatr0n
karmatr0n / random_string.rb
Created October 30, 2023 02:52
Generate random string
require 'securerandom'
SecureRandom.base64(28).slice(0,26).gsub(/(\+|\/)/,("a".."z").to_a.
sample)
@karmatr0n
karmatr0n / debug_gem_notes.md
Last active July 31, 2023 22:45
Ruby Debug Gem Notes.md

Ruby Debug Gem Notes

Debug control

  • show_cmds
  • whereami
  • l or list
  • list 22-28 # Range of lines requested
  • show_source "Class or Class#method"
  • info # Instance variables, local variables, etc
  • step # go for next line/point of execution after the breakpoint (line by line)
@karmatr0n
karmatr0n / integer_to_sixtytwo.rb
Created July 5, 2023 04:55
Convert integer to sixty two
require 'test/unit'
def integer_to_sixtytwo(n)
return '0' if n.zero?
sixtytwo_digits = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
result = ''
while n > 0 do
result << sixtytwo_digits[n % 62]
n /= 62
end
result.reverse
@karmatr0n
karmatr0n / move_zeros.rb
Created June 23, 2023 13:46
Move all zeros to the end
def move_zeros(nums)
return nums if nums.empty?
left = 0
right = nums.length - 1
while left < right do
if nums[left] == 0
nums[left], nums[right] = nums[right], nums[left]
right -= 1
else
left += 1
@karmatr0n
karmatr0n / minimal_heaviest_subset.rb
Created June 23, 2023 13:44
Minimal heaviest subset
def minimal_heaviest_subset(weights)
weights.sort!
half_sum = weights.sum / 2
weights
.each_cons(2)
.filter {|a, b| a+b >= half_sum}
.flatten
.uniq
end
@karmatr0n
karmatr0n / might_i_recommend_ruby.rb
Last active November 30, 2022 15:34
might_i_recommend_ruby.rb
require 'uri'
require 'net/http'
require 'csv'
class Downloader
attr_accessor :uri, :content
def initialize(uri)
@uri = URI(uri)
@content = nil