Skip to content

Instantly share code, notes, and snippets.

View stan's full-sized avatar
💭
¯\_(ツ)_/¯

stan

💭
¯\_(ツ)_/¯
View GitHub Profile
require 'spec_helper'
class ::ParentDoc
include MongoMapper::Document
many :embedded_docs
many :child_docs
key :name, String
end
class ::EmbeddedDoc
@cowboyd
cowboyd / allruby.rb
Created January 17, 2011 19:36
Proof of concept for making all ruby available to javascript.
require 'v8'
require 'openssl'
class Module
def [](name)
self.const_get(name)
end
end
@rawsyntax
rawsyntax / gist:789162
Created January 21, 2011 02:45
an example model (with activemodel validations)
class Example
include ActiveModel::Validations
##
# Validates a URL
#
# If the URI library can parse the value, and the scheme is valid
# then we assume the url is valid
#
class UrlValidator < ActiveModel::EachValidator
@iconara
iconara / Redis questions on StackOverflow
Created January 24, 2011 16:20
How to query StackOverflow for the most recent, unanswered but upvoted, questions tagged "redis"
#!/usr/bin/env ruby
require 'zlib'
require 'open-uri'
require 'json'
io = Zlib::GzipReader.new(open("http://api.stackoverflow.com/1.0/questions?tagged=redis&sort=votes&min=1"))
obj = JSON.parse(io.read)
/* `XHTML, HTML4, HTML5 Reset
----------------------------------------------------------------------------------------------------*/
a,
abbr,
acronym,
address,
applet,
article,
aside,
class Message < ActiveRecord::Base
validate :image_size_validation, :if => Proc.new { |m| m.image.present? }
mount_uploader :image, MessageImageUploader
private
def image_size_validation
errors[:image] << "should be less than 2MB" if image.size > 2.megabytes
end
@desandro
desandro / jquery.imagesloaded.js
Created January 26, 2011 18:01 — forked from paulirish/README.md
$.fn.imagesLoaded jQuery plugin
// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images
// Modified with a two-pass approach to changing image
// src. First, the proxy imagedata is set, which leads
// to the first callback being triggered, which resets
// imagedata to the original src, which fires the final,
// user defined callback.
$(document).ready(function(){
var focus = true;
var count = 0;
var title = document.title;
$(window).focus(function(){
focus = true;
count = 0;
setTimeout(function(){
document.title = title;
@capotej
capotej / deobfuscator.rb
Created February 2, 2011 07:30
the opposite of
require 'erb'
src = File.read(ARGV[0])
data_segment = src.split(/(;)/).first
code_segment = src.split(/(;)/)[1..-1].join
data_segment.match(/var (_0x\w*{4})=/)
holder_var = $1
$strings_arr = eval(data_segment.split('=').last)
@igrigorik
igrigorik / ruby-1.9-tips.rb
Created February 3, 2011 17:19
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"