Skip to content

Instantly share code, notes, and snippets.

@Olgagr
Olgagr / gist:4192bae863b9b6497e6f
Created September 28, 2014 06:08
Sinatra router implementation - not working
# This implementation causes error:
# ArgumentError: wrong number of arguments (0 for 1..3)
# config.ru:10:in `instance_eval'
# config.ru:10:in `initialize'
# config.ru:26:in `new'
# config.ru:26:in `block in inner_app'
# /Users/ograbek/.rvm/gems/ruby-2.1.2@owning_rails/gems/rack-1.5.2/lib/rack/builder.rb:55:in `instance_eval'
# /Users/ograbek/.rvm/gems/ruby-2.1.2@owning_rails/gems/rack-1.5.2/lib/rack/builder.rb:55:in `initialize'
module Heroku
module Rake
class Task
attr_accessor :name
def initialize(name)
@name = name
end
def self.[](name)
Heroku::Rake::Task.new(name)
@Olgagr
Olgagr / gulp_aws_deploy.js
Created October 28, 2014 11:38
Gupl aws deployment script
function deploy(env) {
var bucketSuffix = env === 'staging' ? '-staging' : '';
var publisher = $.awspublish.create({
key: 'xxxx',
secret: 'xxx',
bucket: 'picaly.co' + bucketSuffix,
region: 'eu-west-1'
});
return gulp.src('./dist/**/*')
@Olgagr
Olgagr / react_authorization.js
Created November 7, 2015 13:37
react authorization
requireAuth: function(nextState, replaceState) {
if (!AuthStore.isAuthenticated()) {
replaceState({ nextPathname: nextState.location.pathname }, '/');
}
},
render: function() {
return (
<Layout>
<Router history={history}>
@Olgagr
Olgagr / Comparable.rb
Created May 26, 2013 08:26
Comparable module in Ruby
#to use this module the class has to mixin it and define <=> method
class Bid
include Comparable
attr_accessor :estimate
def <=>(other_bid)
if self.estimate > other_bid.estimate
1
@Olgagr
Olgagr / case_statement_behaviour.rb
Created May 26, 2013 08:45
Defining case statement behaviour for Ruby class
# to do it we have to define === method inside our class
class Ticket
attr_accessor :venue, :date, :price
def initialize(venue, date, price)
self.venue = venue
self.date = date
self.price = price
@Olgagr
Olgagr / devise_setup_email_layout.rb
Created May 28, 2013 18:54
Set up layout for email in Devise gem
# in application.rb
config.to_prepare do
Devise::Mailer.layout "email_template" # in views/layouts
end
@Olgagr
Olgagr / rspec_shared_examples.rb
Created May 30, 2013 06:00
create shared examples in spec file
shared_examples('title of shared examples') do
#some examples here
end
#then in a spec
describe 'something' do
it_behaves_like 'title of shared examples'
@Olgagr
Olgagr / short_syntax_factory_girl.rb
Created June 2, 2013 07:09
shorter syntax for factory_girl
# in spec_helper
RSpec.configure do |config| do
#other code
config.include FactoryGirl::Syntax::Methods
end
@Olgagr
Olgagr / controller_private_setter_for_local_variable.rb
Created June 15, 2013 15:48
Controller private setter for local variable
class FollowingRelationshipsController < ApplicationController
def create
current_user.follow user
redirect_to user
end
def destroy
current_user.unfollow user
redirect_to user