- Ruby
- Git
- Standard
Create a git pre commit hook and give it permission to execute:
touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
class HashBased | |
include Surrealist | |
extend Schema | |
attr_reader :hash | |
def initialize(hash = {}) | |
@hash = hash.deep_symbolize_keys | |
end |
# app/types/br_money_type.rb | |
class BrMoneyType < ActiveRecord::Type::Decimal | |
def cast(value) | |
value.is_a?(String) ? value.clean_money : value | |
end | |
def deserialize(value) | |
value ? value.to_f : value | |
end | |
end |
# You just need to set inactivity_timeout = 0.1 (or any other low number except zero). | |
# It will trigger the request and wait only 0.1 second for the response. You don't need to define the callbacks as well. | |
# Example code below: | |
require 'bundler/inline' | |
gemfile do | |
source 'https://rubygems.org' | |
gem "em-http-request" | |
end |
class Array | |
# Few types of normalizations | |
# https://developers.google.com/machine-learning/data-prep/transform/normalization | |
def normalize | |
return if self.empty? | |
x_min, x_max = self.minmax | |
dx = (x_max-x_min).to_f |
class ExcelFormulas { | |
class func pmt(rate : Double, nper : Double, pv : Double, fv : Double = 0, type : Double = 0) -> Double { | |
return ((-pv * pvif(rate, nper: nper) - fv) / ((1.0 + rate * type) * fvifa(rate, nper: nper))) | |
} | |
class func pow1pm1(x : Double, y : Double) -> Double { | |
return (x <= -1) ? pow((1 + x), y) - 1 : exp(y * log(1.0 + x)) - 1 | |
} | |
class func pow1p(x : Double, y : Double) -> Double { |
Create a git pre commit hook and give it permission to execute:
touch .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
# For more: https://github.com/ruby-concurrency/concurrent-ruby | |
num_threads = Concurrent.processor_count # or whatever you prefer like 4 | |
thread_pool = Concurrent::FixedThreadPool.new(num_threads) | |
products = Product.all | |
executors = products.map { |product| | |
Concurrent::Future.execute({executor: thread_pool}) do | |
p "processing #{product.id}" | |
end |
# app/jobs/job_debouncer.rb | |
module JobDebouncer | |
extend ActiveSupport::Concern | |
class_methods do | |
def perform_later_once(*args, wait_time: 15.seconds) | |
job_key = "job_debouncer_#{self}_#{args}" | |
return if Rails.cache.exist?(job_key) |
// for the ST3 users who don't have the Default.sublime-theme file (which is actually the default configuration), | |
// the simplest procedure is: | |
// 1- Navigate to Sublime Text -> Preferences -> Browse Packages | |
// 2- Open the User directory | |
// 3- Create a file named Default.sublime-theme with the following content (modify font.size as required): | |
[ | |
{ | |
"class": "sidebar_label", | |
"color": [0, 0, 0], | |
"font.size": 16 |