Skip to content

Instantly share code, notes, and snippets.

View avdi's full-sized avatar

Avdi Grimm avdi

View GitHub Profile
@avdi
avdi / gist:5750935
Created June 10, 2013 18:09
Why can't I load org-mode 8.0.3?
Output from M-x org-version:
Org-mode version 7.9.3f (release_7.9.3f-17-g7524ef @ /home/avdi/.emacs24.d/elisp/external/org-8.0.3/lisp/)
@avdi
avdi / maybenull.rb
Created May 24, 2013 19:56
Pondering Null Objects and Optional Types in Ruby
# I've been thinking about Null Objects and Optional Types in Ruby lately.
# Optional Types are often defined using both a Null type and some kind of
# Proxy for non-nulls, but proxies have all sorts of subtle problems in Ruby.
# Let's say we do optional types without a proxy. E.g.:
x = Maybe("foo") # => "foo"
y = Maybe(nil) # => NullObject.instance
# In order to keep NullObjects from "leaking" into places they aren't wanted,
# we need an inverse conversion function to "collapse" values back to either
@avdi
avdi / gist:5265908
Last active December 15, 2015 13:18
The great slide deck scavenger hunt!

Welcome to the great slide deck scavenger hunt!

I'm terrible at coming up with illustrations for slides, and I'm running out of time getting my slides together for my next talk. Alternatively, I am very lazy; that explanation works too. Anyway, I'm crowd-sourcing.

Below is a list of themes I need illustrations for. If you see one you know the perfect funny/poignant/memorable image for, please post it in the comments! Attribution hints are helpful too.

If I use your suggestion, I'll give you $5 your next purchase at my store (excluding RubyTapas; I don't have the ability to generate coupons for that yet).

I'll be adding more entries over the next day or so, so check back if you just can't get enough. I'll also cross off ones that I've picked an image for.

@avdi
avdi / Ruby.markdown
Created February 18, 2013 20:09 — forked from jcoglan/Ruby.markdown

Core ideas

  • An Object is a set of instance variables and a pointer to a 'singleton class'.
  • Properties are looked up in the instance variables, methods are dispatched via the singleton class.
  • Module is a subtype of Object. A Module is a set of methods and an ordered list of zero-or-more 'parent' modules.
  • Module A becomes a parent of module B via B.include(A).
  • Method lookup works by doing a depth-first right-to-left search of a module tree.
  • Class is a subtype of Module. A Class is a Module that can be instantiated.
  • A Class has only one 'superclass'. A class includes its superclass as its first parent module for the purposes of method dispatch. A class's singleton class includes the superclass's singleton class as its first parent.
  • The default superclass of all classes is Object.
# If you don't want to force the composed methods to raise exceptions,
# have them take a block specifying the failure action
def composed_method
frobulate_widgets { return false }
refrobulate_widgets { return false }
confribulate_frobulations { return false }
true
end
@avdi
avdi / selective_method_import.rb
Created January 16, 2013 06:35
Playing around with selective method import in Ruby
# Generate a module which imports a given subset of module methods
# into the including module or class.
def Methods(source_module, *method_names)
all_methods = source_module.instance_methods +
source_module.private_instance_methods
unwanted_methods = all_methods - method_names
import_module = source_module.clone
import_module.module_eval do
define_singleton_method(:to_s) do
"ImportedMethods(#{source_module}: #{method_names.join(', ')})"
@avdi
avdi / org-html-bug.html
Last active December 10, 2015 12:18
Garbage characters in org-mode HTML export
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>def hello</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<meta name="title" content="def hello"/>
<meta name="generator" content="Org-mode"/>
<meta name="generated" content="2013-01-02T01:47-0500"/>
@avdi
avdi / task.cs
Created December 17, 2012 23:35 — forked from kberridge/task.cs
public class Task : ActiveRecord
{
public string Name { get; set; }
public int AssignedTo_UserId { get; set; }
public DateTime DueOn { get; set; }
public Task()
{
DueOn = DateTime.Now.AddDays(1);
}
@avdi
avdi / gist:3842243
Created October 5, 2012 20:38
Observer pattern terminology

When it comes to the Observer pattern, there are a number of related, overlapping terms used by different codebases. Off the top of my head:

  • Observer/Observable/Subject
  • Listener/Listenable
  • Event/Event source/Event sink/Event handler
  • Hook/Callback
  • Subscriber/Subscribable
  • "Firing" vs. "Triggering" vs "Notifying" vs "Executing"

Which of these do consider to be synonymous?

@avdi
avdi / life.rb
Created September 30, 2012 00:48
Game of Life, mildly functional version
#!/usr/bin/env ruby
# The game board, at one point in time
class BoardGeneration
# How an instance will build a copy with a new grid
def self.from_grid(grid)
allocate.tap do |bg|
bg.grid = grid
end