Skip to content

Instantly share code, notes, and snippets.

@fauxparse
fauxparse / 04_make_it_better.js
Created August 8, 2011 17:50
JS Master Class Ex 4
function isCreditCard(CC) {
if (CC.length < 20) {
for (var i = 0, l = CC.length, double = false, sum = 0;
i < l;
i++, double = !double) {
var digit = CC.substring(l-i-1,l-i),
tproduct = parseInt(digit ,10) * (double ? 2 : 1);
sum += Math.floor(tproduct / 10) + tproduct % 10;
}
@fauxparse
fauxparse / gist:1003436
Created June 1, 2011 21:58
Textmate command to convert hex to RGB(A) to hex
#!/usr/bin/env ruby
color = ENV['TM_SELECTED_TEXT'] || ENV['TM_CURRENT_WORD']
if color =~ /^\#?(([0-9a-f]{3}){1,2})$/i
hex = $1
hexes = if hex.length == 3
[hex[0, 1] * 2, hex[1, 1] * 2, hex[2, 1] * 2]
else
[hex[0, 2], hex[2, 2], hex[4, 2]]
/**
* Style definitions for banner management
*/
.ui-split {
position: relative;
}
.ui-split-pane {
position: absolute;
module Mongoid
module Markdown
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def markdown(*attributes)
write_inheritable_attribute(:markdown_attributes, markdown_attributes + Array(attributes))
@markdown_unicode = String.new.respond_to? :chars
module Mongoid
module DeepCloning
def deep_clone(attrs = {}, obj = nil)
returning obj || self.class.new do |o|
o.write_attributes(@attributes.merge(attrs).except("_id", "versions").except(*o.class.associations.keys))
yield o if block_given?
o.save
@attributes.each_pair do |key, value|
next unless proxy = self.associations[key]
case proxy.association
class Account
include Mongoid::Document
include Mongoid::Timestamps
field :subdomain, :type => String
embeds_many :users
accepts_nested_attributes_for :users
validates_presence_of :name, :subdomain
validates_uniqueness_of :subdomain, :case_sensitive => false
class InlinePremailer < ::Premailer
def initialize(string, options = {})
@options = {:warn_level => Warnings::SAFE,
:line_length => 65,
:link_query_string => nil,
:base_url => nil,
:remove_classes => false}.merge(options)
@html_file = @options[:base_url]
@is_local_file = false
require File.expand_path(File.dirname(__FILE__) + "/../../../spec_helper")
class ValidationTest
include ActiveModel::Validations
before_validate :do_something
validates_presence_of :something
def do_something
raise "callback"
class Post
key :title, String
key :slug, String
validates_presence_of :title, :slug
validates_uniqueness_of :slug
before_create :fill_in_slug
protected
def fill_in_slug
@fauxparse
fauxparse / og.sh
Created January 3, 2010 03:04
Scripts to open a gem's source in TextMate, and its RDoc in Safari
#!/bin/bash
myfile=/usr/local/lib/ruby/gems/1.8/gems/`ls "/usr/local/lib/ruby/gems/1.8/gems" | grep -e "^$1" | tail -1`
if [ -d $myfile ]
then
mate $myfile
else
echo "Couldn't find a gem called $1"
fi