Skip to content

Instantly share code, notes, and snippets.

@mengqingzhong
mengqingzhong / generate_certs.sh
Created March 25, 2023 19:35 — forked from rahulkj/generate_certs.sh
Script to generate self signed certificate on Ubuntu
#!/bin/bash
###### For generate_certs.sh script ######
export COUNTRY=US
export STATE=California
export CITY=Irvine
export ORGANIZATION=YourCompany
export UNIT=YourBU
export COMMON_NAME=server.example.com
export SAN_NAME_1=server.example.com

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@mengqingzhong
mengqingzhong / Certificates.go
Created March 25, 2023 14:18 — forked from Mattemagikern/Certificates.go
Create x509 certificate chain using Golang. Root CA, Designated CA, server CA
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"crypto/x509/pkix"
"encoding/pem"
"fmt"
"math/big"
@mengqingzhong
mengqingzhong / dp.c
Created October 11, 2017 11:47
树形动态规划,士兵
#include<iostream>
#include<algorithm>
#include <stdio.h>
using namespace std;
#define COUNT 1501
int father[COUNT];
int childcnt[COUNT];
int n;
@mengqingzhong
mengqingzhong / AVL.c
Created October 11, 2017 08:45
AVL tree
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct Node
{
Node*left;
Node*right;
int value;
int height;
git config --global color.status auto
git config --global color.diff auto
git config --global color.branch auto
git config --global color.interactive auto
@mengqingzhong
mengqingzhong / libevtest.c
Last active September 30, 2022 13:58
libev demo
#include <ev.h>
#include <unistd.h>
#include <stdio.h> // for puts
// every watcher type has its own typedef'd struct
// with the name ev_TYPE
ev_io stdin_watcher;
ev_timer timeout_watcher;
// all watcher callbacks have a similar signature
@mengqingzhong
mengqingzhong / option.c
Last active August 29, 2015 14:26
option
#include<stdio.h>
#include <getopt.h>
int flag;
struct option long_options[] = {
{ "deamon", no_argument, NULL, 'D' },
{ "loglevel", required_argument, NULL, 'L' },
{ "ip", required_argument,&flag, 1 },
{ "port", required_argument, &flag, 2 },
};
@mengqingzhong
mengqingzhong / git config
Last active August 29, 2015 14:21
git config
git config --global user.name ""
git config --global user.email ""
git config --global color.ui auto
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
#!/bin/bash
function show_elapsed_time()
{
user_hz=$(getconf CLK_TCK) #mostly it's 100 on x86/x86_64
pid=$1
jiffies=$(cat /proc/$pid/stat | cut -d" " -f22)
sys_uptime=$(cat /proc/uptime | cut -d" " -f1)
last_time=$(( ${sys_uptime%.*} - $jiffies/$user_hz ))
lastday=$(( $last_time/3600/24 ))
lasthour=$(( ($last_time-$lastday*3600*24)/3600 ))