Skip to content

Instantly share code, notes, and snippets.

View noogen's full-sized avatar
¯\_(ツ)_/¯

Tom Noogen noogen

¯\_(ツ)_/¯
View GitHub Profile
@noogen
noogen / getuserid.lua
Last active April 19, 2017 20:57
Redis get unique user identity by key
local appPrefix = ARGV[1]
local userId = KEYS[1]
if not appPrefix then
appPrefix = "trak"
end
if not userId then
return "error: userId/keys[1] is required"
end
@noogen
noogen / trackuserevent.lua
Last active April 19, 2017 20:55
Redis track a user event
local utcDate = KEYS[1] -- because redis does not have os.time, we require a utc date expecting yyyy-mm-dd hh-mm-ss
local userId = KEYS[2] -- a username/email/unique identifier
local eventName = KEYS[3] -- event name to track
local siteId = KEYS[4] -- site id
local appPrefix = ARGV[1]
if not utcDate then
return "error: utcDate/keys[1] is required"
end
@noogen
noogen / azure-cache.lua
Last active March 5, 2016 23:19
Azure table storage use as cache
local ACCOUNT='youraccount'
local KEY='youkey'
local azure = require('niiknow/webslib/azure.lua')
-- PrimaryKey is db like in redis, if not provided set to -default
local pKey = request.query['db'] or '-default'
-- RowKey is the actual key
local rKey = request.query['key']
@noogen
noogen / nginx-proxy.conf
Last active December 7, 2021 08:43
nginx proxy example
# https://www.scalescale.com/tips/nginx/nginx-proxy-cache-explained-2/
proxy_cache_path /var/lib/nginx/cache levels=1:2 keys_zone=my_diskcached:10m max_size=5g inactive=45m use_temp_path=off;
server {
listen 80;
set $cache_uri $uri;
server_name example.com;
location ~ /purge(/.*) {
proxy_cache_purge my_diskcached acme.mycachedefault$uri$is_args$args;
@noogen
noogen / ubuntu-16-04-hardening-stage1.md
Last active January 15, 2021 09:09
Ubuntu 16.04 hardening - stage1

From Fresh install

1) update and upgrade as root

apt-get update && apt-get upgrade -y
  • Setting up hostname, skip if done with installation

pico /etc/hosts

@noogen
noogen / fresh-ubuntu-docker.sh
Last active December 13, 2023 18:39
fresh-ubuntu-docker.sh
#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root!" 1>&2
exit 1
fi
export DEBIAN_FRONTEND=noninteractive
add-apt-repository universe
apt-get update && apt-get upgrade -y
apt-get -y install ntpdate fail2ban apt-transport-https ca-certificates software-properties-common
@noogen
noogen / dreamfactory-htaccess
Created January 30, 2017 07:37
DreamFactory-htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
# this allow for anonymous access
<If "req('X-DreamFactory-Api-Key') == '' && req('X-DreamFactory-Session-Token') == ''">
RequestHeader set X-DreamFactory-Api-Key your-app-token
</If>
@noogen
noogen / download-limit.php
Last active January 30, 2017 17:19
Limit download per ip
<?
$path = addslashes($_GET["file"]);
$ip = addslashes($_SERVER['REMOTE_ADDR']);
if(isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
$dl = false;
@noogen
noogen / cron-mcounter.php
Created February 8, 2017 16:25
minute counter
<?
$counterBaseDir = './counter/';
$files = glob($counterBaseDir . '*.txt')
$now = date("YmdHi");
foreach ($files as $file) {
$fileParts = explode($file, "_");
$fileDate = $fileParts[0];
$tenant = $fileParts[1];
@noogen
noogen / hitcounter.conf
Last active January 28, 2022 07:38
nginx hit counter
server {
listen 80 default_server;
listen [::]:80 default_server;
#NGINX_INSERT0;
#NGINX_INSERT1;
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})") {
set $year $1;
set $month $2;