Skip to content

Instantly share code, notes, and snippets.

/* This is when a refactoring really pays off.
*
* In order to make your code more modular, avoid hard-coding assumptions (or refactor them away).
* The most fundamental, anti-modular assumption in Object-Oriented software is the concrete type of objects.
* Any time you write "new MyClass" in your code (or in Ruby MyClass.new) you've hardcoded
* an assumption about the concrete class of the object you're allocating. These makes it impossible, for example,
* for someone to later add logging around method invocations of that object, or timeouts, or whatever.
*
* In a very dynamic language like Ruby, open classes and method aliasing mitigate this problem, but
* they don't solve it. If you manipulate a class to add logging, all instances of that class will have
require 'rubygems'
require 'sinatra'
require 'redis'
# To use, simply start your Redis server and boot this
# example app with:
# ruby example_note_keeping_app.rb
#
# Point your browser to http://localhost:4567 and enjoy!
#
From bb2a78858cffa7c6937642986e9aca1a4f862c0d Mon Sep 17 00:00:00 2001
From: Ilya Grigorik <ilya@igvita.com>
Date: Thu, 10 Jun 2010 00:46:48 -0400
Subject: [PATCH] async rails3
---
Gemfile | 6 ++++++
app/controllers/widgets_controller.rb | 6 ++++++
app/models/widget.rb | 2 ++
config.ru | 1 +
# estimate the duration of an ALTER TABLE statement in mysql
# this code estimates the worst case, as most of the time, an ALTER will result in a table that is smaller than the original
percentage = 0
interval = 10
while(true) do
sleep(interval)
new_percentage = (File.size('#sql-5316_1a.ibd')*1.0 / File.size('moves.ibd')*1.0)
change = new_percentage - percentage
intervals = 1.0/change
var xyz = {};
xyz.receiverURL = '.res/save-proxy-image.php';
xyz.resizeImage = function(img, dstw, dsth, fit) {
try {
var w = dstw;
var h = dsth;
if (img.naturalWidth === 0 || img.naturalHeight === 0)
return null;
if (img.naturalWidth > dstw || img.naturalHeight > dsth) {
if (fit) {
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
@jperkins
jperkins / gist:564631
Created September 3, 2010 21:54 — forked from tmm1/gist:61762
> - In ruby 1.8.x, what is the functional difference between rb_thread_schedule and rb_thread_select?
rb_thread_schedule() is the guts of the thread scheduler, it traverses
over the linked list of threads (several times) to find the next one
to switch into. The function is long (250 lines) and messy, and covers
all the combinations of thread status (RUNNABLE, TO_KILL, STOPPED,
KILLED) and wait state (FD, SELECT, TIME, JOIN, PID).
If there are no threads doing i/o or waiting on a timeout,
rb_thread_schedule() picks another thread from the list (considering
/*
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
*
* Activate javascript console =)
*/
<script>
console.group("inception movie");
@jperkins
jperkins / GEM_NAME.gemspec
Created July 14, 2011 20:57 — forked from blowmage/GEM_NAME.gemspec
Simple Gem Template
require "rake"
Gem::Specification.new do |s|
s.name = "GEM_NAME"
s.version = "0.1.0"
s.summary = "GEM_SUMMARY (short)"
s.description = "GEM_DESCRIPTION (longer)"
s.homepage = "http://example.com/GEM_NAME"
s.authors = ["GEM_AUTHOR_NAME"]
s.email = "GEM_AUTHOR_EMAIL"
@jperkins
jperkins / gist:2932942
Created June 14, 2012 21:04 — forked from ccurtisj/gist:2932908
Format meeeeeee
<html>
<body style="width: 653px; font-family: Arial; font-size: 12px; background-color: #cccccc;" bgcolor="#cccccc">
<opentracking />
<table style="font-family: Arial; width: 653px; background-color: #ffffff; border: 1px solid #999;" bgcolor="#ffffff">
<tr>
<td style="width: 653px;">
<a href="http://www.dealradar.com/deals/chicago?src=email&utm_source=custom_digest&utm_medium=email&utm_term=header&utm_campaign=chicago" style="color: #027986; text-decoration: none;">
<img alt="" src="http://s3.amazonaws.com/dealradar_assets/email_assets/email_header.png" style="border: none;" border="0" />
</a>
<h1 style="margin-top: 15px; margin-left: 20px; margin-bottom: 0px; font-size: 15px; font-family: Arial; color: #027986;">Local Deals in Chicago - Thursday June 14, 2012</h1>