Skip to content

Instantly share code, notes, and snippets.

@jamesarosen
jamesarosen / comments.hdbs
Created July 24, 2013 04:47
A Handlebars template that is causing some problems.
<div class="body">
{{#if comment }}
<div class="comment">
{{{ comment.value }}}
</div>
{{#if comment.canMakePrivate}}
<div class="link_light make-private">
<em data-action="make-private" data-audit-id="{{../id}}">{{comment.makePrivateActionLabel}}</em>
</div>
{{/if}}
@jamesarosen
jamesarosen / notes.md
Last active December 19, 2015 18:08
Some questions and notes about Elixir

Elixir Notes

Defining Records with Shared Values

In JavaScript, this is a big no-no:

function Set() {
}
Set.prototype.content = [];
@jamesarosen
jamesarosen / if_less_development.md
Last active July 19, 2020 19:53
On Procedural Polymorphism: I like the idea of replacing ifs with Polymorphism, but I'm not quite comfortable with it yet.

Background

Cory Foy recently wrote an article entitled, Procedural Polymorphism: Is your code really telling you to use an if statement?. Corey Haines has been talking about this same topic for a while. Sandi Metz covers the topic in Practical Object-Oriented Design in Ruby. Ben Rady and Rod Coffin discussed using the Null-Object pattern instead of an if statement in Continuous Testing with Ruby, Rails, and JavaScript.

Printing in Conway's Game of Life

That is, very smart people whom I admire agree that, in general,

class DeadCell
@jamesarosen
jamesarosen / spy_fail.md
Last active December 16, 2015 15:39
How do I test interactions with immutable objects?

I have an object that acts as a "directory" or a "library" of data -- for example, a list of the time zones on the machine. Because there is only one such list, and because the list is static, this object is a good candidate for a global, immutable object. For example, in Ruby:

class TimeWithOffset

  ALL_TIME_ZONES = {
    "Midway Island": -660,
    # ...
    "Brasilia": -180,
 # ...
@jamesarosen
jamesarosen / optional_dependencies.md
Last active December 11, 2015 08:09
Some questions about optional dependencies in Ruby gems.

Some questions about optional dependencies

1. A small ruby library

I'm writing a small Ruby library:

class FizzBuzzEndpoint

  def call(env)
@jamesarosen
jamesarosen / git_extraction.md
Created October 24, 2012 16:13
Extracting a directory from a git project

Recently, I needed to extract a number of directories from a git project each into their own projects. The original directory structure looked like

project/
  subprojects/
    Foo/
    Bar/
    Baz
@jamesarosen
jamesarosen / iteration.js
Created August 28, 2012 22:43
JavaScript fundamentals
// Array Iteration:
myArray = [ 'foo' ];
myArray.forEach(function(x) { console.log(x); });
// prints "foo"
// Object Keys:
myObject = { foo: 'bar', baz: 'quux' };
Object.keys(myObject); // [ "foo", "baz" ]
// Object Iteration Helper (context is optional)
@jamesarosen
jamesarosen / 01-office-dig.txt
Created August 24, 2012 19:25
int.tangocard.com DNS problems
# from our office
$ dig int.tangocard.com
; <<>> DiG 9.7.3-P3 <<>> int.tangocard.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14686
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 13, ADDITIONAL: 7
;; QUESTION SECTION:
@jamesarosen
jamesarosen / 01_rack_endpoint.rb
Created August 21, 2012 16:38
An experiment in modeling a process with ActiveModel
# Our starting point:
# a Rack endpoint that performs HTTP Basic auth.
class SignInEndpoint
def call(env)
email, password = *credentials(env)
user = User.authenticate(email, password)
if user.nil? || user.deleted?
respond_with_error 'Invalid credentials'
@jamesarosen
jamesarosen / file_widths.rake
Created August 8, 2012 22:54
Rake task to ensure that files have no more than 80 characters in a line
# Usage
# rake check_file_widths
# rake check_file_widths[120]
# rake check_file_widths[80, "app/**/*.rb"]
#
# Arguments:
# * width - the max width; defaults to 80
# * paths - the list of files to check; defaults to
# {app,lib}/**/*.{js,rb,scss,coffee,erb}
desc "Ensure there are no overly long lines"