Skip to content

Instantly share code, notes, and snippets.

View paulkoegel's full-sized avatar

Paul Kögel paulkoegel

View GitHub Profile
@paulkoegel
paulkoegel / gist:1408656
Created November 30, 2011 10:54
auto_link XML fuckup
- raise auto_link @text
"Winamp for Mac." Wait, what!? <a href="http://t.co/z7weqDII"{:xmlns=>"http://www.w3.org/1999/xhtml", "xml:lang"=<{:rel=>"nofollow", :class=<nil}, :lang=>{:rel=<"nofollow", :class=>nil}}<http://t.co/z7weqDII>/a<
not reproducible in console, where everything looks like it should:
ruby-1.9.3-p0 :001 > t = GridItem.tweets.any_in(:hashtags => ['sebastian_kippe']).first.text
=> "\"Winamp for Mac.\" Wait, what!? http://t.co/z7weqDII"
ruby-1.9.3-p0 :002 > helper.auto_link t
=> "\"Winamp for Mac.\" Wait, what!? <a href=\"http://t.co/z7weqDII\" rel=\"nofollow\">http://t.co/z7weqDII</a>"
@paulkoegel
paulkoegel / gist:1600009
Created January 12, 2012 11:35
Installing Postgres on OSX Lion for Rails 3.2
{
"y-u-no-http": "Tell us what's wrong with this request you just made =)",
"company": "Railslove GmbH",
"email": "team@railslove.com",
"pictures": "http://www.flickr.com/search/?q=railslove&s=rec&ss=1&z=e",
"office": "http://cowoco.de",
"locations": [
"Cologne, Germany",
"Hamburg, Germany"
$(function() {
var circle, circleLocation, circleOptions, cloudmade, cologne, map, marker, markerLocation;
map = new L.Map('map');
cloudmade = new L.TileLayer('http://{s}.tile.cloudmade.com/3b477058df1d402fb1ea6f45611880e9/997/256/{z}/{x}/{y}.png', {
attribution: 'Map data &copy; <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://cloudmade.com">CloudMade</a>',
maxZoom: 18
});
cologne = new L.LatLng(50.9293001, 6.9577079);
map.setView(cologne, 13).addLayer(cloudmade);
markerLocation = new L.LatLng(51.5, -0.09);
@paulkoegel
paulkoegel / subregions_idea.js
Created November 30, 2012 08:04
Is there a way to define Marionette subregions like this? Wouldn't this be cool?
// SCENARIO: i have an overview page with several regions.
// when clicking on an item, an overlay is opened (overview remains in the DOM).
// the overlay has several Marionette regions as well (article intro, article body,
// related articles, its own footer)
// QUESTION: wouldn't it be cool to render views by calling myApp.overlay.mainContent(new ArticleView())?
myApp.addRegions({
overview: {
el: '#overview',
@paulkoegel
paulkoegel / gist:4566993
Created January 18, 2013 18:30
Synchronously load RequireJS-modularized QUnit tests and start QUnit afterwards This fixes an annoying issue with rerunning single QUnit tests. When loading tests asynchronously, single tests are identified by numerical IDs and since their order can change between reloads, you can't be sure you'll rerun the same test twice.
// author: Mathias Schäfer (@molily)
QUnit.config.autostart = false;
var modules = ['module_a', 'module_b'];
function loadNext () {
var module = modules.shift();
if (module) {
require([module], loadNext);
} else {
QUnit.start();
}
@paulkoegel
paulkoegel / mixed_layout.md
Last active December 11, 2015 19:28
Extended MarionetteLayout to which you can pass an array of region names and View instances (via .addViews()); automatically creates the required region DOM containers. SEE BELOW FOR CODE.

MixedLayout

MixedLayouts are our custom extension of MarionetteLayouts which we use to wrap a heterogeneous collection of Backbone Views. This allows us to change the contents of complex pages all at once while preventing zombie views and leaving certain static elements like Navigation, Toolbar, or FooterViews on the page.

Rationale and Raison d'être

Marionette's Composite and CollectionViews are limited to rendering all their associated collection's items with the same ItemView. For our homepage, e.g., we need to encapsulate various Views - TopView, CategoryView, QuoteOfTheDayView etc. - in dynamic order into one Marionette View construct that can be .closed() to prevent zombie views. The Marionette view component designed to encapsulate heterogeneous subviews is the Layout. However, we cannot use a vanilla MarionetteLayout for the homepage because a Layout relies

@paulkoegel
paulkoegel / window_innerHeight_ios.coffee
Last active January 29, 2016 18:47
Workaround to get the real window.innerHeight on Safari and Chrome on iOS with auto-hiding address bars
# window.innerHeight with auto-hiding address bar
# When calling `window.innerHeight` on DOM.ready in Safari or Chrome
# on iOS (in 2013-05 at elast ;) you'll get the height of the available
# screen area between the address bar - which is displayed on page load and
# then automatically hidden once you start scrolling - and the toolbar.
# On my iPhone simulator it's 356px with the address bar and 416px without.
# To get the window's real height, we first need to trigger a scroll event,
# which will auto-hide the address bar, and then chain all further calculations
# of window.innerHeight inside a timeout. Ironically, when loading the page,
module Slug
def generate_slug
temp_slug = SecureRandom.hex 8
# ensure slug is unique
while self.class.where(slug: temp_slug).count > 0
temp_slug = SecureRandom.hex 8
end
self.slug = temp_slug
end
@paulkoegel
paulkoegel / strong_parameter_matcher.rb
Created September 12, 2013 16:01 — forked from DonSchado/example_spec.rb
Thoughtbot retracted their initial implementation of strong parameters matchers in v2.0.0 of shoulda-matchers, so we decided to build our own until new officail ones are released. The following is a small matcher for testing what params should be permitted in controllers. The matcher's syntax is based on validation matchers. If you're not follow…
# usage:
#
# it { should permit_params(:email, :name) }
# it { should permit_params(:email, :name).for_class(SpecialUser) }
# it { should permit_params(:name).params_method(:my_params_method) }
module StrongParameterMatcher
class PermitMatcher
attr_reader :permitted_params, :errors_protected, :errors_permitted