Skip to content

Instantly share code, notes, and snippets.

View corny's full-sized avatar

Julian Kornberger corny

View GitHub Profile
@corny
corny / kde_deobfuscate.rb
Created July 31, 2010 10:25
Deobfuscation for KDE passwords
def kde_deobfuscate(str)
chars = str.split("")
out = ''
while chars.any?
b1 = chars.shift
if b1 == 0xef.chr
case chars.shift
when 0xbe.chr
out << (0x1001F - chars.shift[0] - 0xff00).chr
when 0xbf.chr
@corny
corny / devise.de.yml
Created January 3, 2011 16:16 — forked from chrugail/devise.de.yml
German device translations
de:
errors:
messages:
not_found: "nicht gefunden"
already_confirmed: "wurde bereits bestätigt"
not_locked: "ist nicht gesperrt"
devise:
failure:
unauthenticated: 'Sie müssen sich anmelden oder registrieren, bevor Sie weiterfahren können.'
@corny
corny / replace_secret_token.rb
Created March 17, 2012 11:08
Rake task to replace the secret token in your config/initializers/secret_token.rb
#
# License: WTFPL (http://sam.zoy.org/wtfpl/)
#
namespace :secret do
desc 'Replace the secure secret key in your secret_token.rb'
task :replace do
pattern = /(\.secret_token *= *')\w+(')/
secret = SecureRandom.hex(64)
filepath = "#{Rails.root}/config/initializers/secret_token.rb"
@corny
corny / symlink_secret.rb
Created March 17, 2012 12:25
Capistrano recipe to move and replace the secret-token on deployment if missing in shared directory
@corny
corny / application_controller.rb
Created March 17, 2012 14:44
A handler for PostgreSQL Foreign Key Constraint Exceptions to insert in your ApplicationController
class ApplicationController < ActionController::Base
# A foreign key constraint exception from the database
rescue_from PG::Error do |exception|
message = exception.message
if message.include?('foreign key constraint')
logger.warn(message)
# shorten the message
message = message.match(/DETAIL: .+/).to_s
@corny
corny / date_scope.rb
Created March 29, 2012 10:55
Flexible rails scope for date-attributes in a PostgreSQL table
#
# Scopes for date attribute
# https://gist.github.com/2235839
#
module Common::DateScope
extend ActiveSupport::Concern
included do
unless respond_to?(:year)
@corny
corny / active_resource_errors.rb
Created March 29, 2012 23:13
Monkey patch to fix JSON error decoding in ActiveResource 3
# Monkey patch to fix Rails JSON error decoding
# https://gist.github.com/2244799
class ActiveResource::Errors
def from_json(json, save_cache = false)
clear unless save_cache
decoded = ActiveSupport::JSON.decode(json)
if decoded.is_a?(Hash)
@corny
corny / respond_to.sass
Created April 4, 2012 19:04
bootstrap-sass mixin for responsive designs
// bootstrap-sass mixin for responsive designs
// this mixin requires sass support for content blocks (sass >= 3.2.0)
// Media widths:
// http://twitter.github.com/bootstrap/scaffolding.html#responsive
// https://github.com/digineo/bootstrap-sass/commit/20828376f7cf72ec1ca808633dde186c5682ea97
=respond-to($media)
@if $media == phone
@media only screen and (max-width: $mediaPhone)
@corny
corny / will_paginate_bootstrap.rb
Created April 14, 2012 19:54
WillPaginate renderer for will_paginate 2.3.16 to generate HTML code for Twitter Bootstrap
#
# WillPaginate renderer for will_paginate 2.3.16 to generate HTML code for Twitter Bootstrap
# Put this content in in your config/initializers/will_paginate.rb
module WillPaginate
module ViewHelpers
class BootstrapLinkRenderer < LinkRenderer
def to_html
@corny
corny / pagination_helper.rb
Created April 14, 2012 21:56
PaginationHelper for will_paginate
module PaginationHelper
# adds a pagination before and after the given block
def pagination(collection=nil, options={}, &block)
# no Collection given? then call collection method
collection ||= send :collection
pages = will_paginate(collection, options)
html = ''