Skip to content

Instantly share code, notes, and snippets.

class TweetsController < ApplicationController
def search
@result = sort( Tweet.search_text( search_query ) )
end
private
def search_query
params[:q]
end
@bernardo-cs
bernardo-cs / pre-push
Created March 31, 2015 09:53
pre push git hook to build middleman release
#!/bin/sh
echo "building latest release"
rake gitbuild
exit 0
@bernardo-cs
bernardo-cs / commit-msg
Created March 31, 2015 13:19
automatic commit messages
#!/bin/sh
#
# Automatically adds branch name and branch description to every commit message.
#
NAME=$(git branch | grep '*' | sed 's/* //')
echo "$NAME"': '|cat - "$1" > /tmp/out && mv /tmp/out "$1"
@bernardo-cs
bernardo-cs / image_helper.rb
Last active August 29, 2015 14:18
Auto register jpg methods in middleman in middleman
# place me inside the helpers folder on the root of the middleman project
# ex.:
# (given that you have an image name slider.jpg inside the images folder)
#
# slider_image()
# => "<img src=\"slider.jpg\" />"
#
# slider_image( class: 'foo', 'data-attribute': 'bar')
# => "<img class=\"foo\" data-attribute=\"bar\" src=\"slider.jpg\" />"
require 'rails_helper'
describe 'the problem'
it 'only creates a tweet after the third factry invocation'
puts "There are " + Category.count.to_s + " categories in the db"
3.times do
begin
FactoryGirl.build( :twtr_tweet_reg )
rescue Exception => e
puts "Tryied to create category with name" + e.name.to_s
end
@bernardo-cs
bernardo-cs / gist:786a49170406476fbfb5
Created May 12, 2015 09:29
Running spec/models/fb_pst_reg_spec.rb without before all improves test velocity on 50% and tests are still passing.
src/ebench/Ishango2 feat/37-improve-test-suite ✗
▶ rspec spec/models/fb_pst_reg_spec.rb -p
........
Top 8 slowest examples (27.32 seconds, 100.0% of total time):
FbPstReg update some fb post regs
4.95 seconds ./spec/models/fb_pst_reg_spec.rb:22
FbPstReg should update imp factor by licosh
4.49 seconds ./spec/models/fb_pst_reg_spec.rb:72
FbPstReg create some fb post regs
# get it ready
git bisect start
git bisect good c09c728
git bisect bad e6a0692
# give git a command to run against each commit
git bisect run rspec spec/features/my_broken_spec.rb
@bernardo-cs
bernardo-cs / karma.rake
Created November 26, 2015 12:28
Karma with application.js
require 'sprockets'
namespace :karma do
task :start => :environment do
with_tmp_config :start
end
task :run => :environment do
with_tmp_config :start, "--single-run"
end
@bernardo-cs
bernardo-cs / karma.rake
Created November 30, 2015 12:12
Rake task build application.js assets
require 'sprockets'
require 'pry'
require 'fileutils'
namespace :karma do
task :start => :environment do
with_tmp_config :start
end
task :run => :environment do
@bernardo-cs
bernardo-cs / gist:b88cac3895d2a1ffe690
Last active January 29, 2016 07:46
simplified collections with duck typing
namespace :assets do
desc "fetch descriptions for youtube videos without descriptions"
task yt_fetch_description: :environment do
BsuDescriptionUpdater.new(YtChanReg, FbPgeReg, IgUsrReg).update_all
end
end
class BsuDescriptionUpdater
def initialize(*source_klasses)
@source_klasses = source_klasses.map { |src| DescriptionUpdater.new(src) }