Skip to content

Instantly share code, notes, and snippets.

View ekampp's full-sized avatar
💚
Work. Work. It's hard to be green you know.

Emil Kampp ekampp

💚
Work. Work. It's hard to be green you know.
View GitHub Profile
@ekampp
ekampp / _form.html.haml
Created January 29, 2012 20:45
Rails 3.2 not rendering partial corrent
Testing...
@ekampp
ekampp / Gemfile.lock (after deletion)
Created June 5, 2012 13:51
With and without mongoid 3.
GIT
remote: git://github.com/evansagge/mongoid-rspec.git
revision: cc184b8b41f3e5bac4e769444f633e9d7cf2b294
specs:
mongoid-rspec (1.4.5)
mongoid (>= 2.4.6)
rake
rspec (>= 2.9)
GIT
@ekampp
ekampp / random_time.rb
Created August 28, 2012 07:52
Random time extention
class Date
# Samples a random time
#
# Parameters
# This takes up to three parameters, that is a range of `years`, `months` and
# `days`. Each defining the boundries of the sample date.
#
# Examples
# `Time.random({ years: 1..2 })` will produce a date between one and two
@ekampp
ekampp / synchronizable_collection.coffee
Created September 8, 2012 20:04
Backbone synchronizable collection.
#
# In order to expose the `where` and `query` methods (see query.js) we extend
# from the QueryCollection class instead of the standard backbone collection.
#
class Backbone.StandardCollection extends Backbone.QueryCollection
# Checks that the csrf token is present, otherwise fetch it.
csrfToken: ->
if $("head meta[name='csrf-token']").length > 0
debug.log "CSRF token present."
return true
@ekampp
ekampp / hash.rb
Created April 3, 2013 23:36
My hash class extensions. Currently it contains a nice `compact` method for purging blank values from the hash.
class Hash
def compact
self.select{|k,v| !v.blank? }
end
end
@ekampp
ekampp / form.rb
Last active December 15, 2015 18:49
Filling out a form, simply in capybara. I always felt that doing the whole "within.. fill_in..." felt a bit tiresome for standard forms. So I extracted it into an includable context snippet.
# This will fill out the form defined in the `form` hash, and it will fill the
# form elements with the data from the `atrs` hash. So you need to define both
# before incuding this context.
#
# The smallest, possible example:
#
# include_context :fill_and_submit_form do
# let(:form){ {id: "new_user_form" } }
# let(:atrs) { {name: "Weeble & Bob"} }
# end
@ekampp
ekampp / crud.rb
Created April 15, 2013 10:35
Some shared context and examples that I often use when dealing with CRUD actions in Rspec.
shared_examples :denied_access do
before{ action }
it { request.should redirect_to sign_in_path }
it { response.status.should eq 302 }
end
shared_examples :response_ok do
before{ action }
it { response.should be_success }
it { response.status.should eq 200 }
@ekampp
ekampp / actual result
Created September 20, 2016 19:46
Multi-table recursive SQL
uid
1
2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css" />
</head>
<body style="background-color: #fff;">
<p>Current style:</p>
@ekampp
ekampp / All products send
Created February 26, 2019 14:31
SKU statistics
370-230174-230174
370-230174-230174-40
370-230174-230174-41
370-230174-230174-42
370-230174-230174-43
370-230174-230174-45
370-230174-230174-46
370-230174-230174-47
370-230174-230174-48
370-230176-230176