Skip to content

Instantly share code, notes, and snippets.

TAGS_TMP_FOLDER="/tmp/tmp_tags"
coffeetags -R -f $TAGS_TMP_FOLDER
ctags -R --languages=ruby --exclude=.git --exclude=log -a -f $TAGS_TMP_FOLDER . $(bundle list --paths)
mv $TAGS_TMP_FOLDER tags
var API = function () {
};
API.prototype.login = function(username, password) {
console.log("request username and pw to server...");
this.auth_token = "nhonhonho";
};
API.prototype.getUserById = function(user_id) {
if (this.auth_token){
@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) }
@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 / 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
# 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 / 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
@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
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 / 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\" />"