Skip to content

Instantly share code, notes, and snippets.

@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';

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
##################################################################
# /etc/elasticsearch/elasticsearch.yml
#
# Base configuration for a write heavy cluster
#
# Cluster / Node Basics
cluster.name: logng
# Node can have abritrary attributes we can use for routing

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>
@sr3d
sr3d / cors-nginx.conf
Created May 24, 2012 13:52 — forked from michiel/cors-nginx.conf
Wide-open CORS config for nginx
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
@sr3d
sr3d / gist:2038610
Created March 14, 2012 18:46
autobuild.rb
# This file is to rebuild the dist env automatically so that you don't have to
# rerun ant deploy all the time
#
# To run, install watchr gem
#
# gem install watchr
#
# Then simply run
#
# watchr autobuild.rb