Skip to content

Instantly share code, notes, and snippets.

View jerzyn's full-sized avatar

Andrzej Jarzyna jerzyn

  • PZU
View GitHub Profile
@jerzyn
jerzyn / diff-nginx-upstream.conf
Created March 21, 2014 15:11
Nginx upstream configuration
upstream production_upstream {
server production-environment-url-with-port max_fails=5 fail_timeout=30;
}
upstream sandbox_upstream {
server sandbox-environment-url-with-port max_fails=5 fail_timeout=30;
}
@jerzyn
jerzyn / diff-nginx-servername.conf
Created March 21, 2014 15:13
Nginx server_name configuration
listen 80;
## CHANGE YOUR SERVER_NAME TO YOUR CUSTOM DOMAIN OR LEAVE IT BLANK IF ONLY HAVE ONE
server_name YOUR-SERVICE-DOMAIN-FOR-NGINX;
@jerzyn
jerzyn / diff-nginx-lua-path.conf
Created March 21, 2014 15:14
Nginx change lua file path
## CHANGE THE PATH TO POINT TO THE RIGHT FILE ON YOUR FILESYSTEM
access_by_lua_file LUA-SYSTEM-PATH;
@jerzyn
jerzyn / diff-nginx-commenting-out.conf
Created March 21, 2014 15:15
Nginx commenting out unneeded lines
-- if is_known ~= 200 then
local res = ngx.location.capture("/threescale_authrep", { share_all_vars = true })
-- -- IN HERE YOU DEFINE THE ERROR IF CREDENTIALS ARE PASSED, BUT THEY ARE NOT VALID
-- if res.status ~= 200 then
-- -- remove the key, if it's not 200 let's go the slow route, to 3scale's backend
-- api_keys:delete(ngx.var.cached_key)
-- ngx.status = res.status
-- ngx.header.content_type = "application/json"
-- error_authorization_failed(service)
@jerzyn
jerzyn / diff-nginx-match-plans.conf
Last active August 29, 2015 13:57
Nginx matching the environments plans names
local s = ngx.re.match(res.body,[=[<plan>Sandbox]=])
local p = ngx.re.match(res.body,[=[<plan>Production]=])
if p then
ngx.var.proxy_pass = "http://production_upstream"
elseif s then
ngx.var.proxy_pass = "http://sandbox_upstream"
end
@jerzyn
jerzyn / varnish-module-config.vcl
Created March 21, 2014 15:25
Varnish - Configure the Module and VCL Script
import threescale;
set req.http.X-tmp = threescale.send_get_request_threaded(“su1.3scale.net”,“80”,req.url,"");
set req.http.X-tmp = threescale.send_get_request(“su1.3scale.net”,“80”,req.url,“X-ur-header: true;”);
@jerzyn
jerzyn / varnish-benchmark
Created March 21, 2014 15:29
Varnish - benchmark reduced latency
ab -c 1 -n 1 http://127.0.0.1:8080/transactions/authrep.xml?provider_key=PROVIDER_KEY&app_id=APP_ID&app_key=APP_KEY&%5Busage%5D%5Bhits%5D=1
@jerzyn
jerzyn / retrieve-account-plan.liquid
Created March 21, 2014 15:32
Account Plans - Controlling Portal Content Based on Account Plans
{% for feature in current_user.account.bought_account_plan.system_name %}
...
{% endfor %}
@jerzyn
jerzyn / authorize.php
Last active August 29, 2015 13:57
PHP plugin setup
$response = $client->authorize("the app id", "the app key");
@jerzyn
jerzyn / cc-notification.html
Created March 21, 2014 16:09
Create a home page notification when the credit card details are missing
{% if current_account %}
{% if current_account.credit_card_required? and current_account.credit_card_missing? %}
<div class="missing_card">
<p>You have selected a paid API plan.
Please <a href="{{ urls.payment_details }}">enter your credit card</a>
to get access to your API key.</p>
</div>
{% endif %}
{% endif %}