Skip to content

Instantly share code, notes, and snippets.

View komuw's full-sized avatar

Komu Wairagu komuw

View GitHub Profile
@komuw
komuw / gist:fb746bbb85ddcc3d00ac
Created January 29, 2015 09:07
ansible execute bash script
name: execute bash script
command: bash {{ APP_DIR }}/some_script.sh
@komuw
komuw / gist:00fca08aa2c81c05d97e
Last active September 26, 2016 10:07
ssl on nginx django
#A very good resource on configuring some webservers with ssl:
https://wiki.mozilla.org/Security/Server_Side_TLS
# create a file: /etc/nginx/sites-enabled/app_name.conf and also link to /etc/nginx/sites-available/app_name.conf
# and edit as:
log_format timed_combined '$remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" $request_time';
@komuw
komuw / django 1.3wsgi.py
Created March 17, 2015 11:27
django 1.3 wsgi.py
import os
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings")
# This application object is used by the development server
# as well as any WSGI server configured to use this file.
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
@komuw
komuw / gist:5b37ad11a320202c3408
Last active August 29, 2015 14:21
generate server cert,key and client certificate and use them in Nginx.
#Taken from:
http://nategood.com/client-side-certificate-authentication-in-ngi
#reposted here to preserve history
#see: https://gist.github.com/komuW/076231fd9b10bb73e40f for a bash script to auto-generate all this
Client Side Certificate Auth in Nginx
Why Client-Side Certificate Authentication? Why nginx?
I sometimes peruse the ReST questions of stackoverflow.com. Many times I see questions about authentication. There are many options (Basic HTTP Auth, Digest HTTP Auth, OAuth, OAuth Wrap, etc.) however when security is of importance, I like to recommend client side certificates. This is the route our team at ShowClix chose when implementing our API.
@komuw
komuw / gist:076231fd9b10bb73e40f
Created May 20, 2015 15:59
Shell script to generate server cert, key and client certs (all self-signed)
#! /usr/bin/env bash
# Create the CA Key and Certificate for signing Client Certs
openssl genrsa -des3 -out ca.key 4096
openssl req -new -x509 -days 365 -key ca.key -out ca.crt
# Create the Server Key, CSR, and Certificate
openssl genrsa -des3 -out server.key 1024
openssl req -new -key server.key -out server.csr
@komuw
komuw / https in haproxy
Last active October 27, 2015 16:52
https in haproxy
#/etc/haproxy/haproxy.cfg
frontend http-in
bind *:{{APP_PORT}}
mode http
default_backend servers
frontend https-in
bind *:{{APP_PORT_HTTPS}} ssl no-sslv3 crt /etc/haproxy/server_cert.pem
reqadd X-Forwarded-Proto:\ https
@komuw
komuw / fake(mock) datetime in python (django)
Created June 2, 2015 09:17
fake(mock) datetime in python (django)
class DateTimefaker(datetime):
"""
fake datetime to use your own custom datetimes
"""
def __new__(cls, *args, **kwargs):
return datetime.__new__(datetime, *args, **kwargs)
class TestSomething(TestCase):
fixtures = ['test_data']
@komuw
komuw / read_from_mem.py
Last active August 29, 2015 14:24
python read file from memory
# We compare/measure reading a file from memory(1) vs reading from filesytem(2)
##################################
### 1. reading file from memory ##
##################################
import time
import mmap
filename = "myfile.txt"
@komuw
komuw / test_xml.py
Created July 2, 2015 13:31
test xml in django/ rest framework
from rest_framework.test import APIClient
class SomeTests(LiveServerTestCase):
def setUp(self):
self.real_URL = settings.SOME_URL
settings.SOME_URL = '{0}/some-url/'.format(self.live_server_url)
self.client = APIClient()
self.payload = """<some>xml-string</xml>"""
@komuw
komuw / http_handlers.go
Last active August 29, 2015 14:24
answer to a tour of go exercise on http handlers(web servers) https://tour.golang.org/methods/14
package main
import (
"fmt"
"net/http"
)
type Mystring string
type Mystruct struct {