Skip to content

Instantly share code, notes, and snippets.

// Handles JavaScript history management and callbacks. To use, register a
// regexp that matches the history hash with its corresponding callback.
window.HashHistory = {
// The interval at which the window location is polled.
URL_CHECK_INTERVAL : 500,
// We need to use an iFrame to save history if we're in an old version of IE.
USE_IFRAME : jQuery.browser.msie && jQuery.browser.version < 8,
@ryandotsmith
ryandotsmith / memstat.rb
Created July 29, 2011 05:04
I am using this to profile my workers (queue_classic)
module Memstat
extend self
def puts
"memory=#{real_mem_size} ruby_objects=#{num_objects}"
end
def real_mem_size
mb = `ps -o rsz #{$$}`.split("\n")[1].to_f / 1024.0
mb = mb.round(-2) # nearest 100 (i.e. 60.round(-2) == 100)
@ryandotsmith
ryandotsmith / instruments.rb
Created April 6, 2012 07:09
Sequel & Sinatra Instrumentation
module Instruments
def self.set_logger(l, m)
@logger = l
@method = m
end
def self.logger
@logger
end
@bgentry
bgentry / rated.go
Created October 11, 2012 23:48
Go token bucket rate limiter #golang
package main
import (
"fmt"
"time"
)
func main() {
ticker := rateLimit(4, 10)

Make it real

Ideas are cheap. Make a prototype, sketch a CLI session, draw a wireframe. Discuss around concrete examples, not hand-waving abstractions. Don't say you did something, provide a URL that proves it.

Ship it

Nothing is real until it's being used by a real user. This doesn't mean you make a prototype in the morning and blog about it in the evening. It means you find one person you believe your product will help and try to get them to use it.

Do it with style

@icub3d
icub3d / main.go
Created July 29, 2013 23:46
First stab at groupcache.
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"github.com/golang/groupcache"
"io"
"net"
@JoshCheek
JoshCheek / what-is-an-object.txt
Last active January 1, 2016 02:18
Feynman talking about definitions of objects
Any simple idea is approximate; as an illustration, consider an object,
… what is an object? Philosophers are always saying, “Well, just take a chair for example.”
The moment they say that, you know that they do not know what they are talking about any more.
What is a chair? Well, a chair is a certain thing over there … certain?, how certain?
The atoms are evaporating from it from time to time—not many atoms,
but a few—dirt falls on it and gets dissolved in the paint;
so to define a chair precisely, to say exactly which atoms are chair,
and which atoms are air, or which atoms are dirt,
or which atoms are paint that belongs to the chair is impossible.
So the mass of a chair can be defined only approximately.
@roidrage
roidrage / meatballs.md
Last active December 5, 2019 22:44
Americanized version of my meatballs recipe

The @roidrage meatballs extravaganza.

The secret ingredient to this recipe is letting everything stew for a few hours. First the tomato sauce, requires at least 90 minutes to 2 hours. Then the meatballs in the sauce another 90 minutes. The longer the better.

Once the meatballs are in the sauce, the more time you give them, the more delicious flavor will seep from the meat into the sauce, and vice versa. I'd recommend giving it a total of four hours for maximum taste extraction.

The long stew ensure that the fluids have evaporated and that you're left with the tastiest meatballs you've ever had.

Ingredients (serves four hungry people):

@gavinandresen
gavinandresen / BlockPropagation.md
Last active March 14, 2023 09:45
O(1) block propagation

O(1) Block Propagation

The problem

Bitcoin miners want their newly-found blocks to propagate across the network as quickly as possible, because every millisecond of delay increases the chances that another block, found at about the same time, wins the "block race."

@brandur
brandur / request-trees.md
Last active August 29, 2015 14:05
Request Trees

But why gen a new id if someone passes you an id? Just use the supplied id in the called srvc.

This is certainly disputable territory, but the main motivation is that depending on service architecture, a single incoming request can balloon out into a full tree of backend requests because requests can map 1:N between any two components. Assigning every request in every component a unique ID allows any particular request to be isolated, while still allowing the any subsection of the tree to be viewed all at once.

Visually, this might look something like this:

      Component 1            Component 2            Component 3
+----------------------+----------------------+----------------------+