Skip to content

Instantly share code, notes, and snippets.

@bricker
bricker / amznymous.md
Last active April 23, 2024 11:14
An Amazon Programmer's Perspective (http://pastebin.com/BjD84BQ3)

Originally posted at http://pastebin.com/BjD84BQ3

Trigger warning: mention of suicidal ideation

tl;dr: I burned out as a developer at Amazon at the end of my second year. I’ve since found a healthy and sustainable work-life balance and enjoy work again. I write this to A) raise awareness, especially for new-hires and their families, and B) help give hope and advice to people going through the same at Amazon or other companies.

Hello, world

There’s been no shortage of anecdotes, opinions, and rebuttals regarding Amazon’s corporate culture as of late. I write this not to capitalize on the latest news-feed fad, but to share what I had already written and promptly deleted. I didn’t think anyone would want to hear my story, but it’s apparent people are going through a similar experience and don’t have a voice.

I’m a Software Development Engineer II at Amazon; SDE II basically means a software developer with at least 2–3 years of industry experience. I started at Amazon as an SDE I.

javascript:(function()%7B%24(%22.file%20.meta%22).each(function()%7Bvar%20btn%3D%24(%22%3Cbutton%20/%3E%22,%7Bclass:%22fileHider%22,text:%22HIDE%22%7D)%3B%24(this).append(btn)%3B%7D)%3B%24(%22.fileHider%22).on(%22click%22,function()%7Bvar%20data%3D%24(this).parents(%22.file%22).find(%22.data,%20.image%22)%3Bdata.toggle()%3B%7D)%3B%7D)()%3B

KPCC Ruby Style Guide

We base our Ruby style off of https://github.com/bbatsov/ruby-style-guide . There are a few other things, which are documented here.

Methods

  • Prefer a short-circuit return to a deeply-nested if condition:
# good
PREFIX = "Article:"
@bricker
bricker / unique_by_date_validator.rb
Created August 26, 2013 18:49
Unique By Date Validator
##
# Unique By Date validator
# Makes sure an attribute is unique by a specified day, month, year, etc.
# This validator is heavily based on ActiveRecord::Validations::UniquenessValidator
#
# It uses the `beginning_of_*` and `end_of_*` methods to
# specify the range of dates for which the attribute must be unique
# ActiveSupport::CoreExtensions::Date::Calculations
# http://apidock.com/rails/ActiveSupport/CoreExtensions/Date/Calculations
#
@bricker
bricker / promises.md
Last active March 14, 2018 00:33
Promises in Rails callbacks, using after_save and after_commit together.

"Russian-Doll Caching" is great. It embraces the Rails (and Ruby) goal to "make the developer happy". And it does. Not having to worry about cache expiration is superb.

It has its limits, though. If you're trying to avoid any database queries, russian-doll caching will not work for you. If you are trying to represent thousands, or even hundreds, of objects under a single cache fragment, russian-doll caching is not the best option.

We use it whenever it makes sense, but sometimes we just have to bite the bullet and expire a cache fragment manually. When you want to start manually expiring cache on a fairly busy website, you have to start considering race conditions. I recently ran into the following scenario:

class Post < ActiveRecord::Base
  after_save :expire_cache
  
# A simple, stupid script that counts how many times a letter occurs
# in the english translation of each number from 0 to MAX_NUM.
# Doesn't include the joining word "and" in numbers like "one hundred and two"
#
# NOTE: You need to install two gems to run this script:
# * loggability (linguistics depends on it but doesn't install it as a dependency for some reason)
# * linguistics
require 'linguistics'
Linguistics.use(:en)
@bricker
bricker / django_auth_in_rails.rb
Created December 11, 2012 21:19
Django Admin's Auth system, represented with Rails ActiveRecord models.
# Django Admin's auth system, represented using ActiveRecord
module Django
#--------------------------
# User
class User < ActiveRecord::Base
self.table_name = "auth_user"
has_many :django_user_permissions, class_name: "Django::UserPermission"
has_many :django_user_groups, class_name: "Django::UserGroup"

I programmed thirds, with the help of SuperCollider. This is the dumbest thing I've ever wasted 20 minutes on.

(
SynthDef.new("thirds", { |base=440|
	var outArray, third;
	third = base * 1.3;

	outArray = [
 SinOsc.ar(base, 0, 0.2),

The RSS Parser in Ruby's standard library is too strict, and is therefore, I believe, unfit for production. Feedzirra is tolerant of invalid XML, and I recommend it over the RSS module in Ruby.

However, if you know the RSS you're dealing with valid XML 100% of the time, and that you won't get 404 errors or anything else unexpected, then you might like to use it. Here's a little monkey patch to make it slightly safer:

module RSS
  class Parser
    def self.safe_parse(url, &block)
      begin
        open(url) do |xml|
@bricker
bricker / applicaton_helper.rb
Created September 24, 2012 07:31
tracking_link_to
# Wrapper around link_to to help with event tracking links.
# Adds the `track-event` class (even if another class is present)
# and adds the tracking data to the data attributes hash.
#
# Usage:
#
# tracking_link_to "Events", event_path, category: "Events", action: "Visit Events", label: "Events"
#
# If you need to pass html_options, be sure to let it know where one hash ends and the other begins:
#