Skip to content

Instantly share code, notes, and snippets.

View alexdunae's full-sized avatar

Alex Dunae alexdunae

View GitHub Profile
@guilleiguaran
guilleiguaran / jruby.txt
Created August 20, 2011 06:29
JRuby: From source to RbEnv (1.7.0dev)
% git pull origin master
% ant dist
% tar zxvf dist/jruby-bin-1.7.0.dev.tar.gz -C ~/.rbenv/versions
% cd ~/.rbenv/versions/jruby-1.7.0.dev/bin
% rm -f *.exe *.dll *.bat jruby.sh
% sed -i "" 's/^#!\/bin\/bash/#!\/usr\/bin\/env bash/' jruby
% ln -fs jruby ruby
@saranyan
saranyan / active_merchant.rb
Created December 20, 2011 16:38
PayPal IPN using Active merchant
if Rails.env.production?
PAYPAL_ACCOUNT = 'production@gmail.com'
else
PAYPAL_ACCOUNT = 'development@gmail.com'
ActiveMerchant::Billing::Base.mode = :test
end
@viruthagiri
viruthagiri / wp_plugin_stub.php
Created February 16, 2012 21:36 — forked from mattwiebe/wp_plugin_stub.php
A good starting place for a static class-based WordPress plugin
<?php
/*
Plugin Name: A Plugin Name
Plugin URI: http://somadesign.ca/
Description: Be descriptive.
Version: 0.1
Author: Soma Design
Author URI: http://somadesign.ca/
License: GPL v2
@icyleaf
icyleaf / ar_migrate.rb
Last active June 6, 2024 20:06
ActiveRecord type of integer (tinyint, smallint, mediumint, int, bigint)
# activerecord-3.0.0/lib/active_record/connection_adapters/mysql_adapter.rb
# Maps logical Rails types to MySQL-specific data types.
def type_to_sql(type, limit = nil, precision = nil, scale = nil)
return super unless type.to_s == 'integer'
case limit
when 1; 'tinyint'
when 2; 'smallint'
when 3; 'mediumint'
when nil, 4, 11; 'int(11)' # compatibility with MySQL default
# config/routes.rb
resources :documents do
scope module: 'documents' do
resources :versions do
post :restore, on: :member
end
resource :lock
end
end
@eltercero
eltercero / klass.sublime-snippet
Created July 17, 2015 13:05
Snippet for creating a class with its attributes
<!--
Easily creates something like:
class Object
attr_reader :attr1, :attr2, :attr3
def initialize attr1, attr2, attr3
@attr1 = attr1
@attr2 = attr2
@attr3 = attr3

Scaling your API with rate limiters

The following are examples of the four types rate limiters discussed in the accompanying blog post. In the examples below I've used pseudocode-like Ruby, so if you're unfamiliar with Ruby you should be able to easily translate this approach to other languages. Complete examples in Ruby are also provided later in this gist.

In most cases you'll want all these examples to be classes, but I've used simple functions here to keep the code samples brief.

Request rate limiter

This uses a basic token bucket algorithm and relies on the fact that Redis scripts execute atomically. No other operations can run between fetching the count and writing the new count.

@yahonda
yahonda / ruby31onrails.md
Last active October 21, 2024 18:20
Ruby 3.1 on Rails

Ruby 3.1 on Rails

Actions required to use Ruby 3.1.0 with Rails

Rails 7.0.Z

  • Rails 7.0.1 is compatible with Ruby 3.1.0.
  • Rails 7.0.1 addes net-smtp, net-imap and net-pop gems as Action Mailbox and Action Mailer dependency, you do not need to add them explicitly in your application Gemfile anymore.
  • thor 1.2.1 has been released. You will not see DidYouMean::SPELL_CHECKERS.merge deprecate warnings anymore.

Rails 6.1.Z

  • Use Rails 6.1.5 to support database.yml with aliases and secrets.yml with aliases.