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
class ApplicationController < ActionController::Base | |
# ... | |
unless Rails.application.config.consider_all_requests_local | |
rescue_from Exception, with: lambda { |exception| render_error 500, exception } | |
rescue_from ActionController::RoutingError, ActionController::UnknownController, ::AbstractController::ActionNotFound, ActiveRecord::RecordNotFound, with: lambda { |exception| render_error 404, exception } | |
end | |
private | |
def render_error(status, exception) |
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
#!/usr/bin/env ruby | |
require 'rambling-trie' | |
trie = Rambling::Trie.create '/usr/share/dict/web2' | |
puts trie.scan 'beaut' # => | |
# beauteous | |
# beauteously | |
# beauteousness | |
# beauti |
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
#!/usr/bin/env ruby | |
# From https://stackoverflow.com/questions/41521492/faster-way-to-see-if-a-huge-list-of-strings-is-contained-within-another-string/41523304#41523304 | |
# with slight changes | |
require 'triez' | |
require 'trie' | |
require 'rambling-trie' | |
require 'benchmark' |
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
#!/usr/bin/env bash | |
chmod +x ./substrings.rb | |
# with the words with friends dictionary found in | |
# https://github.com/gonzedge/rambling-trie/blob/master/assets/dictionaries/words_with_friends.txt | |
./substrings.rb 'ifdxawesome45someword3' # => | |
# aw | |
# awe | |
# awes |
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
def self.delegate delegated_methods_to_delegated_to | |
delegated_methods_to_delegated_to.each do |methods, delegated_to| | |
methods.each do |method| | |
define_method method do |*args| | |
send(delegated_to).send method, *args | |
end | |
end | |
end | |
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
trie.each do |word| | |
puts "#{word} is included!" | |
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
module ApplicationHelper | |
PYGMENTIZE_URL = URI.parse 'http://pygmentize.herokuapp.com/' | |
def highlight_code(code, language) | |
sha = Digest::SHA1.hexdigest code | |
Rails.cache.fetch ['code', language, sha].join('-') do | |
Net::HTTP.post_form(PYGMENTIZE_URL, lang: language, code: code).body.html_safe | |
end | |
end | |
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
trie << 'word' # equivalent to trie.add_branch_from('word') |
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
class ApplicationController < ActionController::Base | |
# ... | |
private | |
# ... | |
def notify(exception) | |
ExceptionNotifier::Notifier.exception_notification(request.env, exception, | |
data: {message: 'an error happened'}).deliver |
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
gem 'rambling-slider-rails' |
NewerOlder