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
#!/usr/bin/env ruby | |
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'config', 'environment')) | |
require 'optparse' | |
require 'timeout' | |
require 'ostruct' | |
USAGE = "usage: script/resque command [options]" | |
COMMANDS = %w( start status stop ) | |
TIMEOUT = 60 |
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
# Adds support for dirty attributes to a couchbase model. | |
# | |
# class Foo < Couchbase::Model | |
# include CouchbaseExt::Dirty | |
# acts_as_dirty_attribute :bar, :blub # only selected attributes will be dirty... | |
module CouchbaseExt | |
module Dirty | |
DIRTY_SUFFIXES = ['_changed?', '_change', '_will_change!', '_was'] |
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 Counter < Struct.new(:value) | |
def self.wrap(bucket, result) | |
new(result['value']) | |
end | |
end | |
view :count_all, :include_docs => false, :wrapper_class => Counter | |
def self.count | |
count_all.first.present? ? count_all.first.value : 0 | |
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
namespace :disable_users do | |
desc 'Generates a csv file containing candidates for deletion' | |
task :determine_candidates => :environment do | |
logger = Logger.new('tmp/candidates.csv') | |
users = 0 | |
candidates = 0 | |
{ :invalid => :invalid_emails, :dns_err => :unresolvable_emails }.each_pair do |reason, input_file| |
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
# 0. Make sure you have Ruby 1.9.3 installed, and optionally RVM and PostgreSQL | |
# 0.2 If you are on the Mac, make sure you have a c compiler by installing XCode Command Line Tools or gcc4.2 with homebrew | |
# https://github.com/mxcl/homebrew/wiki/Custom-GCC-and-cross-compilers | |
# 0.5 Make sure you have bundler version ~> 1.2 as Rails depends on it | |
gem install bundler | |
# 1. Get edge Rails source (master branch) | |
git clone https://github.com/rails/rails.git |
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
desc 'Generates a csv file containing invalid or unresolvable email addresses' | |
task :check_emails => :environment do | |
logger = Logger.new('log/faulty_emails.csv') | |
Account.find_each do |account| | |
identifier = "#{account.uuid},#{[account.current_sign_in_at, account.updated_at].compact.max},#{account.email}" | |
if !EmailUtils::Validator.valid?(account.email) | |
logger.warn("invalid,#{identifier}") |
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
# | |
# RFC822 Email Address Regex | |
# -------------------------- | |
# | |
# Originally written by Cal Henderson | |
# c.f. http://iamcal.com/publish/articles/php/parsing_email/ | |
# | |
# Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb. | |
# | |
# Licensed under a Creative Commons Attribution-ShareAlike 2.5 License |
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 ModelExt | |
module MasterSlaveDb | |
# This module allows you to send db queries directly to the slave database. | |
# Please do not use this on the user frontend at the moment - administration interface only. | |
# | |
# 1) The slave is weaker (CPU, RAM) than the master. | |
# 2) The slave will be down around lunch time for backup reasons. | |
# | |
# Usage: |
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 SetDatabaseDefaults < ActiveRecord::Migration | |
def up | |
case ActiveRecord::Base.connection.adapter_name | |
when "MySQL", "Mysql2" | |
execute "ALTER DATABASE #{current_database} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci" | |
when "SQLite" | |
# do nothing since SQLite does not support changing the database encoding and only supports unicode charsets | |
when "PostgreSQL" | |
# do nothing since PostgreSQL does not support changing the database encoding |
NewerOlder