Skip to content

Instantly share code, notes, and snippets.

@gonzedge
gonzedge / scanning.rb
Created February 1, 2017 02:04
Scan test
#!/usr/bin/env ruby
require 'rambling-trie'
trie = Rambling::Trie.create '/usr/share/dict/web2'
puts trie.scan 'beaut' # =>
# beauteous
# beauteously
# beauteousness
# beauti
@gonzedge
gonzedge / match_prefix_benchmark.rb
Last active January 23, 2017 02:05
Benchmark comparing fast_trie, triez and rambling-trie for a match prefix example
#!/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'
@gonzedge
gonzedge / run.sh
Last active January 7, 2017 17:39
Find all substrings that are words with a(n uncompressed) trie
#!/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
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
@gonzedge
gonzedge / README.md
Last active September 30, 2015 14:29
Put your git author in your git-svn commit messages (works great with `git pair`!)

This script will set up a hook to insert your git author information into the body of Subversion commit messages.

To set it up, cd into your favorite git-svn repository and run the following command:

bash < <( curl -s -L https://gist.githubusercontent.com/gonzedge/8447840ed0e5710eb228/raw/set-up-git-svn-hooks.sh )

Enjoy!

@gonzedge
gonzedge / each.rb
Created July 28, 2012 19:44
Version 0.4.2 of the Rambling Trie has been released!
trie.each do |word|
puts "#{word} is included!"
end
@gonzedge
gonzedge / application_helper.rb
Created July 28, 2012 19:13
Pygmentizing your Rails app hosted on Heroku
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
@gonzedge
gonzedge / add.rb
Created July 21, 2012 14:41
Rambling Trie 0.4.1 is out!
trie << 'word' # equivalent to trie.add_branch_from('word')
@gonzedge
gonzedge / application_controller.rb
Created April 27, 2012 14:39
Rails - Custom 404 and 500 pages and the exception_notification gem
class ApplicationController < ActionController::Base
# ...
private
# ...
def notify(exception)
ExceptionNotifier::Notifier.exception_notification(request.env, exception,
data: {message: 'an error happened'}).deliver
@gonzedge
gonzedge / Gemfile
Created April 27, 2012 07:19
Introducing rambling-slider-rails: Easily include the jQuery Rambling Slider on your rails app
gem 'rambling-slider-rails'