Skip to content

Instantly share code, notes, and snippets.

View lepture's full-sized avatar
💭
I'm working on Typlog.com now

Hsiaoming Yang lepture

💭
I'm working on Typlog.com now
View GitHub Profile
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);
});
# 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 = '-_~'
@lepture
lepture / sanitilize_link.py
Created July 15, 2013 06:34
Clean utm parameters on link.
@lepture
lepture / server.js
Last active December 20, 2015 05:09
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();
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
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
@lepture
lepture / qq_download_ip
Last active December 22, 2015 06:58
deny QQ Download
# "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
# 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:
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
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.