Skip to content

Instantly share code, notes, and snippets.

View carlosagp's full-sized avatar

Carlos Garcia carlosagp

  • Salt Lake Valley
View GitHub Profile
@carlosagp
carlosagp / terminal_utils.rb
Created May 3, 2022 18:40
Copy and Paste from the rails terminal
# frozen_string_literal: true
# In {rails_app}/config/initializers/terminal_utils.rb
Rails.configuration.to_prepare do
require "terminal/utils"
module Rails::ConsoleMethods
include Terminal::Utils
end
end
@carlosagp
carlosagp / get_last_job_and_perform.rb
Created December 4, 2017 16:33
Get Last Resque Job and perform
def get_last_job_and_perform(queue)
raw_job = Resque.redis.lrange("queue:#{queue}", 0, -1).last
job = Resque.decode(raw_job)
klass = Resque::Job.constantize(decoded_job['class'])
klass.perform(*decoded_job['args'])
end
@carlosagp
carlosagp / DeleteResqueJobs.rb
Created November 29, 2017 17:39
Delete Resque Jobs
def delete_mailer_jobs(number=10)
queue_name = 'mailer'
jobs = Resque.redis.lrange('queue:mailer', 0, number)
deleted_count = 0
jobs.each do |job|
decoded_job = Resque.decode(job)
if decoded_job['class'] == 'MailerQueue' && decoded_job['args'].include?('error_notification')
Resque::Job.destroy(queue_name, decoded_job['class'], *decoded_job['args'])
deleted_count += 1

Keybase proof

I hereby claim:

  • I am carlosagp on github.
  • I am carlosagp (https://keybase.io/carlosagp) on keybase.
  • I have a public key ASAVARPsP0aB8htzJaGMvFZu3_ipg8AWFNVgIjifL6C-1Qo

To claim this, I am signing this object:

@carlosagp
carlosagp / PR-Template.js
Last active September 29, 2015 23:30
Github Bookmarklet Template
javascript:
(
function() {
var e, i;
e = document.getElementById('pull_request_title');
if (e) {
var m = e.value.match(/\/(\d+)\/(.*)/) || [];
i = m[1] || 'N/A';
e.value = (m[2] || 'Description');
};
@carlosagp
carlosagp / gist:f9a3a36b9c10780b8011
Created August 25, 2014 22:47
Test for rotating a matrix counter clockwise
require 'test/unit'
require 'solution'
class RotationTest < Test::Unit::TestCase
def test_square_rotation
square = [
[0, 1, 0, 0],
[0, 1, 1, 0],
[0, 0, 1, 0],
[0, 0, 0, 0]
@carlosagp
carlosagp / simpler_rock_paper_scissors.rb
Created August 21, 2014 07:04
Simpler Rock Paper Scissors
#!/usr/bin/ruby
choices = {1 => 'Rock', 2 => 'Paper', 3 => 'Scissors'}
puts "These are your choices"
puts "1) Rock"
puts "2) Paper"
puts "3) Scissors"
print "Please enter the number of your choice: "
player_choice = gets
player_choice = player_choice.to_i
@carlosagp
carlosagp / rock_paper_scissors.rb
Created August 20, 2014 19:05
Rock Paper Scissors
# Rock paper scissors
choices = %w[rock paper scissors] # this is the as: ['rock', 'paper', 'scissors']
results = {
:player => 0,
:computer => 0,
:ties => 0
}
player_results = 0
@carlosagp
carlosagp / string_reversal.rb
Created August 20, 2014 01:01
Reversing a string manually.
# Reversing a String
puts 'Give me your string'
string_captured = gets().chomp # Get the input and remove the new line characted
# Go through each char from beginning to end in the captured string and then
# concatenate them by putting the last characted accessed at the beginning
# of the new string.
new_string_v1 = ''
string_captured.chars.each{|c| new_string_v1 = c + new_string_v1 }