Skip to content

Instantly share code, notes, and snippets.

View rbmrclo's full-sized avatar
Coffee 👨‍💻Code 🍸Cocktails

Robbie Marcelo rbmrclo

Coffee 👨‍💻Code 🍸Cocktails
View GitHub Profile
@rbmrclo
rbmrclo / delete-evicted-pods-all-namespaces.sh
Created April 1, 2019 06:29 — forked from psxvoid/delete-evicted-pods-all-namespaces.sh
Delete evicted pods from all namespaces (also ImagePullBackOff and ErrImagePull)
#!/bin/sh
# based on https://gist.github.com/ipedrazas/9c622404fb41f2343a0db85b3821275d
# delete all evicted pods from all namespaces
kubectl get pods --all-namespaces | grep Evicted | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
# delete all containers in ImagePullBackOff state from all namespaces
kubectl get pods --all-namespaces | grep 'ImagePullBackOff' | awk '{print $2 " --namespace=" $1}' | xargs kubectl delete pod
# delete all containers in ImagePullBackOff or ErrImagePull or Evicted state from all namespaces
@rbmrclo
rbmrclo / databases.rake
Created March 8, 2017 13:06 — forked from wbailey/databases.rake
ActiveRecord migrations outside of Rails
require 'yaml'
require 'logger'
require 'active_record'
namespace :db do
def create_database config
options = {:charset => 'utf8', :collation => 'utf8_unicode_ci'}
create_db = lambda do |config|
ActiveRecord::Base.establish_connection config.merge('database' => nil)
@rbmrclo
rbmrclo / curl.md
Created June 15, 2016 07:54 — forked from btoone/curl.md
A curl tutorial using GitHub's API

Introduction

An introduction to curl using GitHub's API

The Basics

Makes a basic GET request to the specifed URI

curl https://api.github.com/users/caspyin
@rbmrclo
rbmrclo / datetime_cheatsheet.md
Last active May 4, 2017 14:52
DateTime Cheatsheet

DOs

2.hours.ago # => Thu, 27 Aug 2015 14:39:36 AFT +04:30
1.day.from_now # => Fri, 28 Aug 2015 16:39:36 AFT +04:30
Time.zone.parse("2015-08-27T12:09:36Z") # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current # => Thu, 27 Aug 2015 16:39:36 AFT +04:30
Time.current.utc.iso8601 # When suppliyng an API ("2015-08-27T12:09:36Z")
Time.strptime("2015-08-27T12:09:36Z", "%Y-%m-%dT%H:%M:%S%z").in_time_zone # If you can't use Time.zone.parse (Thu, 27 Aug 2015 16:39:36 AFT +04:30)
Date.current # If you really can't have a Time or DateTime for some reason (Thu, 27 Aug 2015)
@rbmrclo
rbmrclo / gist:e4df82f1a8f04b11a325
Last active August 29, 2015 14:18
SHA1Generator
require 'digest/sha1'
#
# A wrapper for generating SHA1 hash value
# Simply done by concatenating all values using the colon symbol for delimiter.
# This algorithm is mostly used by payment gateways.
#
# Usage:
#
# SHA1Generator.digest('foo', 'bar', 'fizz', 'buzz')
# => "e723e86a6000fc8462142eb4821672de107535c1" # 40 chars
@rbmrclo
rbmrclo / email_validator.rb
Created May 22, 2014 05:57
Email validatior
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i
record.errors[attribute] << (options[:message] || 'is not an email')
end
end
end

Status

Resque.info
Resque.queues
Resque.redis
Resque.size(queue_name)

# check out what's coming next in the queue
#    Resque.peek(archive_queue)
require 'resque'
require 'resque_scheduler'
require 'resque/server'
require 'resque_scheduler/server'
schedules = YAML.load_file(Rails.root.join('config', 'schedules.yml'))
$redis = Resque.redis = Redis.current = Redis.new( url: ENV['REDIS_URI'] )
Resque.schedule = schedules
@rbmrclo
rbmrclo / gist:9888023
Created March 31, 2014 08:41
Ignore concerns for rails_admin
# config/rails_admin.rb
config.excluded_models = Dir.glob(Rails.root.join('app/models/concerns/**.rb')).map {|p| 'Concerns::' + File.basename(p, '.rb').camelize }
@rbmrclo
rbmrclo / slugable.rb
Last active August 29, 2015 13:56
An simple way to find an object by slug
module Slugable
module ClassMethods
def find_by_slug(param)
if to_return = where("lower(name) LIKE ?", "#{patternify(param)}")
to_return.first
else
nil
end
end