Skip to content

Instantly share code, notes, and snippets.

View kaievns's full-sized avatar

Kai Evans kaievns

  • Sydney, Australia
View GitHub Profile
@kaievns
kaievns / gist:6228359
Created August 14, 2013 05:53
How to enable nested `feature` constructions in the `rspec` features
#
# Put this somwehere in your `spec/support` folder, then you can do something like that
#
# feature "Stuff" do
# feature 'new' do
# scenario 'user goes in and gets awesomized' do
# end
#
# scenario 'user goes in with evil intentions and doesn't get awesomized' do
# end
@kaievns
kaievns / gist:3158011
Created July 22, 2012 02:38
Paperclip mongoid support that works with mongoid 3
#
# Save this into your `lib/mongoid/paperclip.rb` file
#
#
require "paperclip"
module Paperclip
class << self
data: function() {
return {
trend : this.model.trend,
subtrend : this.model,
next_subtrend : this.model.nextSubtrend(),
next_trend : this.model.trend.nextTrend()
};
}
@kaievns
kaievns / gist:1509909
Created December 22, 2011 10:54
CSS3 Links without icons
a.add, a.edit, a.delete
&:before
margin-right: .25em
a.add:before
content: "\271A"
a.edit:before
content: "\270E"
@kaievns
kaievns / gist:1497611
Created December 19, 2011 15:11
Gradient Buttons The Right Way
// This way you can change the buttons color with a simple `background-color` setting
// without need to regenerate the whole gradient
input[type=button], input[type=submit], button
font-family: Arial, Helvetica
color: #333
border: 1px solid #ccc
border-radius: .25em
text-shadow: 0 1px 1px rgba(0,0,0,.3)
@kaievns
kaievns / gist:1466051
Created December 12, 2011 08:59
MongoID counter_cache hack
#
# Save this in `lib/mongoid/counter_cache.rb`
#
# Then define your relations kinda like that
#
# class Comment
# belongs_to :post, counter_cache: true # 'comments_count'
# belongs_to :user, counter_cache: 'my_field_name'
# end
#
@kaievns
kaievns / gist:1439065
Created December 6, 2011 17:27
RSpec speed up for BCrypt
#
# Making BCrypt to use minimal cost so that the specs run faster
#
# place this in the spec/support/bcrypt.rb file
#
require 'bcrypt'
module BCrypt
class Engine
class << self
@kaievns
kaievns / gist:1200232
Created September 7, 2011 10:28
RJS substitute for right-rails
#
# RJS handler was kicked out of Rails 3.1 along with Prototype
# so, here is a little substitute coz we use it here and there
#
# Just save it in some file in the `config/initializers`
#
module ActionView
module Template::Handlers
class RJS
# Default format used by RJS.
@kaievns
kaievns / gist:1063414
Created July 4, 2011 14:43
Recursive Object -> Query String in CoffeeScript
#
# Recursively converts an object into a query string
#
to_query_string = (data)->
map = (hash, prefix='')->
result = []
for key, value of hash
key = if prefix is '' then key else "#{prefix}[#{key}]"
@kaievns
kaievns / gist:996893
Created May 28, 2011 14:20
Cubic Bezier function emulator
/**
* Cubic Bezier CSS3 transitions emulator
*
* See this post for more details
* http://st-on-it.blogspot.com/2011/05/calculating-cubic-bezier-function.html
*
* Copyright (C) 2011 Nikolay Nemshilov
*/
function Bezier(p1,p2,p3,p4) {
// defining the bezier functions in the polynomial form