Skip to content

Instantly share code, notes, and snippets.

@PetrKaleta
PetrKaleta / gist:946362
Created April 28, 2011 13:38
Sequel error in macruby
irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'sequel'
=> true
irb(main):003:0> DB = Sequel.sqlite
=> #<Sequel::SQLite::Database: "sqlite:/">
irb(main):004:0> DB.create_table :items do
irb(main):005:1> primary_key :id
irb(main):006:1> String :title
irb(main):007:0> end
@PetrKaleta
PetrKaleta / gist:946712
Created April 28, 2011 16:36
Macruby alias_method in module bug
class Base
module InstanceMethods
alias_method :model, :class
end
end
class Model
include Base::InstanceMethods
end
@PetrKaleta
PetrKaleta / gist:951931
Created May 2, 2011 17:09
Sequel error in macruby
require 'rubygems'
require 'sequel'
DB = Sequel.sqlite
DB.create_table :models do
primary_key :id
column :first_attr, :fixnum
column :second_attr, :string
@PetrKaleta
PetrKaleta / gist:980671
Created May 19, 2011 12:47
jQuery plugin starter with methods support
(function($) {
$.fn.myPlugin = function(options, args){
this.each(function(){
$this = $(this);
var instance = $this.data('myPlugin');
if (instance && typeof(instance) == 'object')
callInstance(instance, options, args);
else
@PetrKaleta
PetrKaleta / gist:1084214
Created July 15, 2011 06:46
mini_magick error
Command ("identify -ping /var/folders/Y6/Y6ctKVyOFjCFdBR1qX2zuU+++TI/-Tmp-/mini_magick20110715-72476-oai3or-0.jpg") failed: {:status_code=>127, :output=>"sh: identify: command not found\n"}
@PetrKaleta
PetrKaleta / gist:1527710
Created December 28, 2011 11:57
Simple OOP pattern
log = (o) -> console.log o
# -------------- CLASS DEFINITIONS -------------
# Private methods are starting with underscore, but this is just for better readability
class SimpleOOPPattern
@classProperty: 'le class property'
@classMethod: ->
'le class method'
publicProperty: 'le public property'
@PetrKaleta
PetrKaleta / gist:1548614
Created January 1, 2012 23:13
How to append rendered Hogan.js template into some DOM element
# use pre-compiled template
piicHTML = HoganTemplates.piic.render { link: '#', url: 'http://foo.bar/image.jpg' }
# used just for htmlString => DOMElement conversion
el = document.createElement 'span'
el.innerHTML = piicHTML
# append all first childs
@piicsContainer.appendChild el.firstChild while el.firstChild
@PetrKaleta
PetrKaleta / gist:1557073
Created January 3, 2012 21:38
How to work properly with event listeners in CoffeeScript classes
class SomeClass
constructor: ->
@message = 'Page scrolled'
window.addEventListener 'scroll', @onPageScrolled, no
# note I'm using a fat arrow (check how the compiler handle it)
onPageScrolled: =>
alert @message
@PetrKaleta
PetrKaleta / Caffeinated.coffee
Created January 8, 2012 21:38
Micro JavaScript library written in CoffeeScript to solve my needs when creating mobile web apps for iOS.
###
Caffeinated.js 1.0.1
(c) 2012 Petr Kaleta, @petrkaleta
Caffeinated.js is freely distributable under the MIT license.
Micro JavaScript library written in CoffeeScript to make my life easier when creating mobile web apps for iOS.
I don't like extending built-in JavaScript objects, so I've created this lib as an separate object.
I used underscore identifier to make its calls short as possible. So please do not mess this lib with gorgeous
Underscore.js lib by Jeremy Ashkenas, DocumentCloud Inc.
Some methods are inspired or borrowed from popular JavaScript frameworks like jQuery, Underscore.js and Prototype.js
@PetrKaleta
PetrKaleta / config.ru
Created March 20, 2012 14:27
The Rack::TryStatic middleware delegates requests to Rack::Static middleware trying to match a static file
# config.ru
# The Rack::TryStatic middleware delegates requests to Rack::Static middleware
# trying to match a static file
#
# Inspired by original code from rack-contrib
# http://github.com/rack/rack-contrib/blob/master/lib/rack/contrib/try_static.rb
#
module Rack