Skip to content

Instantly share code, notes, and snippets.

View komuw's full-sized avatar

Komu Wairagu komuw

View GitHub Profile
@komuw
komuw / pycrypto_AES.py
Created February 15, 2016 14:19
python AES with CBC/PKCS5Padding
from Crypto.Cipher import AES
from Crypto import Random
import base64
block_size = AES.block_size
#unpad = lambda s : s[0:-ord(s[-1])]
def pad(plain_text):
@komuw
komuw / pycrypto_DES3.py
Last active March 28, 2023 06:35
python DES3(triple DES encryption)
`pip install pycrypto`
from Crypto.Cipher import DES3
from Crypto import Random
key = 'Sixteen byte key'
iv = Random.new().read(DES3.block_size) #DES3.block_size==8
cipher_encrypt = DES3.new(key, DES3.MODE_OFB, iv)
plaintext = 'sona si latine loqueri ' #padded with spaces so than len(plaintext) is multiple of 8
encrypted_text = cipher_encrypt.encrypt(plaintext)
@komuw
komuw / install_nginx_and_override.yml
Created December 25, 2015 16:16
install nginx and override old config
- name: install newer nginx and ovveride old config file
shell: sudo apt-get -y -o Dpkg::Options::=--force-confnew install nginx
notify: restart nginx
@komuw
komuw / create_vpn.sh
Last active November 15, 2023 09:12
create vpn
#https://www.zeitgeist.se/2013/11/22/strongswan-howto-create-your-own-vpn/
#https://www.gypthecat.com/ipsec-vpn-host-to-host-on-ubuntu-14-04-with-strongswan
#Example of simple pre-shared keys vpn setup: https://www.strongswan.org/uml/testresults/ikev2/rw-psk-ipv4/
$ sudo apt-get -y install strongswan
$ ipsec version
Linux strongSwan U5.1.2/K3.13.0-55-generic
Institute for Internet Technologies and Applications
University of Applied Sciences Rapperswil, Switzerland
See 'ipsec --copyright' for copyright information.
@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 {
@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 / 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 / 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 / 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