Skip to content

Instantly share code, notes, and snippets.

View corny's full-sized avatar

Julian Kornberger corny

View GitHub Profile
@corny
corny / error_pages.rb
Created May 12, 2012 11:32
Custom error pages
#
# Usage:
# class ApplicationController < ActionController::Base
# include ErrorPages
# end
#
module ErrorPages
extend ActiveSupport::Concern
@corny
corny / jquery.get_cached_script.js
Created May 14, 2012 12:17
$.getScript with caching
jQuery.getCachedScript = function(url, callback, options) {
// allow user to set any option except for dataType, cache, and url
options = jQuery.extend(options || {}, {
dataType: "script",
cache: true,
url: url,
complete: callback || jQuery.noop
});
// Use jQuery.ajax() since it is more flexible than $.getScript
@corny
corny / mysql2_dump_triggers.rb
Created June 1, 2012 11:16
Hot fix that adds support for dumping triggers to the mysql2 adapter.
# config/initializers/mysql2_dump_triggers.rb
module TriggerDumper
def structure_dump
super << select_all("SHOW TRIGGERS").map { |trigger|
exec_without_stmt("SHOW CREATE TRIGGER #{trigger['Trigger']}").first['SQL Original Statement'].sub(/DEFINER=\S+ /,'') << "\n\n"
}.join
end
end
@corny
corny / array_tests.md
Created July 9, 2012 19:28
Tests for a elastic search plugin

Recipes (number) with ingredients (letter):

    1. A B
    1. B C D
    1. D

All must match:

  • Query for A matches 1
  • Query for B matches 1,2
  • Query for C matches 2
  • Query for D matches 3
@corny
corny / google_oauth2_access_token.rb
Created August 24, 2012 19:11 — forked from jotto/google_oauth2_access_token.rb
ruby command line script for generating google oauth2 access token
# (create oauth2 tokens from Google Console)
client_id = ""
client_secret = ""
# (paste the scope of the service you want here)
# e.g.: https://www.googleapis.com/auth/gan
scope = ""
@corny
corny / seo-slugs.rb
Created August 27, 2012 13:05
seo slugs
class MyModel < ActiveRecord::Base
def to_param
"#{id}-#{name}".parameterize
end
end
@corny
corny / shoulda_robots_matcher.rb
Created August 29, 2012 16:36
Shoulda macro for testing the robots.txt
#
# Shoulda Macros for testing the robots.txt
# =========================================
#
# source: https://gist.github.com/3515360
# inspiration: https://github.com/fizx/robots/blob/master/lib/robots.rb
# license: WTFPL http://sam.zoy.org/wtfpl/
#
# Example usage:
#
@corny
corny / devise.de.yml
Created September 10, 2012 23:51
german i18n for devise 2.0
de:
errors:
messages:
expired: "ist abgelaufen, bitte neu anfordern"
not_found: "nicht gefunden"
already_confirmed: "wurde bereits bestätigt"
not_locked: "ist nicht gesperrt"
not_saved:
one: "Konnte %{resource} nicht speichern: ein Fehler."
other: "Konnte %{resource} nicht speichern: %{count} Fehler."
@corny
corny / async_helper.rb
Created October 8, 2012 18:17
Resque Helpers
module AsyncHelper
extend ActiveSupport::Concern
module ClassMethods
def perform(id, method, *args)
find(id).send(method, *args)
end
end
def async(method, *args)
@corny
corny / jwebsocket2github.sh
Created October 31, 2012 15:01
migration of jwebsocket to github
# clone repo
svn2git http://jwebsocket.googlecode.com/svn
# remove unwanted files
git filter-branch --index-filter "git rm -rf --cached --ignore-unmatch \
jWebSocketDownloads \
jWebSocketExecutables \
jWebSocketRTE \
jWebSocketClient/web/javadocs \
jWebSocketDeployment \