Skip to content

Instantly share code, notes, and snippets.

@sr3d
sr3d / CloudFoundry Push
Created May 30, 2011 22:07
Mongoid Initializer for CloudFoundry
alexle:pushpuppy sr3d$ vmc push pushpuppy --runtime ruby19
Would you like to deploy from the current directory? [Yn]:
Application Deployed URL: 'pushpuppy.cloudfoundry.com'?
Detected a Rails Application, is this correct? [Yn]:
Memory Reservation [Default:256M] (64M, 128M, 256M, 512M or 1G)
Creating Application: OK
Would you like to bind any services to 'pushpuppy'? [yN]: y
Would you like to use an existing provisioned service [yN]? N
The following system services are available::
1. mongodb
Ti.include('../../lib/active_record.js');
Ti.include('../../lib/utils.js');
Ti.include('../../lib/models.js');
var guest = Model.Guest.find(win.guest.id),
gift = Model.Gift.find({ first: true, where: {guest_id: guest.id} }),
sections = [],
currentSection = 0,
yesNoBtn, amountInput, giftDescription,
tableView = Ti.UI.createTableView({ style: Titanium.UI.iPhone.TableViewStyle.GROUPED });
@sr3d
sr3d / config__initializers__active_merchant.rb
Created August 21, 2020 05:51 — forked from werkshy/config__initializers__active_merchant.rb
Mock Authorize.net CIM Gateway (ActiveMerchant). Released under the MIT License
# Initializer where we inject the mock gateway into global variable AUTHNET_GATEWAY or setup the real client
if !Rails.env.production?
ActiveMerchant::Billing::Base.mode = :test
end
$using_mock_auth_net_gateway = false
# Use FORCE_AUTH_NET to use the real Auth.net API in tests
# Use MOCK_AUTH_NET to use the mock Auth.net API even in development (good on a plane!)
@sr3d
sr3d / dev.mydomain.com
Created February 28, 2019 20:03
Alternative to ngrok with Permanent subdomain using Nginx, SSL, and reverse SSH
# Nginx configuration file:
# /etc/nginx/sites-available/dev.mydomain.com
# This block redirects non-ssl traffic to the ssl-version
server {
if ($host = dev.mydomain.com) { # replace with your mydomain
return 301 https://$host$request_uri;
}
// ==UserScript==
// @name Required Shopify Tampermonkey
// @version 0.1
// @author Alex
// @match https://*.myshopify.com/admin/*orders*
// @require https://xxx/shopify-tampermonkey.js?r
// @grant none
// ==/UserScript==
(function() {
'use strict';
#!/usr/bin/env ruby
require 'ftools'
require 'fileutils'
require 'rubygems'
require 'RMagick'
include Magick
require 'open3'
def merge( files = [] )

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.

@sr3d
sr3d / installDante.sh
Created January 18, 2017 09:29 — forked from Fire-/installDante.sh
Basic Dante Socks5 Server Setup and Configuration
# Basic Dante Socks5 Setup, Debian
apt-get update
apt-get install make gcc
cd /usr/src
# get newest from http://www.inet.no/dante/download.html
wget http://www.inet.no/dante/files/dante-1.4.1.tar.gz

Friendly URLs

By default, Rails applications build URLs based on the primary key -- the id column from the database. Imagine we have a Person model and associated controller. We have a person record for Bob Martin that has id number 6. The URL for his show page would be:

/people/6

But, for aesthetic or SEO purposes, we want Bob's name in the URL. The last segment, the 6 here, is called the "slug". Let's look at a few ways to implement better slugs.

@sr3d
sr3d / gist:3505480
Created August 29, 2012 00:00
embeddable
<article itemscope itemtype="http://nik.io/v1/schema/Article">
<span itemprop="categories" content=""></span>
<span itemprop="tags" content=""></span>
<span itemprop="permalink" content=""></span>
<!--
YOUR CONTENT
-->
</article>