Skip to content

Instantly share code, notes, and snippets.

// Prototype toQueryString fix
(function(){
'use strict';
function typeOf(obj) {
if (obj instanceof Date) {
return 'date';
} else if (Object.isArray(obj)) {
return 'array';
/*
Prototype's helper for quick and easy observing
click events on different elements including
anchors with '#' href
Usage examples:
instead of:
@rwz
rwz / rails_template.rb
Created November 18, 2010 10:42
rails template
run 'rm public/index.html'
run 'rm public/favicon.ico'
run 'rm public/images/rails.png'
# remove Prototype defaults
run 'rm public/javascripts/controls.js'
run 'rm public/javascripts/dragdrop.js'
run 'rm public/javascripts/effects.js'
run 'rm public/javascripts/prototype.js'
@rwz
rwz / doesnt.rb
Created December 13, 2010 06:50
state_machine + delayed_job wtf
# doesn't fucking work
class Logo < ActiveRecord::Base
state_machine :state, :initial => :initial do
# here vvv
after_transition :initial => :used, :do => :test_callback
// тупо
var wiget = new Class({
// ...
getSomething: function(){
if (this.something) return this.something;
this.something = new Element('div');
// тут километры кода
return this.something;
!function(){
function fakeLength(fn, length) {
if (length == fn.length) return fn;
var fakeArgs = [];
while(length--) fakeArgs.push('$fakeArg'+length);
return eval('(function('+fakeArgs.join(',')+'){ return fn.apply(this, arguments); })');
}
Function.prototype.allRequired = function(){
@rwz
rwz / authentication.rb
Created June 14, 2011 10:43
Twitter authentication fail with Omniauth credentials [FIXED, see https://github.com/jnunemaker/twitter/issues/171]
class Authentication < ActiveRecord::Base
belongs_to :user
serialize :info
serialize :credentials
def update_from_omniauth(omniauth)
self.uid = omniauth['uid']
self.provider = omniauth['provider']
self.info = omniauth['user_info']
self.credentials = omniauth['credentials']
@rwz
rwz / ternary.rb
Created February 8, 2012 06:39
A little rubyquiz
my_object.bool_method?? 'yes' : 'no'
# or
my_object.bool_method? ? 'yes' : 'no'
# or
(my_object.bool_method?) ? 'yes' : 'no'
@rwz
rwz / application.html.slim
Created April 11, 2012 06:44
nestive layouts
= extends :html5_base do
- append :head do
meta(http-equiv="X-UA-Compatible" content="IE=edge")
title Lolwut
= area :assets do
= javascript_include_tag 'application'
= yield
#fb-root
@rwz
rwz / gist:2366293
Created April 12, 2012 10:21 — forked from justinfrench/gist:2362758
Nestive
# Expected h1 title for posts#show is "My Blog :: My Post Title"
# --------------------------------------------------------------
# This was how it worked with `layout nil` in the controller
#
# posts_controller.rb
class PostsController
layout nil