Skip to content

Instantly share code, notes, and snippets.

View Electron-libre's full-sized avatar

Cedric Brancourt Electron-libre

View GitHub Profile
"#top-menu ul li a".on('click', function(e){
e.preventDefault();
$('content').load(e.target.pathname);
e.target.parent().radioClass('active');
});
".opacify".on({
mouseover: function(e){
e.target.morph({opacity: '1'})
},
mouseout: function(e){
e.target.morph({opacity: '0.7'})
}
});
def integrity
if time_credit?
errors.add(:base, I18n.t(:establishment_cost_empty, :scope => [:models, :destinations, :integrity])) unless establishment_cost?
elsif establishment_cost?
errors.add(:base, I18n.t(:time_credit_empty, :scope => [:models, :destinations, :integrity])) unless time_credit?
end
end
def integrity
dependent_attributes = %w(time_credit establishment_cost)
nullity_proc = lambda{|attr| send(attr.to_sym).nil? || send(attr.to_sym).zero?}
dependent_attributes.each_index do |i|
if nullity_proc.call(dependent_attributes[i]) && !nullity_proc.call(dependent_attributes[i-1])
errors.add(dependent_attributes[i].to_sym, I18n.t("#{dependent_attributes[i]}_empty", :scope => [:models, :destinations, :integrity]))
end
end
end
@Electron-libre
Electron-libre / destination_prefixes.rb
Created February 16, 2011 15:08
to get ["1", "12", "123", "1234", "12345", "123456", "1234567", "12345678", "123456789", "1234567890"] with "123456789"
destination_number = cdr.called_number
prefixes_array = Array.new
destination_number.each_char do |char|
prefixes_array << (destination_number[-1] or '' ) + char
end
@files = ARGV
@files.each_with_index do |file, index|
pid = fork {
require 'stomp'
client = Stomp::Client.open("", "", "localhost", 61613)
def send_message(server, message, queue)
server.send("/cdr/cdr#{queue}", message, {})
end
def self.resolve(cdr)
prefixes_array = Array.new
cdr.called_number.each_char do |char|
prefixes_array << (prefixes_array[-1] or '') + char
end
prefixes_array.reverse!
best_match = Proc.new do |destinations, prefixes|
@Electron-libre
Electron-libre / report.rb
Created April 11, 2011 12:26
compute reporting for destination groups
monthly_reports = []
date = '10-10'
Journal.only('_id').where(:account.in => accounts, :date => Regexp.new(date)).each do |j|
j.reload
entries = j.billing_entries.to_a
existing_report_for_account = monthly_reports.find_index do |account|
account[:journal] == j.account
end
if existing_report_for_account
monthly_report = monthly_reports[existing_report_for_account]
@Electron-libre
Electron-libre / Mongoid_cursor_timeout.rb
Created April 14, 2011 08:42
How I tried to fix it
accounts = %w( 0990000047000 0990000047001 0990000047900 )
("0990000091000" .. "0990000091005").each do |c|
accounts << c
end
("0990000071000" .. "0990000071019").each do |c|
accounts << c
end
date = '10-11'
def reprice(accounts,date)
accounts.each do |acc|
module HectorFetch
module InstanceMethods
def service_with_fetch
res = service_without_fetch
logger.info("in with_fetch #{current_user}")
current_user.update_from_hector
res
end
end