Skip to content

Instantly share code, notes, and snippets.

@sr3d
sr3d / config__initializers__active_merchant.rb
Created Aug 21, 2020 — forked from werkshy/config__initializers__active_merchant.rb
Mock Authorize.net CIM Gateway (ActiveMerchant). Released under the MIT License
View config__initializers__active_merchant.rb
# 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 Feb 28, 2019
Alternative to ngrok with Permanent subdomain using Nginx, SSL, and reverse SSH
View dev.mydomain.com
# 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;
}
View embedded
// ==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';
View 0-rate-limiters.md

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 Jan 18, 2017 — forked from Fire-/installDante.sh
Basic Dante Socks5 Server Setup and Configuration
View installDante.sh
# 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
View elasticsearch.yml
##################################################################
# /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
View friendly_urls.markdown

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.

View gist:3505480
<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 — forked from michiel/cors-nginx.conf
Wide-open CORS config for nginx
View cors-nginx.conf
#
# Wide-open CORS config for nginx
#
location / {
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
#
View gist:2038610
# 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