Skip to content

Instantly share code, notes, and snippets.

@carloscortegagna
carloscortegagna / external_link.css
Created July 3, 2012 07:38
CSS: style external domain links
@carloscortegagna
carloscortegagna / foreign_keys_not_indexed
Created July 3, 2012 08:03
Rails: list foreign keys which aren't indexed
c = ActiveRecord::Base.connection
c.tables.collect do |t|
columns = c.columns(t).collect(&:name).select {|x| x.ends_with?("_id" || x.ends_with("_type"))}
indexed_columns = c.indexes(t).collect(&:columns).flatten.uniq
unindexed = columns - indexed_columns
unless unindexed.empty?
puts "#{t}: #{unindexed.join(", ")}"
end
end
@carloscortegagna
carloscortegagna / gist:56b32a63aad04d9b096e
Created November 19, 2014 13:52
Handlebars debug helper
Handlebars.registerHelper('debugger', function(optionalValue) {
console.log('Current Context');
console.log('====================');
console.log(this);
if (optionalValue) {
console.log('Value');
console.log('====================');
console.log(optionalValue);
}
module ApplicationHelper
include ActionView::Helpers::AssetTagHelper
def image_tag(source, options = {})
if options[:retina]
options['data-at2x'] = path_to_image(source.split('.').join('@2x.'))
options.tap { |h| h.delete(:retina) }
else
options['data-no-retina'] = ''
end
Coupon.bonus.each { |b| b.update_attributes(total_tutor_cost_cents: 750) if b.total_tutor_cost_cents == 1500 }
context 'real use cases, lasted less than min duration' do
it 'elapsed seconds = 0, lesson duration = 30min, residual seconds = 45min, pay MIN' do
create(:purchased_credit, credit: bundle, student: student, residual_seconds: 45*60, expire_at: Time.now+1.year, status: :paid)
expect(lesson_service.lesson_started?).to be_falsey
expect(lesson_service.lasted_less_than_min_duration?).to be_truthy
expect(lesson_service.lasted_less_than_duration?).to be_truthy
expect(lesson_service.show_min_duration?).to be_truthy
expect(lesson_service.max_duration).to eql lesson.duration
expect(lesson_service.close_and_pay!('min')).to be_truthy
lock '3.2.1'
# Configuration
set :application, 'travel-mesh'
set :repo_url, "git@github.com:NetBookingCom/travel-mesh.git"
set :executener, fetch(:user)
set :admin_executener, fetch(:user)
set :use_sudo, false
set :normalize_asset_timestamps, false
{
"network_infos":{
"search_details":{
"search_id":{
"$oid":"57b5bac04d616306b9030000"
},
"search_type":"Accomodation"
},
"results":[
{
/usr/local/bsmart/current/log/activations.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
copytruncate
}
Tutor.all.each do |tutor|
tutor.generate_tutor_search_cache
tutor.rates_count = tutor.feedbacks.positive.count - tutor.feedbacks.negative.count
tutor.opinions_count = tutor.feedbacks.with_opinion.count
tutor.save
end