Skip to content

Instantly share code, notes, and snippets.

View brianjlandau's full-sized avatar

Brian Landau brianjlandau

  • Walnut Creek, CA
View GitHub Profile
<% if my_block_content.present? %>
<%= my_block_content%>
<% else %>
<%# default without block %>
<% end %>
@brianjlandau
brianjlandau / paperclip_s3_migrator.rb
Last active July 5, 2018 08:32
This allows you to migrate files on S3 stored by paperclip to a new location.
# Example usage:
#
# PaperclipS3Migrator.new(
# [User, BlogPost, Page],
# ':attachment/:id/:style/:filename',
# ':class/:id/:attachment/:style/:updated_at_:filename'
# ).migrate
#
class PaperclipS3Migrator < Struct.new(:klasses, :old_path, :new_path)
@brianjlandau
brianjlandau / send_imessage_repeatedly.scpt
Last active August 29, 2015 14:06
This sends an iMessage to the person who's phone number you enter 100 times every 5 seconds. Feel free to modify the delay or the number of times to repeat. Enjoy
repeat 100 times
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy "3211234567" of targetService
send "This is an automated message" to targetBuddy
end tell
delay 5
end repeat
Host *
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
@brianjlandau
brianjlandau / gist:da0bab27dcf1d8691f6e
Last active November 16, 2019 01:23
Email validator based on DNS
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
@brianjlandau
brianjlandau / gist:aa33f69932a4089a4de9
Created June 17, 2014 18:07
More strict web URL regex for validations. (better then URI.regexp)
require 'uri'
hostname = "(?:(?:[\\w\\-]+\\.)+[[:alpha:]]{2,})"
host = "(?:#{hostname}|#{URI::DEFAULT_PARSER.pattern[:IPV4ADDR]}|#{URI::DEFAULT_PARSER.pattern[:IPV6ADDR]})"
server = "//(?:#{URI::DEFAULT_PARSER.pattern[:USERINFO]}@)?#{host}(?::\\d*)?"
absolute_path = "(?:#{URI::DEFAULT_PARSER.pattern[:ABS_PATH]})?"
query = URI::DEFAULT_PARSER.pattern[:QUERY]
http_uri_regex = Regexp.new("\\A(?:http|https):(?:#{server}#{absolute_path})(?:\\?(?:#{query}))?\\z", Regexp::EXTENDED, 'N')
@brianjlandau
brianjlandau / secrets.rb
Created April 11, 2014 18:12
Secret ENV values for Heroku apps in dev
secrets_file = Rails.root.join('config', 'secrets.yml')
if secrets_file.file?
ENV.update(YAML.load_file(secrets_file)[Rails.env])
end
set daemon 120
set logfile /var/log/monit.log
set idfile /var/lib/monit/id
set statefile /var/lib/monit/state
set mailserver localhost
set mail-format { from: monit-noreply@viget.com }
@brianjlandau
brianjlandau / rails_resources.md
Created February 7, 2014 16:29 — forked from jookyboi/rails_resources.md
Rails-related Gems and guides to accelerate your web project.

Gems

  • Bundler - Bundler maintains a consistent environment for ruby applications. It tracks an application's code and the rubygems it needs to run, so that an application will always have the exact gems (and versions) that it needs to run.
  • rabl - General ruby templating with json, bson, xml, plist and msgpack support
  • Thin - Very fast and lightweight Ruby web server
  • Unicorn - Unicorn is an HTTP server for Rack applications designed to only serve fast clients on low-latency, high-bandwidth connections and take advantage of features in Unix/Unix-like kernels.
  • SimpleCov - SimpleCov is a code coverage analysis tool for Ruby 1.9.
  • Zeus - Zeus preloads your Rails app so that your normal development tasks such as console, server, generate, and specs/tests take less than one second.
  • [factory_girl](h
@brianjlandau
brianjlandau / javascript_resources.md
Created February 7, 2014 16:29 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage