Skip to content

Instantly share code, notes, and snippets.

@hugowan
hugowan / openssl.md
Created July 5, 2022 18:14 — forked from roustem/openssl.md
Common OpenSSL Commands with Keys and Certificates

Common OpenSSL Commands with Keys and Certificates

SSL Info

Generate RSA private key with certificate in a single command

openssl req -x509 -newkey rsa:4096 -sha256 -keyout example.key -out example.crt -subj "/CN=example.com" -days 3650 -passout pass:foobar

Generate Certificate Signing Request (CSR) from private key with passphrase

openssl x509 -x509toreq -in example.crt -out example.csr -signkey example.key -passin pass:foobar

@hugowan
hugowan / time.py
Created November 20, 2018 09:04
Finding yesterday’s beginning and ending unix timestamp
import datetime
import time
yesterday = datetime.datetime.now() - datetime.timedelta(days = 1)
yesterday_beginning = datetime.datetime(yesterday.year, yesterday.month, yesterday.day,0,0,0,0)
yesterday_beginning_time = int(time.mktime(yesterday_beginning.timetuple()))
yesterday_end = datetime.datetime(yesterday.year, yesterday.month, yesterday.day,23,59,59,999)
yesterday_end_time = int(time.mktime(yesterday_end.timetuple()))
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="https://v4-alpha.getbootstrap.com/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css" rel="stylesheet">
<style type="text/css">
.container {position: absolute; top:0; left: 0; z-index: 1000; wid}
.nav-link {padding: .5em 0;}
@staticmethod
def getArrayParam(request, key):
rs = {}
for k, v in request.POST.iteritems():
if re.match(key + '\[', k):
newKey = re.findall(r'\[(.*?)\]', k)
if len(newKey) == 1:
rs[newKey[0]] = v
else:
if newKey[0] not in rs:
@hugowan
hugowan / manifest.xml
Created December 3, 2015 08:33
auspost maninfest xml
<?xml version="1.0" encoding="UTF-8"?>
<PCMS xmlns="http://www.auspost.com.au/xml/pcms">
<SendPCMSManifest>
<header>
<TransactionDateTime>2010>01-13T16:30:00.0Z</TransactionDateTime>
<TransactionId>1</TransactionId>
<TransactionSequence>1</TransactionSequence>
<ApplicationId>MERCHANT</ApplicationId>
</header>
<body>
@hugowan
hugowan / gist:10581957
Last active August 29, 2015 13:59
lego
<?php
$lego = new lego();
$lego->init();
class lego {
private $yql = 'https://query.yahooapis.com/v1/public/yql?q=';
<?php
$url = 'http://t.hk.qq.com/index.php/u/janetchow0825';
$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
@hugowan
hugowan / gist:3096288
Created July 12, 2012 06:32
CodeIgniter cURL Elastic Search Client
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class ElasticSearch {
public $index;
function __construct($config = array('server' => 'http://localhost:9200'))
{
$this->server = $config['server'];
}
@hugowan
hugowan / gist:2923089
Created June 13, 2012 09:37
HTML5 Ajax upload
<form>
<input type="file" id="file" name="file">
<input type="submit">
</form>
<script>
$('form').submit(function (e) {
e.preventDefault();
var data;