Rough notes to start using WeeChat on Fedora 17/18:
Install and Start
# yum install weechat # weechat-curses
| module Mixin | |
| Code = proc do | |
| a_class_level_method(self.name) | |
| end | |
| def Mixin.included(other) | |
| super | |
| ensure | |
| other.module_eval(&Code) |
List moved
Please use https://github.com/bf4/learning to fork and pull changes.
| #!/usr/bin/env sh | |
| if ! which md5sum > /dev/null; then | |
| echo Install md5sum | |
| exit 1 | |
| fi | |
| if ! which curl > /dev/null; then | |
| echo Install curl | |
| exit 1 |
| #!/usr/bin/env sh | |
| if ! which md5sum > /dev/null; then | |
| echo Install md5sum | |
| exit 1 | |
| fi | |
| if ! which curl > /dev/null; then | |
| echo Install curl | |
| exit 1 |
| module Cached | |
| def cache(*method_names) | |
| method_names.each do |m| | |
| original = instance_method(m) | |
| results = {} | |
| define_method(m) do |*a| | |
| results[[m, a]] ||= original.bind(self).call(*a) | |
| end | |
| end |
When access to an object's internals is truly necessary, it isn't practical to use composition based techniques. For example, consider the following mixin-based code which implements a memoization routine for caching method return values:
module Cached
def cache(*method_names)
method_names.each do |m|
original = instance_method(m)| class Aggregator | |
| def initialize(target_filename, output_filename, pattern, output_file_type=nil) | |
| @target_filename = target_filename | |
| @output_filename = output_filename | |
| @pattern = pattern | |
| @output_file_type = output_file_type || "csv" | |
| end | |
| def run | |
| open_files |
| require "tempfile" | |
| require "fileutils" | |
| require "csv" | |
| require "time" | |
| # -*- coding: utf-8 -*- | |
| rents = "/Users/seanjw/Library/Thunderbird/Profiles/gdg1f8hw.default/ImapMail/imap.googlemail.com/Parents" | |
| output = "/Users/seanjw/Dropbox/Programming-Languages/Ruby/rents-email-dates.txt" | |
| odd_output = "/Users/seanjw/Dropbox/Programming-Languages/Ruby/odd-rents-dates.txt" |
| class Ability | |
| include CanCan::Ability | |
| def initialize(user) | |
| user ||= User.new # guest user (not logged in) | |
| if user.has_role? :admin # rolify | |
| can :manage, :all | |
| can :access, :ckeditor | |
| # Performed checks for actions: | |
| can [:read, :create, :destroy], Ckeditor::Picture |