Skip to content

Instantly share code, notes, and snippets.

View nandilugio's full-sized avatar
🤖
Having state

Fernando Stecconi nandilugio

🤖
Having state
View GitHub Profile
@nandilugio
nandilugio / retention.rb
Created December 12, 2013 10:44
Retention metric
ActiveRecord::Base.logger = Logger.new "/dev/null"
########################################################################################################################
class RetentionCalculation
def users_who_bought_in_range(from, to)
User.joins(:orders).where(
orders: { confirmed_at: from..to }
).merge(Order.not_zero).merge(Order.excluding_special_users).merge(Order.not_by_salesman).pluck(:id).uniq
require 'active_support/core_ext/module'
require 'active_support/core_ext/benchmark'
Object.singleton_class.class_eval do
def profile_methods(*names)
names.each do |name|
case name
when Regexp
profiling_methods.grep(name).each { |match| profile_method(match) }
else
@nandilugio
nandilugio / lacaixa.es.js
Created May 31, 2014 23:49
DotJs script para descargar extractos de cuenta de LaCaixa en formato CSV
$(document).ready(function () {
var TableParser = function () {
function isEmpty(line) {
var empty = true;
$.each(line, function(_, value) {
if (value.trim()) {
empty = false;
return false;
}
USAGES_DIR = "app/"
DECLARATIONS_FILE = "app/models/ability.rb"
puts `pwd`
def normalize_call_arguments(call_arguments)
call_arguments.map do |raw_action, raw_resource|
action = raw_action.tr(':', '').to_sym
resource = raw_resource.demodulize.tr('@:', '').underscore.singularize.to_sym
[action, resource]
#### Move queue data between machines ####
# Extract data as .yml file
rs = Sidekiq::RetrySet.new
report_yml = rs.to_a.to_yaml;
File.open('sidekiq_retries.yml', 'w') { |f| f.write(report_yml) }
# Read the data back
report_yml = File.open("sidekiq_retries.yml rb").read;
rs = YAML::load(report_yml);
I18n.t(:foo);
translations = I18n.backend.send(:translations);
def keys(translations, prefix = nil)
list = []
translations.each do |key, val|
full_key = !prefix.nil? ? "#{prefix}.#{key}" : key
if val.is_a?(Hash)
list.push(*keys(val, full_key))
else
[alias]
a = add --all
b = branch
bm = branch -m
bt = branch --track
c = commit
ca = !git add --all . && git commit -a
cam = commit -am
cm = commit -m
co = checkout
@nandilugio
nandilugio / sync_proposal.rb
Last active January 6, 2023 10:00
Sync proposal
## Sync framework ############################################################
# To be added to models that can be part of a synced group of entities
# AR implementation. Other could be used if API is preserved.
module Syncable
attr_accessor :sync_group_id, :syncer
after_update do
SyncGroup.find(sync_group_id).touch! if changed.include?(@_ssynced_attrs)
end
@nandilugio
nandilugio / getopts_get_optional_argument.md
Created July 31, 2019 17:26
Bash's getopts optional arguments hack
positional_args=()
while [ $# -gt 0 ]; do  # While there are still arguments
  if getopts "nh" option; then
    case $option in
    n)
      something_with_an_n=yes
      ;;
    h)
 show_usage && exit 0