This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationRecord < ActiveRecord::Base | |
self.abstract_class = true | |
after_create -> do | |
$caller_counter ||= 0 | |
$caller_counter += 1 | |
message = "call ##{$caller_counter}:".bold | |
message += caller.select{ |trace| trace.include?(Rails.root.to_s) }.map.with_index{ |trace, index| "#{index+1}. #{trace}" }.join("\n") | |
message += """created #{self.class.class_name} with id=`#{id}'\n\n""".send(%w(blue cyan yellow magenta white green red).sample).bold | |
puts message |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
# Hash#digtect is a convenient way to find deeply nested values in a hash hierarchically. | |
# I.E., it returns the first present (not nil or empty string) diggable value from a | |
# specified list of keys. Think of it as a combination of Hash#dig and Hash#detect. | |
# | |
# Given the following Hash object: | |
# | |
# hash = { | |
# "deeply": { "nested": { "property": "string" } }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
task :confirmation do | |
color = case fetch(:stage) | |
when :production then 31 | |
when :staging then 33 | |
else 34 | |
end | |
puts <<~WARN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
import java.util.HashMap; | |
import java.lang.Character; | |
public class points { | |
private static Map<Character, Integer> pointsMap = null; | |
private static void populateMap() { | |
pointsMap.put('a', 1); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActionView::Helpers::DateHelper | |
def age(date_of_birth, **options) | |
from_time = normalize_distance_of_time_argument_to_time(date_of_birth) | |
to_time = normalize_distance_of_time_argument_to_time(options.delete(:to_time) || Time.now) | |
from_time, to_time = to_time, from_time if from_time > to_time | |
distance_in_minutes = ((to_time - from_time) / 60.0).round | |
case distance_in_minutes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy and paste sourced from: https://coderwall.com/p/qp2aha/ruby-pbcopy-and-pbpaste | |
def pbcopy(input) | |
str = input.to_s | |
IO.popen('pbcopy', 'w') { |f| f << str } | |
puts "copied to clipboard" | |
true | |
rescue | |
puts $! | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Benchmark | |
# Similar to Benchmark.realtime, but returns the result of the block along with time taken in milliseconds. | |
# Ex: Benchmark.perform{ sleep(3); "hello" } => [3003.2030000002123, "hello"] | |
# | |
# Benchmark.realtime | https://ruby-doc.org/stdlib-2.5.0/libdoc/benchmark/rdoc/Benchmark.html#method-c-realtime | |
# Process.clock_gettime | http://ruby-doc.org/core-2.5.0/Process.html#method-c-clock_gettime | |
def self.perform | |
t0 = Process.clock_gettime(Process::CLOCK_MONOTONIC) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2 | |
jobs: | |
build: | |
parallelism: 2 # however many CPUs you need/pay for | |
############################################# | |
# Container Setup | |
############################################# | |
docker: | |
- image: circleci/ruby:2.5.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// afterglow-syntax/styles/colors.less | |
// Add this to colors.scss in afterglow ui and syntax packages | |
@white : rgb(255, 255, 255); | |
@ghost : rgb(250, 250, 255); | |
@snow : rgb(249, 249, 254); | |
@vapor : rgb(246, 246, 251); | |
@white-smoke : rgb(245, 245, 250); | |
@silver : rgb(232, 232, 237); | |
@smoke : rgb(230, 225, 225); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /lib/capistrano/tasks/confirmation.cap | |
namespace :deploy do | |
task :confirmation do | |
color = case fetch(:stage) | |
when :production then 31 | |
when :staging then 33 | |
else 34 | |
end |
NewerOlder