Skip to content

Instantly share code, notes, and snippets.

@eladmeidar
eladmeidar / cached_method.rb
Created November 22, 2020 12:36
Caching a method in Rails
module CachedMethod
def self.included(base)
base.class_eval do
@method_cache_validators = Hash.new(0)
extend ClassMethods
end
end
module ClassMethods
@eladmeidar
eladmeidar / datasize.rake
Created February 6, 2010 07:22
Rake task to get current database size
# Run rake db:size to get a print of your database size in bytes.
# Works for Mysql, as for the others not really sure.
namespace :db do
desc 'Print data size'
task :size => :environment do
database_name = ActiveRecord::Base.connection.instance_variable_get("@config")[:database]
adapter = ActiveRecord::Base.connection.adapter_name.downcase
@eladmeidar
eladmeidar / fetch_logos.rb
Created November 8, 2020 06:34
Simple ruby script to fetch possible logos from a domain.
# Usage: ruby fetch_logos.rb <FULL_DOMAIN>
require 'httparty'
require 'nokogiri'
require 'css_parser'
require 'byebug'
class Array
def self.wrap(object)
if !object.is_a?(Array)
let isRunning = false
const foo = function() {
isRunning = true
console.log('called')
isRunning = false
}
const events = ['click', 'mousedown']
let func = function(eventsArr, cb) {
@eladmeidar
eladmeidar / widget_inject.rb
Last active January 30, 2019 15:09
Coding exercise
class String
module WidgetExceptions
class InvalidWidget < ArgumentError; end
end
def widget_inject(widgets = [])
self_with_widgets = self.clone
widgets.sort_by {|w| w[:position] }.reverse.each do |widget|
raise WidgetExceptions::InvalidWidget, "widget must be a hash, was #{widget.class.name}" unless widget.is_a?(Hash)
require 'active_record'
require 'active_record/fixtures'
Fixtures.create_fixtures('test/fixtures/', ActiveRecord::Base.connection.tables)
@eladmeidar
eladmeidar / _form.html.erb
Created July 31, 2013 11:13
User specific timezones in rails
<%= f.label :time_zone %>
<%= f.time_zone_select :time_zone %>
check process thin-3000 with pidfile /var/www/html/redmine2/current/tmp/pids/thin.3000.pid
start program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin start -C /var/www/html/redmine2/current/config/thin/performance.yml"
stop program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin stop -C /var/www/html/redmine2/current/config/thin/performance.yml"
if 3 restarts within 5 cycles then timeout
if totalmem is greater than 400.0 MB for 2 cycles then restart
group thin
check process thin-3000 with pidfile /var/www/html/redmine2/current/tmp/pids/thin.3000.pid
start program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin start -C /var/www/html/redmine2/current/config/thin/performance.yml"
stop program = "cd /var/www/html/redmine2/current && /usr/local/rvm/bin/rvm default do bundle exec thin stop -C /var/www/html/redmine2/current/config/thin/performance.yml"
if 3 restarts within 5 cycles then timeout
if totalmem is greater than 400.0 MB for 2 cycles then restart
group thin
class FavoritesManager
attr_reader :user_id
def initialize(user_id)
@user_id = user_id
@client = REDIS
end
def favorite_post(post)