Skip to content

Instantly share code, notes, and snippets.

require 'resolv'
class EmailValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if Resolv::DNS.new.getresources(value.split("@").last, Resolv::DNS::Resource::IN::MX).empty?
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
rescue Resolv::ResolvError, Resolv::ResolvTimeout
record.errors[attribute] << (options[:message] || "does not have a valid domain")
end
<?php
/**
* Get first paragraph from a WordPress post. Use inside the Loop.
*
* @return string
*/
function get_first_paragraph(){
global $post;
$str = wpautop( get_the_content() );
/usr/libexec/PlistBuddy -c 'Add :LSUIElement bool true' /Applications/iTerm.app/Contents/Info.plist
<?php
// =================================================================
// getShares
// @author: Constantin Guay
// @url: https://gist.github.com/Cog-g/8284663
// v. 1.5.6
//
// This script will get number of shares for usual social networks.
//
// @param:
/* @author 14islands.com
* SASS mixins for future proof resolution media query
*/
@mixin if-min-resolution($dppx) {
@include if-resolution(min, $dppx) {
@content;
}
}

This runs provides an .optim job for dragonfly and also adds the .optim job into .thumb

This requires you have the 'image_optim' gem and it's dependencies.

// Adapted from the awesome zurb foundation
// https://github.com/zurb/foundation/blob/v5.2.0/scss/foundation/components/_block-grid.scss
//
// Block Grid Mixins
//
// We use this to control the maximum number of block grid elements per row
$block-grid-elements: 12 !default;
module DefaultValues
def has_default_values(default_values = {})
cattr_accessor :default_values
self.default_values = default_values
after_initialize :assign_default_values
include InstanceMethods

This provides an .optim method for Dragonfly.

This requires you have the 'image_optim' gem in your Gemfile

# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end