Skip to content

Instantly share code, notes, and snippets.

View thobroni's full-sized avatar

Riza B.T. thobroni

View GitHub Profile
<?php
/**
* WP Redix Index
*
* Redis caching system for WordPress. Inspired by Jim Westergren.
*
* @author Jeedo Aquino
* @see http://www.jeedo.net/lightning-fast-wordpress-with-nginx-redis/
* @see http://www.jimwestergren.com/wordpress-with-redis-as-a-frontend-cache/
*/
#!/bin/bash
# This script creates a compressed backup archive of the given directory and the given MySQL table. More details on implementation here: https://theme.fm
# Feel free to use this script wherever you want, however you want. We produce open source, GPLv2 licensed stuff.
# Author: Konstantin Kovshenin exclusively for Theme.fm in June, 2011
# Set the date format, filename and the directories where your backup files will be placed and which directory will be archived.
NOW=$(date +"%Y-%m-%d-%H%M")
FILE="example.org.$NOW.tar"
BACKUP_DIR="/home/username/backups"
@thobroni
thobroni / remove_cpt_prefix.php
Created June 4, 2020 04:54
Remove the slug from published cpt post permalinks.
<?php
/**
* Remove the slug from published post permalinks.
* Only affect to our custom post type, though.
*/
add_filter("post_type_link", "wphdlr_remove_post_type_slug", 10, 3);
function wphdlr_remove_post_type_slug($post_link, $post, $leavename)
{
if (!in_array("users", $post->post_type))
<?php
function get_encrypt($string, $key)
{
srand((double) microtime() * 1000000);
$key = md5($key);
$td = mcrypt_module_open("des", "", "cfb", "");
$key = substr($key, 0, mcrypt_enc_get_key_size($td));
$iv_size = mcrypt_enc_get_iv_size($td);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
@thobroni
thobroni / distance.js
Created April 25, 2018 05:24
distance.js
/*!
* JavaScript function to calculate the geodetic distance between two points specified by latitude/longitude using the Vincenty inverse formula for ellipsoids.
*
* Original scripts by Chris Veness
* Taken from http://movable-type.co.uk/scripts/latlong-vincenty.html and optimized / cleaned up by Mathias Bynens <http://mathiasbynens.be/>
* Based on the Vincenty direct formula by T. Vincenty, “Direct and Inverse Solutions of Geodesics on the Ellipsoid with application of nested equations”, Survey Review, vol XXII no 176, 1975 <http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf>
*
* @param {Number} lat1, lon1: first point in decimal degrees
* @param {Number} lat2, lon2: second point in decimal degrees
* @returns {Number} distance in metres between points
@thobroni
thobroni / latlong.js
Created April 25, 2018 05:09
latlong.js
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Latitude/longitude spherical geodesy tools (c) Chris Veness 2002-2017 */
/* MIT Licence */
/* www.movable-type.co.uk/scripts/latlong.html */
/* www.movable-type.co.uk/scripts/geodesy/docs/module-latlon-spherical.html */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
'use strict';
if (typeof module!='undefined' && module.exports) var Dms = require('./dms'); // ≡ import Dms from 'dms.js'
<?php
add_action("init", "wprl_add_endpoints");
function wprl_add_endpoints()
{
add_rewrite_rule('^book/([^/]+)/([^/]+)/?', 'index.php?post_type=book&name=$matches[1]&tab=$matches[2]', 'top');
}
add_filter("query_vars", "wprl_query_vars");
function wprl_query_vars($vars)
@thobroni
thobroni / map.py
Created May 21, 2017 03:34
Python number mapping, taken from : http://stackoverflow.com/a/1969274
def mapping(value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
leftSpan = leftMax - leftMin
rightSpan = rightMax - rightMin
# Convert the left range into a 0-1 range (float)
valueScaled = float(value - leftMin) / float(leftSpan)
# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan)
@thobroni
thobroni / map.py
Created May 21, 2017 03:33
Python number mapping
def mapping(value, leftMin, leftMax, rightMin, rightMax):
# Figure out how 'wide' each range is
leftSpan = leftMax - leftMin
rightSpan = rightMax - rightMin
# Convert the left range into a 0-1 range (float)
valueScaled = float(value - leftMin) / float(leftSpan)
# Convert the 0-1 range into a value in the right range.
return rightMin + (valueScaled * rightSpan)
@thobroni
thobroni / udp_threadpool_server.py
Created May 13, 2017 02:48 — forked from loadletter/udp_threadpool_server.py
ThreadedUDPServer with threadpool
#Threaded UDPServer with threadpool
import SocketServer
from Queue import Queue
import threading, socket
class ThreadPoolMixIn(SocketServer.ThreadingMixIn):
'''
use a thread pool instead of a new thread on every request
'''