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
json.data do
json.partial! "board/items/item", locals: { item: @item }
end
json.meta do
json.receipt @receipt if @receipt.present?
json.genesis_address @item.genesis_address
json.short_address @item.short_address
end
# frozen_string_literal: true
require "hash"
def pretty_name(string)
return "election" if string.to_s == "genesis_item"
string.to_s.gsub("_configuration_item", "")
end
@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
<!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 / actual result
Created September 20, 2016 19:46
Multi-table recursive SQL
uid
1
2
@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 / 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 / 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 / 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 / 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