Skip to content

Instantly share code, notes, and snippets.

@jcoglan
jcoglan / Gemfile.lock
Created May 2, 2014 14:51
Parade-triggered Ruby encoding error
GEM
remote: https://rubygems.org/
specs:
addressable (2.3.6)
blankslate (2.1.2.4)
css_parser (1.3.5)
addressable
gli (1.6.0)
json (1.8.1)
mini_portile (0.5.3)
@jcoglan
jcoglan / Makefile
Last active August 29, 2015 14:01
# Context:
#
# browserify is an executable found in the node_modules/.bin directory.
PATH := node_modules/.bin:$(PATH)
SHELL := /bin/bash
source_js := app_root.js
build.js: $(shell PATH=$(PATH) browserify --list $(source_js)) # How come this needs explicit PATH
// I need a better name for the thing below called StreamReader. It essentially
// lets you split a stream into a sequence of smaller streams of fixed size,
// simplifying parsing TCP input for certain protocols.
//
// What it does:
//
// * It's a writable stream that buffers everything written to it
//
// * It has a fork() method, that takes a number n and returns a stream that
// will yield up to n bytes before emitting 'end', with no guarantees about
$ brew install mysql
Error: You must `brew link pkg-config' before mysql can be installed
$ brew link pkg-config
Linking /usr/local/Cellar/pkg-config/0.28...
Error: Could not symlink share/doc/pkg-config
/usr/local/share/doc is not writable.
$ sudo !!
sudo brew link pkg-config

An ActiveRecord conundrum

I'm going to describe a weird problem I faced when using ActiveRecord today. To protect the innocent, I'm not going to talk about the app I'm actually working on but will instead discuss a hypothetical but isomorphic database design for a clone of the popular blogging platform Tumblr.

Tumblr lets you publish various different sorts of content. We might be tempted to shove all these types in a big STI table, but the types are all quite different from one another and so we give them their own tables.

If you have these classes:

class Foo < ActiveRecord::Base
  has_many :things, as: :content
end

class Bar < Foo
end
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Socket.io</title>
<script src="http://localhost:9000/socket.io/socket.io.js"></script>
</head>
<body>
<h1>Socket.io</h1>

Turing complete type systems

I'm trying to understand the computational power of different compiler components.

For example, JavaScript programs are Turing-complete, but recognising valid JS syntax only requires a CFG, not a Turing machine. The syntax is decidable, the semantics is not.

When people say 'Turing-complete type system', do they mean that user programs can use types to implement a Turing machine, or do they mean that the type checker is a Turing machine, or both?

If the latter, what is the purpose of such a type system? What is the value in having the system that checks the consistency/safety of programs itself be capable of running arbitrary programs?

# This spec works on RSpec 2.99 but not on 3.0.
class Model
attr_reader :attributes
def initialize(attributes)
@attributes = attributes
end
def ==(other)
require 'nokogiri'
class Html2Md
class Link < Struct.new(:href, :title)
end
class Format < Struct.new(:name, :head, :body, :opened)
end
WIDTH = 80