Skip to content

Instantly share code, notes, and snippets.

blaix / selfie.rb
Last active Dec 10, 2021
How to understand `extend self` and `class << self` in ruby.
View selfie.rb
# Everything in ruby is an object which is an instance of a class. Even classes
# themselves are objects that are instances of the class `Class`.
class Dog
puts Dog.class # => Class
# When you use the class keyword, you are opening a class to define instance
# methods for any instance of the class:
View modular-inheritence.rb
module Stomach
def eat(food)
@contents ||= []
@contents << food
def vomit

My experience is mostly with server-side web frameworks, so that's how I'll describe it:

  1. I start in an "outer" TDD loop:
  2. Write a functional test that hits the URL of the feature I'm testing This fails for a silly reason: no route, no template, etc. (scaffolding)
  3. I add only the piece of scaffolding that's causing the failure I'm seeing. At this point I'm just dealing with "glue" that the framework provides me.
  4. Repeat steps 3 until I hit some logic that isn't solved with simply writing together things the framework gives me.
  5. I call a function (or whatever) that doesn't exist yet but named for the logic I'm introducing. My integration test is now failing because it doesn't exist.
blaix / whatversionoftmuxamirunning.txt
Created Aug 18, 2017
I just wanted to know what version of tmux I'm running...
View whatversionoftmuxamirunning.txt
$ tmux --version
tmux: illegal option -- -
usage: tmux [-2CluvV] [-c shell-command] [-f file] [-L socket-name]
[-S socket-path] [command [flags]]
$ tmux --help
tmux: illegal option -- -
usage: tmux [-2CluvV] [-c shell-command] [-f file] [-L socket-name]
[-S socket-path] [command [flags]]
blaix /
Last active Aug 12, 2017


An RPG for our entire family.


  • Use weapons like swords and bows (C), but without hurting or killing (N)
  • Gameplay that works for both young (3) and old (10+) kids
  • Just enough structure to avoid chaos while still focusing on having fun
blaix /
Created May 2, 2017
turning a function into a method
class User:
def __init__(self, coolness_factor)
self.coolness_factor = coolness_factor
cool_user = User(coolness_factor=100)
uncool_user = User(coolness_factor=1)
def user_is_cool(user):
return user.coolness_factor > 50
class MyClass:
def __init__(one, two, three): = one
self.two = two
self.three = three
def my_factory_method(one, two, three=None):
if three is None:
return MyClassWithoutThree(one, two)
class BaseModel:
fields = ()
def __init__(self, **data):
for key, val in data.items():
setattr(self, key, val)
class MyModel(BaseModel):
fields = ('field1', 'field2', 'field3')
# in importer/
import logging as log
log.basicConfig(filename='importer.log', level=log.WARNING, format='%(message)s')
# everywhere else:
from importer.logging import log
log.warning('used warning so i could look at the log without clutter from other projects')
def validate_token(secret, auth_token):
# do the token check logic... (using settings.PARTNER_ID)
def validate_token_from_yola(auth_token):
yola = Yola()
partner = yola.get_partner(settings.PARTNER_ID)
validate_token(partner['shared_secret_key'], auth_token)