Skip to content

Instantly share code, notes, and snippets.

View schneems's full-sized avatar

Richard Schneeman schneems

View GitHub Profile
class Levenshtein
def initialize(str)
@str = str.downcase
end
def distance(str2)
distances = (0..str2.length.next).to_a
@str.each_char.with_index do |char, i|
distances[0] = i + 1
sub_cost = i

Proposal: Annotated Config

Problem Statement

Rails promotes "convention over configuration". The convention provides a good baseline to start, but almost all apps must deviate in some large or small fashion, especially when it comes to config/environments/*.rb. This is even true between different environments. By default development and production have different configuration.

Many developers become accustomed to "what works" in one environment and do not try their code in a production environment until they actually deploy to production. This leads to a very confusing series of debugging steps, starting with "I don't understand...it works locally", and ending in "what is different". This is a problem, it leaves developers with a broken production application, a demoralizing, and unclear problem to solve as well as no easy way to actually see "what is different".

To make matters worse, different configuration can do different things between Rails versions see (https://github.com/rails/rails/comm

require 'pathname'
require 'bigdecimal'
KB_TO_BYTE = 1024 # 2**10 = 1024
MB_TO_BYTE = 1_048_576 # 1024**2 = 1_048_576
GB_TO_BYTE = 1_073_741_824 # 1024**3 = 1_073_741_824
CONVERSION = { "kb" => KB_TO_BYTE, "mb" => MB_TO_BYTE, "gb" => GB_TO_BYTE }
ROUND_UP = BigDecimal.new("0.5")
def linux_memory(file)

Your Rails Config

config.i18n.railties_load_path

no docs for i18n.railties_load_path found in rails guides

["/Users/schneems/.gem/ruby/2.1.2/gems/will_paginate-3.0.4/lib/will_paginate/locale/en.yml", "/Users/schneems/.gem/ruby/2.1.2/gems/devise-3.2.4/config/locales/en.yml", "/Users/schneems/Documents/projects/codetriage/config/locales/devise.en.yml", "/Users/schneems/Documents/projects/codetriage/config/locales/en.yml"]

Me

The electricity at my house went out last week while I was out of town. After it's back up and wifi is reconnected, my dropcam failed to recognize the network and reconnect itself. As a result, it was offline for the rest of the time when I was out of town. Coincidentally a couple other houses on my street reported break-in's and I had no way of knowing if my house was okay. I feel like Dropcam should be able to handle situations like this and reconnect itself and network is detected again?

Support

Hi there,

Dropcam is designed to search for and connect to it's associated network any time the power or internet goes out. Any time that the camera is not connected to it's network it will be actively searching for that network.

Routing behavior regarding backlog.

Puma and unicorn both have a "backlog". This is really a fancy way of saying that the socket they're listening at can queue messages faster than they're processing them. Backlog is a good thing, otherwise without it we could not "burst" i.e. a request could only be handled if there was capacity in the existing web server to process it at the moment.

We want to avoid the "rap genius" queuing scenario of load. This is where we have a really fast request queued behind a really slow one. The best way to avoid this is to have a concurrent server (unicorn/puma). In the most famous case, a single threaded non concurrent webs erver was used. When a concurrent server is used...now if you have 4 workers that can process requests you would need to have 4 slow requests in a row before the one fast one to have the same effect. As routing is randomized the probability of this approaches 0 with the more concurrency you have on each dyno.

Coming back to backlog, it matters the load on

My Abstracts

Here's a raw bit of my abstracts that I've submitted in the past:

Refactor your Foundation

Home builders have been called "developers" long before programmers were. In this talk you’ll be lead through a journey of what it takes to turn a 1905 house into a home. We will explore the parallels between remodeling and refactoring. You will be lead through a dive deep into how to architect for change in your app and your abode. A smart carpenter sharpens their tools before use: you’ll walk away with a freshly honed sense for software craftsmanship for your projects.

ActionDispatch::Static

Speed

By removing ActionDispatch on a barebones app we were able to achieve between ~1% and ~9% more iterations per second on every non-asset request.

Speed testing technique.

Generated two example apps with a simple erb endpoint that renders a hello world page. The point is to benchmark rails internals and not work done in the user space.

ActionDispatch::Static Purposes

What does ActionDispatch::Static do? It currently serves assets from the /public directory. It can serve asset pipeline assets as well as "unmanaged" assets you place in this directory.

  • Serving asset pipeline assets (managed under public/assets)
  • Serving non-asset pipeline assets (unmanaged, anywhere else)

It is possible for it to serve user uploaded assets (user uploads smile.png and it goes into /public and is served by Static), but this is not best practice in production, and the only time you would enable this is in production. Doing this makes it impossible to scale up to more than one server, therefore this is not a supported use of this middleware.

It can also be used to serve static html pages i.e. /public/index.html. While this is still technically under the "serving non-asset pipeline assets" it is a special enough case.

/*
I wanted an easy way to compare semver based strings without any fancy
c-extensions in postgres:
```
=> select '1.0.1'::semverish >= '1.0.0';
?column?