Skip to content

Instantly share code, notes, and snippets.

View greentornado's full-sized avatar

Hai Nguyen greentornado

View GitHub Profile
@greentornado
greentornado / trailing-slash-middleware
Created May 11, 2017 03:37 — forked from dannypurcell/trailing-slash-middleware
Ring middleware fn. Removes a trailing slash from the uri before calling the handler.
(defn ignore-trailing-slash
"Modifies the request uri before calling the handler.
Removes a single trailing slash from the end of the uri if present.
Useful for handling optional trailing slashes until Compojure's route matching syntax supports regex.
Adapted from http://stackoverflow.com/questions/8380468/compojure-regex-for-matching-a-trailing-slash"
[handler]
(fn [request]
(let [uri (:uri request)]
(handler (assoc request :uri (if (and (not (= "/" uri))
@greentornado
greentornado / phpbrew-config.md
Created November 16, 2017 03:34 — forked from yang-wei/phpbrew-config.md
How to use switch PHP(using phpbrew) version in nginx config
php -v
PHP 5.6.3 (cli) (built: Oct 28 2015 09:47:41)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies

But this only changes in CLI. You have to tweak you nginx(same for apache) to make it works. Nginx will still using the native PHP-FPM.

> ps aux | grep php-fpm
@greentornado
greentornado / README.md
Created April 8, 2019 03:51 — forked from hasanbayatme/README.md
A Simple Bash Script for Installing Composer on Ubuntu Locally (current user) and Globally (all users).

Installation

Install composer locally (current user only):

wget -O - https://gist.github.com/EmpireWorld/1dd5f59566e186907f99dc16badc382a/raw/install-composer-local.sh | bash

Install composer globally (all users):

@greentornado
greentornado / install-chrome-headless.sh
Created April 10, 2019 03:54 — forked from pragmaticivan/install-chrome-headless.sh
Installing headless chrome on Ubuntu.
#!/bin/bash
# from https://chromium.woolyss.com/
# and https://gist.github.com/addyosmani/5336747
# and https://chromium.googlesource.com/chromium/src/+/lkgr/headless/README.md
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:canonical-chromium-builds/stage
sudo apt-get update
sudo apt-get install chromium-browser
chromium-browser --headless --no-sandbox http://example.org/
@greentornado
greentornado / chromeinstall_ubu16.sh
Created April 10, 2019 03:54 — forked from LoganGray/chromeinstall_ubu16.sh
this worked to install selenium and google chrome on my Ubuntu 16 server.
#!/usr/bin/env bash
# used to install offical chrome and selenium on Ubuntu 16.04.1 LTS, Jan 2019
cd ~
sudo apt-get update
sudo apt install python-pip
pip install simplejson
pip install bs4
pip install selenium
apt-get install libasound2 libnspr4 libnss3 libxss1 xdg-utils unzip
sudo apt-get install -y libappindicator1 fonts-liberation
@greentornado
greentornado / example.com
Created April 12, 2019 12:12 — forked from 1hakr/example.com
Supercharge your NGIX config
proxy_cache_path /tmp/cacheapi levels=1:2 keys_zone=microcacheapi:100m max_size=1g inactive=1d use_temp_path=off;
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name example.com;
location /api/ {
# Rate Limiting
limit_req zone=reqlimit burst=20; # Max burst of request
@greentornado
greentornado / progress.py
Created April 25, 2019 15:40 — forked from ahopkins/progress.py
Python command line progress bar in less than 10 lines of code.
# The MIT License (MIT)
# Copyright (c) 2016 Vladimir Ignatev
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#
@greentornado
greentornado / feed.py
Created April 25, 2019 15:45 — forked from ahopkins/# Sanic websocket feeds v1.md
Sanic Websocket Feed
from .objects import Feed
# from sanic_jwt.decorators import protected
feeds = {}
def get_feed(feed_name, app):
if feed_name in feeds:
return feeds.get(feed_name)
@greentornado
greentornado / sanic-websockets.py
Created April 30, 2019 14:10 — forked from ahopkins/# Sanic websocket feeds v2.md
Sanic based websocket pubsub feed
import json
import random
import string
from functools import partial
from sanic import Sanic
import aioredis
import asyncio
import websockets