This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import hmac | |
import hashlib | |
import json | |
from base64 import urlsafe_b64encode | |
def create_token(access_key, secret_key, scope): | |
deadline = int(time.time()) + 50000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
from wand.image import Image | |
def resize(blob, min=300, max=1200): | |
image = Image(blob=blob) | |
width = image.width | |
height = image.height | |
if width < min: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; QQDownload 713; .NET CLR 2.0.50727; InfoPath.2)" | |
# sudo iptables -I INPUT -j DROP -s [ip] | |
# row 2 | |
180.96.74.17 | |
182.140.168.14 | |
119.188.77.8 | |
111.30.135.16 | |
113.142.38.15 | |
115.236.140.15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SUBSTITUTE=`ps -A -o pid,rss,command | grep substitute | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'` | |
SUPERVISOR=`ps -A -o pid,rss,command | grep supervisord | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'` | |
GUNICORN=`ps -A -o pid,rss,command | grep gunicorn | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'` | |
MYSQL=`ps -A -o pid,rss,command | grep mysql | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'` | |
NGINX=`ps -A -o pid,rss,command | grep nginx | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'` | |
OTHER=`ps -A -o pid,rss,command | grep -v nginx | grep -v substitute | grep -v gunicorn | grep -v mysql | grep -v supervisord | grep -v grep | awk '{total+=$2}END{printf("%d", total/1024)}'` | |
printf "%-12s %3s MB\n" "Supervisor:" $SUPERVISOR | |
printf "%-12s %3s MB\n" "Substitute:" $SUBSTITUTE | |
printf "%-12s %3s MB\n" "Gunicorn:" $GUNICORN | |
printf "%-12s %3s MB\n" "Nginx:" $NGINX |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask as _Flask | |
from flask.sessions import SecureCookieSessionInterface | |
class _SecureCookieSessionInterface(SecureCookieSessionInterface): | |
def save_session(self, app, session, response): | |
if not session.modified: | |
return | |
super(_SecureCookieSessionInterface, self).save_session( | |
app, session, response |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fs = require('fs'); | |
var path = require('path'); | |
var http = require('http'); | |
var bind = 9090; | |
var basedir = ''; | |
var server = http.createServer(function(req, res) { | |
if (req.method === 'POST') { | |
var d = new Date(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
import urlparse | |
def linky(url): | |
"""Sanitize link. clean utm parameters on link.""" | |
if not re.match(r'^https?:\/\/', url): | |
url = 'http://%s' % url | |
rv = urlparse.urlparse(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://github.com/mozilla/unicode-slugify/blob/master/slugify/__init__.py | |
import re | |
import unicodedata | |
from django.utils.encoding import smart_unicode | |
# Extra characters outside of alphanumerics that we'll allow. | |
SLUG_OK = '-_~' | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var md5 = require('md5'); | |
const SUBSTITUTE_BASE = 'https://example.com/'; | |
const SUBSTITUTE_SECRET = 'a secret'; | |
html = html.replace(/<img[^>]*src=('|")(.*?)\1[^>]*>/g, function(img) { | |
var src = RegExp.$2; | |
var digest = md5.hmac(SUBSTITUTE_SECRET, src); | |
var newSrc = SUBSTITUTE_BASE + digest + '/' + encodeURIComponent(src); | |
return img.replace(src, newSrc); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
def fix_orientation(img): | |
orientation = img.metadata.get('exif:Orientation', 1) | |
if orientation == 1: | |
# do nothing | |
return img | |
elif orientation == 2: | |
# vertical mirror |