Skip to content

Instantly share code, notes, and snippets.

View raja-ashok's full-sized avatar

Raja Ashok Karmegam raja-ashok

View GitHub Profile
@raja-ashok
raja-ashok / run_cmd.py
Created April 10, 2018 09:42
Calling an external command or script in Python
#!/usr/bin/env python
import subprocess
import os
# 1) Calling an external command in Python
# Simple way to call external command is using os.system(...). And this funciton returns the exit value of the command.
# But the drawback is we wont get stdout and stderr.
ret = os.system('some_cmd.sh')
if ret != 0 :
@raja-ashok
raja-ashok / find_duplicates.py
Last active April 10, 2018 09:33
Find duplicates in an integer list using python
#!/usr/bin/env python
from itertools import groupby
myList = [1, 2, 1, 3, 1]
for x, y in groupby(sorted(myList)):
# groupby groups by consecutive elements which are similar
# x is the element, y is the list which contains the elements occurence
dup_list = list(y)
print 'x : ' + str(x) + ', y: ' + str(list(dup_list))
@raja-ashok
raja-ashok / gen_ecc_cert.sh
Last active April 26, 2021 16:36
OpenSSL Certificate chain generation
#!/bin/bash
openssl ecparam -genkey -name prime256v1 -conv_form uncompressed -outform PEM -out ec.pem
openssl req -newkey ec:ec.pem -passout pass:123456 -sha256 -subj "/C=IN/ST=Kar/L=En/O=ABC/OU=ABCDepart/CN=root/emailaddress=root@abc.com" -keyout rootkey.pem -out rootreq.pem -config openssl.cnf
openssl x509 -req -in rootreq.pem -passin pass:123456 -sha256 -extfile openssl.cnf -days 14600 -extensions v3_ca -signkey rootkey.pem -out rootcert.pem
openssl ecparam -genkey -name prime256v1 -conv_form uncompressed -outform PEM -out ec.pem
openssl req -newkey ec:ec.pem -passout pass:123456 -sha256 -subj "/C=IN/ST=Kar/L=En/O=ABC/OU=ABCDepart/CN=server/emailaddress=server@abc.com" -keyout serverkey.pem -out serverreq.pem -config openssl.cnf
openssl x509 -req -in serverreq.pem -passin pass:123456 -sha256 -extfile openssl.cnf -days 14600 -extensions usr_cert -CA rootcert.pem -CAkey rootkey.pem -CAcreateserial -out servercert.pem