Skip to content

Instantly share code, notes, and snippets.

View notahat's full-sized avatar

Pete Yandell notahat

View GitHub Profile
# On a new ubuntu 14.04 box, as root, with the following variables
# export BUILDBOX_AGENT_NAME="buildbox-agent-N"
# export BUILDBOX_AGENT_ACCESS_TOKEN="<your token here>"
# export BUILDBOX_AGENT_SSH_PRIVATE_KEY="<an ssh private key>"
# export BUILDBOX_AGENT_SSH_PUBLIC_KEY="<an ssh public key>"
# Make tmp totally in memory
echo "none /tmp tmpfs size=4g 0 0" >> /etc/fstab
mount /tmp
@notahat
notahat / gist:c84e1784893d31f4e594
Created December 15, 2014 06:01
Private classes in Ruby
module Container
class PublicThing
def hello
PrivateThing.new.hello
end
end
class PrivateThing
def hello
"Hello, world!"

Keybase proof

I hereby claim:

  • I am notahat on github.
  • I am notahat (https://keybase.io/notahat) on keybase.
  • I have a public key whose fingerprint is A466 A52F 204A DE5E 9F85 8F1B C009 0778 6D7E E91A

To claim this, I am signing this object:

@notahat
notahat / gist:c72cee07f9a74e61a2d0
Last active August 29, 2015 14:11
Private classes in Ruby, version 2
module PrivateClass
def self.included(mod)
*parent, child = mod.name.split("::")
Object.const_get(parent.join("::")).private_constant(child)
end
end
module Container
class PublicThing
def hello
$ ping 111.118.175.56
PING 111.118.175.56 (111.118.175.56): 56 data bytes
64 bytes from 111.118.175.56: icmp_seq=0 ttl=55 time=15.581 ms
64 bytes from 111.118.175.56: icmp_seq=1 ttl=55 time=17.552 ms
64 bytes from 111.118.175.56: icmp_seq=2 ttl=55 time=17.283 ms
^C
--- 111.118.175.56 ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 15.581/16.805/17.552/0.873 ms
% ruby --version
ruby 1.8.6 (2007-09-23 patchlevel 110) [i686-darwin9.0.0]
% sudo gem install rails --version 2.1.1
Password:
Successfully installed activesupport-2.1.1
Successfully installed activerecord-2.1.1
Successfully installed actionpack-2.1.1
Successfully installed actionmailer-2.1.1
Successfully installed activeresource-2.1.1
# This is a teaser for a plugin I'm working on to provide an alternative
# to ActiveRecord fixtures.
#
# It's similar to ThoughtBot's Factory Girl, but I think the syntax is
# a lot nicer.
#
# The models below are the canonical Rails blog examples, i.e. a Post
# has_may Comments.
#
# I'm using the very cool Faker gem to make up values for fields.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Table Test</title>
<style type="text/css" media="screen">
table { table-layout: fixed; width: 100%; border-collapse: collapse; border-spacing: 0; }
td { padding: 5px; border: 1px solid #888888; }
Why is http://gist.github.com/15704 invalid HTML?
The width of each column is specified as 50%. Section 10.2 of the CSS2 spec tells us:
The percentage is calculated with respect to the width of the generated box's containing block.
The containing block in this case is the table. So let's say the table is, for example, 500px wide.
That means each column is 250px wide, but...
Section 17.6.2 tells us that the row width is:
@notahat
notahat / gist:39132
Created December 22, 2008 21:33 — forked from xaviershay/gist:39075
value = "Don T Alias"
first_name, last_name = value.reverse.split(' ', 2).reverse.collect(&:reverse)
first_name = first_name.to_s
last_name = last_name.to_s
# Refactored to take into account Xavier's pathological aversion to case statements:
words = value.split(' ')
first_name, last_name = if words.size == 0
['', '']
elsif words.size == 1