Skip to content

Instantly share code, notes, and snippets.

@rmascarenhas
rmascarenhas / undo.sh
Created Nov 16, 2012
Undoing your last command
View undo.sh
# undo: reverts the last command, as long as there is a registered handler
# for it.
#
# Usage:
#
# $ undo
#
# There are no options.
#
# There are by default registered handlers for the following commands:
View email_renderer.rb
require 'config/environment'
class EmailRenderer
class_inheritable_accessor :view_paths
self.view_paths = ["."]
def template
@template ||= initialize_template
end
@rmascarenhas
rmascarenhas / ds.rb
Created Sep 19, 2012
delivery strategy
View ds.rb
class TagSubscription < ActiveRecord::Base
belongs_to :delivery_strategy
end
class DeliveryStrategy < ActiveRecord::Base
# Attributes:
# type: can be 'real_time', 'daily' or 'weekly'
# day: contain the day of the week
# time: the time of the day (morning, afternoon, night)
#
has_many :tag_subscriptions
@rmascarenhas
rmascarenhas / wf.sh
Created Sep 16, 2012
Word-frequency calculator. Can be used standalone or in pipelines.
View wf.sh
#!/usr/bin/env bash
# Word-frequency.
# Usage:
#
# $ wf [-ni] file.txt [file1.txt file2.txt ...]
#
# You can choose to display just the first [n] most frequent words.
#
# $ wf -n2 file.txt
@rmascarenhas
rmascarenhas / repeat.sh
Created Sep 2, 2012
repeat a command in bash
View repeat.sh
#!/usr/bin/env bash
# repeat.sh
#
# Usage:
# repeat <command>
# will repeat <command> forever.
#
# repeat -nN <command>
# will repeat <command> N times.