Mongoid implementation of Ryan Bates authentication-from-scratch lesson on Railscasts.
Also uses 'username' rather than 'email' for validation
Commandline:
rails new authmongoid -O
cd authmongoid/
Gemfile:
class Video < ActiveRecord::Base | |
validates_presence_of :title | |
named_scope :finished, :conditions => { :encoded_state => "finished" } | |
has_attached_file :video, | |
:url => ":class/:id/:style/:basename.:extension", | |
:path => ":class/:id/:style/:basename.:extension", | |
:storage => :s3 | |
validates_attachment_presence :video |
module NullifyBlankAttributes | |
def write_attribute(attr_name, value) | |
new_value = value.presence | |
super(attr_name, new_value) | |
end | |
end |
# db/migrate/#{timestamp}_add_owner_to_delayed_jobs | |
class AddOwnerToDelayedJobs < ActiveRecord::Migration | |
def self.up | |
add_column(:delayed_jobs, :owner_type, :string) | |
add_column(:delayed_jobs, :owner_id, :integer) | |
end | |
def self.down | |
remove_column(:delayed_jobs, :owner_type) | |
remove_column(:delayed_jobs, :owner_id) |
# Parses YouTube URLs directly or from iframe code. Handles: | |
# * Address bar on YouTube url (ex: http://www.youtube.com/watch?v=ZFqlHhCNBOI) | |
# * Direct http://youtu.be/ url (ex: http://youtu.be/ZFqlHhCNBOI) | |
# * Full iframe embed code (ex: <iframe src="http://www.youtube.com/embed/ZFqlHhCNBOI">) | |
# * Old <object> tag embed code (ex: <object><param name="movie" value="http://www.youtube.com/v/ZFqlHhCNBOI">...) | |
/(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/ | |
$5 #=> the video ID | |
# test it on Rubular: http://rubular.com/r/eaJeSMkJvo |
#! /usr/bin/env python | |
import redis | |
import random | |
import pylibmc | |
import sys | |
r = redis.Redis(host = 'localhost', port = 6389) | |
mc = pylibmc.Client(['localhost:11222']) |
// ==UserScript== | |
// @name Use Markdown, sometimes, in your HTML. | |
// @author Paul Irish <http://paulirish.com/> | |
// @link http://git.io/data-markdown | |
// @match * | |
// ==/UserScript== | |
// If you're not using this as a userscript just delete from this line up. It's cool, homey. |
/** | |
* jQuery alterClass plugin | |
* | |
* Remove element classes with wildcard matching. Optionally add classes: | |
* $( '#foo' ).alterClass( 'foo-* bar-*', 'foobar' ) | |
* | |
* Copyright (c) 2011 Pete Boere (the-echoplex.net) | |
* Free under terms of the MIT license: http://www.opensource.org/licenses/mit-license.php | |
* | |
*/ |
Mongoid implementation of Ryan Bates authentication-from-scratch lesson on Railscasts.
Also uses 'username' rather than 'email' for validation
Commandline:
rails new authmongoid -O
cd authmongoid/
Gemfile:
Rails flash messages with AJAX requests
In August 2007 a hacker found a way to expose the PHP source code on facebook.com. He retrieved two files and then emailed them to me, and I wrote about the issue:
http://techcrunch.com/2007/08/11/facebook-source-code-leaked/
It became a big deal:
http://www.techmeme.com/070812/p1#a070812p1
The two files are index.php (the homepage) and search.php (the search page)