Skip to content

Instantly share code, notes, and snippets.

class CreateFoos < ActiveRecord::Migration
def change
create_table :foos do |t|
t.timestamps
end
add_column(:foos, :bar, :json)
end
end
foo = Foo.new
foo.bar = [1,2,3]
foo.save
foo.reload
foo.bar.class # Array
foo.bar # [1,2,3]
foo.bar = {a:1, b:2}
foo.save
@jjb
jjb / gist:6878300
Created October 8, 2013 02:09
If you are uploading something to S3 using the aws-sdk gem (https://github.com/aws/aws-sdk-ruby) and getting timeout errors (AWS::S3::Errors::RequestTimeout: Your socket connection to the server was not read from or written to within the timeout period. Idle connections will be closed.), do this!
AWS.config(:http_open_timeout => 99999, :http_read_timeout => 99999)
@jjb
jjb / gist:6911556
Last active December 25, 2015 03:39
<?php
function is_subscriber_or_anonymous() {
global $current_user;
$current_user = wp_get_current_user();
if ( !($current_user instanceof WP_User) )
true;
$roles = $current_user->roles;
@jjb
jjb / gist:6928376
Last active May 6, 2022 20:33
Installing ruby on MacOS with rbenv / ruby-build using readline from macports
sudo port -v selfupdate
sudo port install rbenv
sudo port install ruby-build
sudo port install readline
RUBY_CONFIGURE_OPTS="--with-readline-dir=/opt/local" rbenv install 2.7.1
# this gist previously also specified the openssl dir,
# but these days ruby-build downloads and builds its own openssl for you
# --with-openssl-dir=/opt/local
@jjb
jjb / gist:6952117
Created October 12, 2013 16:44
running wrong's test suite
➔ g clone [email protected]:sconover/wrong.git
Cloning into 'wrong'...
remote: Counting objects: 1838, done.
remote: Compressing objects: 100% (1044/1044), done.
remote: Total 1838 (delta 795), reused 1793 (delta 754)
Receiving objects: 100% (1838/1838), 8.53 MiB | 2.15 MiB/s, done.
Resolving deltas: 100% (795/795), done.
Checking connectivity... done
➔ cd wrong
➔ rbenv shell 1.9.3-p385-perf
@jjb
jjb / gist:7175694
Last active July 20, 2024 18:17
How to configure Textmate to use the rbenv ruby and gems
  1. Preferences -> Variables
  2. add this to the front of PATH: $HOME/.rbenv/bin:$HOME/.rbenv/shims:
  3. set TM_RUBY to this: $HOME/.rbenv/shims/ruby
  4. populate RBENV_VERSION with your version. example: 2.1.0-preview1
  5. (and make sure the checkboxes for each of those variables is selected)
@jjb
jjb / gist:7389552
Last active December 22, 2024 15:58
Ruby 2.1 memory configuration

This all applies to Ruby 2.1. In some cases a setting is not available in 2.0, this is noted. There is also a different with 1.9, 1.8, and REE --- these are not noted.

All the relevant code is in https://github.com/ruby/ruby/blob/master/gc.c

RUBY_HEAP_MIN_SLOTS

default: 10000

The number of heap slots to start out with. This should be set high enough so that your app has enough or almost enough memory after loading so that it doesn't have to allocate more memory on the first request (althogh this probably isn't such a big deal for most apps).

(todo: figure out how big a slot is. i think the answer can be infered from this code.)

@jjb
jjb / jruby
Last active December 28, 2015 22:29
difference in MRI vs. JRuby behavior
> RUBY_DESCRIPTION
=> "jruby 1.7.6 (2.0.0p195) 2013-10-22 6004147 on Java HotSpot(TM) 64-Bit Server VM 1.6.0_65-b14-462-11M4609 [darwin-x86_64]"
> User.first.try :devise_mailer
NoMethodError: undefined method `devise_mailer' for #<User:0x12d4172e>
from org/jruby/RubyBasicObject.java:1497:in `method_missing'
@jjb
jjb / 1 — readme.md
Last active February 11, 2017 11:38
Leave closed Trello boards for which you are not an admin
  1. go here and get your Developer Key (ignore that token) https://trello.com/1/appKey/
  2. visit this url, with your Developer Key inserted as shown https://trello.com/1/authorize?key=YOURDEVELOPERKEY&name=My+Application&expiration=1day&response_type=token&scope=read,write
  3. grant access, and then get the token that is produced on the next page
  • You'll need to add a file in the same directory called settings.py that contains strings for MY_KEY, MY_TOKEN, and USER_TOKEN (USER_TOKEN can be an empty string)
  • Run the script with the last line commented out to see what boards you're leaving. When you're ready to do it for real, uncomment the last line.