Skip to content

Instantly share code, notes, and snippets.

View datenimperator's full-sized avatar

Christian Aust datenimperator

View GitHub Profile
@mrnugget
mrnugget / forking_rspec.rb
Last active August 29, 2015 14:22
Run RSpec tests on multiple processes at the same time
#!/usr/bin/env ruby
ENV['RAILS_ENV'] = 'test'
require 'benchmark'
rails_loading_time = Benchmark.measure { require './config/environment' }
puts "Rails env loaded in #{rails_loading_time}"
NUM_FORKS = 2
test_groups = `find ./spec -type f -iname "*foobar*"`.split("\n").in_groups(NUM_FORKS).to_a
@mikezter
mikezter / standard_brief_b.rb
Created February 22, 2010 17:05
Briefblatt nach DIN 676 - Formblatt B
require 'prawn/measurement_extensions.rb'
class StandardBriefB < Prawn::Document
def initialize(*args)
super(
:page_size => 'A4',
:page_layout => :portrait,
:margin => [107.4.mm, 8.1.mm, 30.mm, 24.1.mm]
)
options = args.last.is_a?(Hash) ? args.last : {}
@erikng
erikng / swupd.conf
Last active December 26, 2015 10:58
Mountain Lion Server - Maverick Client Support
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} Darwin/9
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-leopard.merged-1.sucatalog
RewriteCond %{HTTP_USER_AGENT} Darwin/10
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-leopard-snowleopard.merged-1.sucatalog
RewriteCond %{HTTP_USER_AGENT} Darwin/11
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-lion-snowleopard-leopard.merged-1.sucatalog
RewriteCond %{HTTP_USER_AGENT} Darwin/12
RewriteRule ^/index\.sucatalog$ http://%{HTTP_HOST}/cgi-bin/SoftwareUpdateServerGetCatalog?/index-mountainlion-lion-snowleopard-leopard.merged-1.sucatalog
@hagenburger
hagenburger / examples-old.md
Last active March 24, 2016 17:00
Optimized Rails I18n format

Traditional way

my_key_link: 'World'
my_key: 'Hello %{link}!'                      link: link_to(t('my_key_link'), 'xy')
'Hello <a href="xy">World</a>!'
  • Need to check if raw is required everytime
  • Translators can loose the context
@zdenekdrahos
zdenekdrahos / config.rb
Last active June 8, 2016 10:38
Generate .htaccess in Middleman. https://coderwall.com/p/daflfq
# disable layout
page ".htaccess.apache", :layout => false
# rename file after build
after_build do
File.rename 'build/.htaccess.apache', 'build/.htaccess'
end
@hmans
hmans / info.md
Last active September 25, 2017 01:23
RESTful Rails Controller, 2017 Edition

This is a RESTful Rails controller, implementing all 7 RESTful actions. In my Rails apps, 9 out of 10 controllers will end up looking like this.

class PostsController < ApplicationController
  load_and_authorize_resource

  def create
    @post.save and redirect_to(@post) or render(:new)
  end
@akiellor
akiellor / document_spec.rb
Created January 2, 2012 05:20
XPath matcher using nokogiri.
require 'nokogiri'
RSpec::Matchers.define :have_xpath do |*paths|
match do |doc|
!doc.xpath(*paths).empty?
end
end
def within *paths, &block
describe "within #{paths.inspect}" do
@jameslafa
jameslafa / admin-projects.rb
Created July 17, 2013 10:28
Paperclip with Rails4 and active admin
ActiveAdmin.register Project do
# Don't forget to add the image attribute (here thumbnails) to permitted_params
controller do
def permitted_params
params.permit project: [:title, :summary, :description, :thumbnail, :date, :url, :client_list, :technology_list, :type_list]
end
end
form do |f|
@0bp
0bp / HTML.lua
Last active April 14, 2020 09:42
MoneyMoney HTML Export mit Kategorie und Kommentar
-- The MIT License (MIT)
--
-- Copyright (c) 2014 Boris Penck
--
-- Permission is hereby granted, free of charge, to any person obtaining a copy
-- of this software and associated documentation files (the "Software"), to deal
-- in the Software without restriction, including without limitation the rights
-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-- copies of the Software, and to permit persons to whom the Software is
-- furnished to do so, subject to the following conditions:
@mislav
mislav / easy_way.rb
Last active May 20, 2020 13:48
RESOLVE SHORT URLS before storing. Short URLs are for microblogging; you should never actually keep them around.
require 'net/http'
# WARNING do not use this; it works but is very limited
def resolve url
res = Net::HTTP.get_response URI(url)
if res.code == '301' then res['location']
else url.to_s
end
end