Skip to content

Instantly share code, notes, and snippets.

View masqita's full-sized avatar

Peter De Berdt masqita

View GitHub Profile
@masqita
masqita / background-via-keyword.html
Created November 5, 2012 16:02
Snel voorbeeldje van keyword detection met dynamische achtergrond
<!doctype html>
<head>
<title>Achtergrond instellen ahv eerste keyword</title>
<style type="text/css">
body {
height: 100%;
background: #e0e0e0 no-repeat center center fixed;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
@masqita
masqita / type_caster.rb
Created November 4, 2011 15:13
TypeCaster module
class Boolean
def self.from_json(value)
if value.is_a?(TrueClass) || value.is_a?(FalseClass)
return value
elsif value.is_a?(String)
return value == ("true" || "1")
elsif value.is_a?(Integer)
return value == 1
else
nil
@masqita
masqita / json_trees.rb
Created October 27, 2010 07:50
Providing a common interface for models to convert to for example a JSON structure
# Put these modules and classes in separate files of course
module ToTree
# Module that will handle the conversion to a generic hashlike structure
# and also provides a common interface for model specific modules
def to_tree(uri_method)
self.tree_attributes.merge('url' => uri_method.call(self)) # We will use the method passed in from the controller to construct the url
end
# In /lib/foo_bar_middleware.rb
class FooBarMiddleware
def initialize(app, options={})
@app = app
# options will be {:foo => :bar} if you look lower down, you can use this in other methods etc
@options = options
end
@masqita
masqita / compare.js
Created December 3, 2009 08:01 — forked from wycats/compare.js
// prototype
new Ajax.Request("/your/mom", onSuccess: function(response) { $("lightbox_content").innerHTML = response.responseJSON.contents })
// jquery
$.getJSON("/your/mom", function(json) { $("#lightbox_content").html(json.contents) })
// prototype sprinkled with a bit of love (last command out of my head)
// Helpers to make JSON requests a bit cleaner.
Ajax.Json = {