I don't like Sprockets, but it's the easiest and best choice for lots of Ruby on Rails projects. When looking for a better way to manage my JavaScript assets and an improved developer story, my current tool of choice is webpack. While I wish Rails supported drop-in asset pipelines the way that Phoenix does, it's not hard to use webpack with Rails.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rexml/document' | |
require 'rexml/xpath' | |
require 'http' | |
require 'icalendar' | |
HTTP::Request::METHODS = HTTP::Request::METHODS + [:report] | |
module AppleCalDav | |
class Client | |
attr_accessor :username, :password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://coderwall.com/p/qp2aha/ruby-pbcopy-and-pbpaste | |
def pbcopy(input) | |
str = input.to_s | |
IO.popen('pbcopy', 'w') { |f| f << str } | |
str | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rexml/document' | |
require 'rexml/xpath' | |
require 'http' | |
require 'icalendar' | |
HTTP::Request::METHODS = HTTP::Request::METHODS + [:report] | |
module AppleCalDav | |
class Client | |
attr_accessor :username, :password |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Modified from: | |
# http://findingscience.com/ruby/ssl/2013/01/13/reading-an-ssl-cert-in-ruby.html | |
require "socket" | |
require "openssl" | |
host = "www.piranhas.co" | |
tcp_client = TCPSocket.new("www.piranhas.co", 443) | |
ssl_client = OpenSSL::SSL::SSLSocket.new(tcp_client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'resolv' | |
class DnsCheck | |
attr_reader :host | |
def initialize(host) | |
@host = host | |
end | |
def a | |
@a ||= Resolv::DNS.new.getresources(host, Resolv::DNS::Resource::IN::A) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Defines a namespace for my application | |
MyApplication = {} | |
# A way to pass a callback both to jQuery's "ready" and turbolinks' "page:load" events | |
MyApplication.onDocumentReady = (callback) -> | |
$(document).ready(callback) | |
$(document).on('page:load', callback) | |
# Defines a function to load the SumoMe script | |
MyApplication.load_sumome_script = (data_sumo_site_id) -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Note: upper bound is 12:01:59 (you could use second precision to get around this, e.g. "12:01:00") | |
time = Time.mktime(2014, 10, 14, 12, 1) | |
allowed_ranges = [ | |
"11:59".."12:01", | |
] | |
formatted_time = time.strftime("%H:%M") | |
p allowed_ranges.any? { |range| range.cover?(formatted_time) } |
Your application is growing, and you are starting to have a complex mailing system: notification emails, retention emails, misc user emails, admin emails, etc...
It's time to clean up your mailers !
You may already have a single mailer, responsible of every emails, like this one:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/compression.rb | |
Rails.application.configure do | |
# Use environment names or environment variables: | |
# break unless Rails.env.production? | |
break unless ENV['ENABLE_COMPRESSION'] == '1' | |
# Strip all comments from JavaScript files, even copyright notices. | |
# By doing so, you are legally required to acknowledge | |
# the use of the software somewhere in your Web site or app: |