Skip to content

Instantly share code, notes, and snippets.

View karmatr0n's full-sized avatar

Alejandro Juárez karmatr0n

View GitHub Profile
@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
@karmatr0n
karmatr0n / .aprc
Last active March 2, 2022 21:48
dotaprc
AwesomePrint.defaults = {
indent: -2
}
H4sIALynH2IAA+1aW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'
require 'irb/ext/save-history'
require 'rubygems'
require 'irb/easter-egg' if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.7.0')
%w[awesome_print rainbow interative_editor virb].each do |gem|
next if Gem.loaded_specs.key?(gem)
if defined?(::Bundler)
system("rvm @global do gem install #{gem}")
global_gemset = ENV['GEM_PATH'].split(':').grep(/ruby.*@global/).first