Skip to content

Instantly share code, notes, and snippets.

Pry.config.editor = "vim --noplugin"
if defined?(PryByebug)
Pry.commands.alias_command 'c', 'continue'
Pry.commands.alias_command 's', 'step'
Pry.commands.alias_command 'n', 'next'
Pry.commands.alias_command 'f', 'finish'
Pry.commands.alias_command 'b', 'break'
Pry.commands.alias_command 'bda', 'break --disable-all'
end
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
@bernardo-cs
bernardo-cs / gist:2d52410618f86d6f594a
Last active August 30, 2016 07:54
Clickbait identifier by Word or Regex
# Class used to identify if a string it considered clickbait
class Spotlight::Examiner
attr_accessor :text, :filters
def initialize(text: '', filters: [ WordFilter.new, RegexFilter.new])
@text = text || ''
@filters = filters
end
# 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