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/
*/
@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
'''
@thobroni
thobroni / ping.py
Created May 13, 2017 00:38 — forked from zed/ping.py
#!/usr/bin/env python
"""
A pure python ping implementation using raw socket.
Note that ICMP messages can only be sent from processes running as root.
Derived from ping.c distributed in Linux's netkit. That code is
import socket
import time
import sys
def main():
argc = len(sys.argv)
addr = "127.0.0.1"
PORT = 801
if(argc > 1):
addr = sys.argv[1]
@thobroni
thobroni / compassbearing.py
Created May 1, 2017 14:01 — forked from jeromer/compassbearing.py
compass bearing between two points in Python
def calculate_initial_compass_bearing(pointA, pointB):
"""
Calculates the bearing between two points.
The formulae used is the following:
θ = atan2(sin(Δlong).cos(lat2),
cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong))
:Parameters:
- `pointA: The tuple representing the latitude/longitude for the
@thobroni
thobroni / ssh.py
Created March 13, 2017 22:18 — forked from AaronGhent/ssh.py
SSH - Python
#! /usr/bin/env python
# >><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><< #
# ssh - simple ssh2 wrapper
# Author: Aaron Ghent
# >><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><<>><< #
#
# import ssh
# client = ssh.Connection(host='example.com', username='root', password='default')
# client.execute('ls')
# client.close()
@thobroni
thobroni / custom-user-model.py
Created March 12, 2017 23:03
Customizing Django’s Default User Model
# accounts/models.py
from django.db import models
from django.core.validators import RegexValidator
from django.contrib.auth.models import AbstractBaseUser, PermissionsMixin, BaseUserManager
import enums
class AuthUserManager(BaseUserManager):
"""
@thobroni
thobroni / models.py
Created March 11, 2017 22:35 — forked from herrersystem/models.py
[Django] Create your custom user model
from django.db import models
from django.contrib.auth.models import AbstractBaseUser
from django.contrib.auth.models import BaseUserManager
from django.contrib.auth.models import PermissionsMixin
'''
In this example, create usermodel who use email and password for login.
Don't forget to add in settings.py:
AUTH_USER_MODEL='your_app.UserModel'
@thobroni
thobroni / emperor.sh
Created March 11, 2017 21:50 — forked from mariuz/emperor.sh
uwsgi emperor init script for debian 7.x
#!/usr/bin/env bash
### BEGIN INIT INFO
# Provides: emperor
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the uwsgi emperor app server
# Description: starts uwsgi emperor app server using start-stop-daemon
@thobroni
thobroni / iptables.sh
Created March 2, 2017 06:31 — forked from fjyuu/iptables.sh
研究室HTTPサーバのiptables.sh
#!/bin/bash
###########################################################
# このスクリプトの特徴
#
# 受信・通過については基本的に破棄し、ホワイトリストで許可するものを指定する。
# 送信については基本的に許可する。ただし、サーバが踏み台になり外部のサーバに迷惑をかける可能性があるので、
# 心配な場合は、送信も受信同様に基本破棄・ホワイトリストで許可するように書き換えると良い。
###########################################################