Skip to content

Instantly share code, notes, and snippets.

View 5minpause's full-sized avatar

Holger Frohloff 5minpause

View GitHub Profile
### Keybase proof
I hereby claim:
* I am 5minpause on github.
* I am 5minpause (https://keybase.io/5minpause) on keybase.
* I have a public key ASCT5J-ZSNPhZo8noxPXeOXBjg8sR_bbm47SY6uq5TcpQAo
To claim this, I am signing this object:
@5minpause
5minpause / rspec-syntax-cheat-sheet.rb
Created March 9, 2016 11:17 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
var ddoc = {
_id: '_design/index',
views: {
index: {
map: function mapFun(doc) {
if (doc.table_name) {
emit(doc.table_name);
}
}.toString()
}
validVinExp: function () {
// WDD 169 007-1J-236589
// WDB1681331J93895
return new RegExp('^(wdb|wdd)\\s*[\\d\\s]{6,}-?[\\w\\d]{2}-?[\\d]{5,6}$', 'i');
},
evaluateVin: function (value) {
return this.validVinExp().test(value);
},
[commit]
template = ~/.gitmessage
$ git rev-list HEAD -count
2442
@5minpause
5minpause / .gitmessage
Last active August 28, 2015 15:32
ikusei git commit message template
# 50-character subject line
# 72-character wrapped longer description.
# Der Grund für die Änderung (Warum)
# Why is this change necessary?
# Wie löst es die Aufgabe (Wie)
# How does it address the issue?
# This is inside Goldencobra::Permission model
after_commit :set_cache_key
def self.restricted?(item)
@@last_permission ||= Goldencobra::Permission.reorder(:updated_at).last
Rails.cache.fetch("#{@@last_permission.cache_key}#{item.cache_key}") do
where(subject_class: item.class, subject_id: item.id).count > 0
end
end
def self.restricted?(item)
where(:subject_class => item.class, :subject_id => item.id).count > 0
end
@5minpause
5minpause / load_overview_tree.rb
Created August 21, 2015 12:48
After optimizations
collection_action :load_overviewtree_as_json do
if params[:root_id].present?
objects = Goldencobra::Article.where(id: params[:root_id]).first.children.reorder(:url_name)
cache_key ||= ["articles", params[:root_id], objects.map(&:id), objects.maximum(:updated_at)]
articles = Rails.cache.fetch(cache_key) do
Goldencobra::Article.find(params[:root_id])
.children.reorder(:url_name).as_json(only: [:id, :url_path, :title, :url_name],
methods: [:has_children, :restricted])
end