Skip to content

Instantly share code, notes, and snippets.

@rwz
rwz / README.md
Created September 26, 2014 00:40
A form-object solution of my wet dreams.

Let's call it AdequateForm for now.

class SignUpForm < AdequateForm
  attribute :first_name
  attribute :last_name
  attribute :birthdate, :date
  
  validates :first_name, :birthdate, presence: true
end
// look ma, no jquery
// assuming that you have
// <a data-komments-permalink="/foobar">comments count goes here</a>
// somewhere in your HTML
function _kmtsLoaded(){
var links = [].slice.apply(document.querySelectorAll("a[data-komments-permalink]"));
links.forEach(function(link){
// 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'
// тупо
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