(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
| import org.slf4j.Logger | |
| import org.slf4j.LoggerFactory | |
| import ratpack.handling.Context | |
| import ratpack.handling.Handler | |
| import ratpack.http.client.HttpClient | |
| import ratpack.http.client.StreamedResponse | |
| import ratpack.http.MutableHeaders | |
| import ratpack.http.client.RequestSpec | |
| import static ratpack.groovy.Groovy.ratpack |
| local ffi = require "ffi" | |
| local sha512 = require "resty.sha512" | |
| local aes = require "resty.aes" | |
| local ffi_new = ffi.new | |
| local ffi_str = ffi.string | |
| local C = ffi.C | |
| local setmetatable = setmetatable | |
| local error = error |
| var crypto = require("crypto"); | |
| var moment = require("moment") | |
| var s3 = { | |
| generateS3Policy: function (fileName) { | |
| var s3Policy = { | |
| 'conditions': [ | |
| {'bucket': CONF.s3.bucket}, | |
| ['starts-with', '$key', 'uploads/' + fileName], | |
| {'acl': 'public-read'}, |
| # to generate your dhparam.pem file, run in the terminal | |
| openssl dhparam -out /etc/nginx/ssl/dhparam.pem 2048 |
| # | |
| # Wide-open CORS config for nginx | |
| # | |
| location / { | |
| if ($request_method = 'OPTIONS') { | |
| add_header 'Access-Control-Allow-Origin' '*'; | |
| # |
| - certain endpoints are always blocked | |
| if nginx_uri == "/_access_token" or nginx_uri == "/_me" then | |
| ngx.exit(403) | |
| end | |
| -- import requirements | |
| local cjson = require "cjson" | |
| -- setup some app-level vars | |
| local app_id = "APP_ID" |
| local random = math.random | |
| local function uuid() | |
| local template ='xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx' | |
| return string.gsub(template, '[xy]', function (c) | |
| local v = (c == 'x') and random(0, 0xf) or random(8, 0xb) | |
| return string.format('%x', v) | |
| end) | |
| end |
| location ^~ /attachments/download_zip/ { | |
| proxy_pass http://mongrel; | |
| proxy_redirect off; | |
| proxy_set_header Host $host; | |
| proxy_set_header X-Real-IP $remote_addr; | |
| proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; | |
| proxy_set_header X_Forwarded_Proto $scheme; | |
| proxy_read_timeout 120; | |
| proxy_connect_timeout 120; | |
| post_action @notify_zip |
| #! /usr/bin/env python | |
| import redis | |
| import random | |
| import pylibmc | |
| import sys | |
| r = redis.Redis(host = 'localhost', port = 6389) | |
| mc = pylibmc.Client(['localhost:11222']) |