Skip to content

Instantly share code, notes, and snippets.

@gmarik
gmarik / expires_fix_2311.rb
Created April 4, 2011 22:13
:expire_after rails 2.3.11 workaround
# workaround for https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6634-railsrack-inconsistency-about-expires_afterexpires-cookie-option#ticket-6634-3
# expiration issue
# drop into RAILS_ROOT/config/initializers/expires_fix_2311.rb
#
require 'rack'
Rack::Utils.class_eval do
class << self
def set_cookie_with_expire!(header, key, value)
if value[:expires].blank? && value[:expire_after]
module Kernel
alias require_orig_bench require
def require(*args)
from = Time.now.to_f
$__deep ||= 0; $__deep += 1
require_orig_bench(*args)
$stderr.puts %Q[ #{" " * ($__deep - 1) } #{(Time.now.to_f - from)} in #{args.inspect} ]
$__deep -= 1
@gmarik
gmarik / ruby.rb
Last active June 22, 2020 03:24
stuff
class Fixnum
def upto2(n)
(self..n).to_a.map{|k| yield k }
end
end
class A
def sum(n)
sum = 0
1.upto(n) do |i|
bills = [
{:name=>"bill[attachment]",
:filename=>"/data/data/com.rhomobile.imageupload/rhodata/apps/rhoconfig.txt"},
{:name=>"bill[amount]",
:body=>nil}]
Rho::AsyncHttp.upload_file(
:url => 'http://localhost:3000/bills.json',
:callback => url_for(:action => :push_callback),
:multipart => bills)
@gmarik
gmarik / content_types again
Created December 5, 2010 03:03
this doesn't work. Why? because value is a string in a key-value store.
# looks like Content-type is set to application/octet-stream for nil values
#
User-Agent: Mozilla-5.0 (ANDROID; generic; 2.2)
I/APP ( 3006): Content-Length: 3531
I/APP ( 3006): Content-Type: multipart/form-data; boundary=----------------------------44729c969b01
I/APP ( 3006):
I/APP ( 3006): I 12/04/2010 20:55:34:609 0066c790 Net| => Send data (818 bytes): ------------------------------44729c969b01
I/APP ( 3006): Content-Disposition: form-data; name="bill[amount]"
I/APP ( 3006): Content-Type: application/octet-stream
I/APP ( 3006): Content-Length: 0
From 6737da2323d9896fe30de66394a659de2b41e9b1 Mon Sep 17 00:00:00 2001
From: gmarik <gmarik@gmail.com>
Date: Tue, 16 Nov 2010 22:05:27 -0600
Subject: [PATCH] Do not set Content-Type header when body defined
---
platform/shared/net/AsyncHttp.cpp | 1 -
1 files changed, 0 insertions(+), 1 deletions(-)
diff --git a/platform/shared/net/AsyncHttp.cpp b/platform/shared/net/AsyncHttp.cpp
@gmarik
gmarik / rho.rb
Created November 14, 2010 01:30
crap
# Return the directories where we need to load configuration files
def process_model_dirs(app_manifest_filename=nil)
File.open(app_manifest_filename).each do |line|
str = line.chomp
if str != nil and str.length > 0
#puts "model file: #{str}"
modelName = File.basename(File.dirname(str))
Rhom::RhomObjectFactory.init_object(modelName)
require str
$ ARCHFLAGS="-arch i386 -arch x86_64" gem install -V mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
GET http://cdscm/latest_specs.4.8.gz
200 OK
GET http://rubygems.org/latest_specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
200 OK
GET http://gemcutter.org/latest_specs.4.8.gz
302 Moved Temporarily
GET http://production.s3.rubygems.org/latest_specs.4.8.gz
#!/usr/bin/env ruby
#
# http://gmarik.info/blog/2010/10/16/scraping-asp-net-site-with-mechanize
require 'rubygems'
require 'mechanize'
require 'logger'
user = 'user'
pass = 'pass'
#!/bin/sh
which rvm >/dev/null 2>&1 || (echo 'requires RVM' && exit 1)
RUBY=$(rvm list default string)
function install()
{
echo "
Plan: