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 / gist:5900017
Last active October 18, 2019 15:43
Create a gemset per project
# I'm not using this anymore
#
# Assuming that you are already on your project directory.
# Step 1: rvm gemset create [name of gemset]
# Step 2: rvm --rvmrc [ruby version here]@[name of gemset] # Note: You can check your current ruby version by running "ruby -v" from your console.
# Step 3: Refresh your directory, you can do this by simply checking out of your directory via command: cd.. and going back to that directory again.
# Step 4: RVM will ask you a simple Yes, No, View, Cancel question. Press Y for yes.
# Step 5: You're done! Run bundle install.
@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 / routes.rb
Last active March 29, 2018 14:34
Rails Best Practices: Routing Concerns in Rails 4
# Routing Concerns is an attempt to DRY up your config/routes.rb.
# The basic idea is to define common sub-resources (like comments)
# as concerns and include them in other resources/routes.
# Here’s the obvious example:
concern :commentable do
resources :comments
end
concern :remarkable do

Status

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

# check out what's coming next in the queue
#    Resque.peek(archive_queue)
@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 / 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 / age.rb
Last active January 2, 2016 11:09
Calculate age by birthday - compatible with leap year.
module Age
class << self
def today
Time.now.utc.to_date
end
# Formats the date as mm/dd/yyyy
def formatted_bday(bday)
@rbmrclo
rbmrclo / minify.rb
Created December 9, 2013 08:52
Minify javascript using uglifier
require 'uglifier'
File.open("outfile.min.js", "w") do |file|
file.write Uglifier.compile(File.read("infile.js"))
end
# Or with a one liner from the Terminal
ruby -e "require 'uglifier'; puts Uglifier.compile(File.read('infile.js'))" > outfile.min.js
@rbmrclo
rbmrclo / obfuscate.rb
Created November 27, 2013 08:11
Obfuscate an id
module Obfuscate
def cipher
OpenSSL::Cipher::Cipher.new('aes-256-cbc')
end
def cipher_key
'any string that you want'
end