Skip to content

Instantly share code, notes, and snippets.

View elskwid's full-sized avatar
🤡

Don Morrison elskwid

🤡
View GitHub Profile
@steveklabnik
steveklabnik / foo_test.rb
Created April 27, 2013 23:25
shared examples in MiniTest As usual, "Just Use Ruby"
require 'test_helper'
describe "foo" do
include SupportsCount
end
@bf4
bf4 / ability.rb
Last active October 14, 2017 15:15
Cancan, rolify, and active admin
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
@supernullset
supernullset / email-date-grouper.rb
Created April 1, 2013 05:48
mail-grouper one off script
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"
@supernullset
supernullset / aggregator.rb
Created April 1, 2013 05:47
First pass aggregator
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

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)
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
#!/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
@raggi
raggi / validate_local_cache.sh
Last active December 11, 2015 23:39
A script to validate your local gem cache against the public s3 repositories. If you find mismatches that contain both local and remote values, please post them in comments.
#!/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
@bf4
bf4 / ruby_learning.md
Last active July 17, 2021 08:06
Some Ruby Learning Resources
@amitsaha
amitsaha / weechat_fedora.rst
Last active October 5, 2021 21:25
WeeChat on Fedora 18

Rough notes to start using WeeChat on Fedora 17/18:

Quick Start

Install and Start

# yum install weechat
# weechat-curses