Skip to content

Instantly share code, notes, and snippets.

View huobazi's full-sized avatar
🎯
Focusing

Marble Wu huobazi

🎯
Focusing
View GitHub Profile
@huobazi
huobazi / minio.sh
Created July 6, 2022 07:21 — forked from corbtastik/minio.sh
Bash script to configure, start and stop single node MinIO container instance on Docker
#!/bin/bash
# --------------------------------------------------------------------
# [init] Create run dir, env file if they don't exist, then source env
# --------------------------------------------------------------------
init() {
MINIO_CONTAINER_NAME=$1
MINIO_RUN_DIR=/data1/run/${MINIO_CONTAINER_NAME}
MINIO_DATA=${MINIO_RUN_DIR}/data
MINIO_CERTS=${MINIO_RUN_DIR}/certs
# create run dir for container instance
@huobazi
huobazi / SnowflakeIdGenerator.cs
Created September 2, 2020 08:24 — forked from jessejjohnson/SnowflakeIdGenerator.cs
Generate Twitter Snowflake ID's
public class SnowflakeIdGenerator
{
public const byte DefaultMachineIdBits = 6;
public const byte DefaultSequenceBits = 12;
private readonly long _machineId = 0;
private readonly byte _machineIdBits = 0;
private readonly byte _sequenceBits = 0;
private readonly long _maxSequence = 0;
private readonly Stopwatch _stopwatch = Stopwatch.StartNew();
private readonly object _lockObject = new object();
@huobazi
huobazi / Golang program stdin stdout interaction.md
Created September 1, 2020 09:01 — forked from jamesrr39/Golang program stdin stdout interaction.md
Using stdout and stdin from other programs in Golang

Go program interaction

Example of how to use stdout and stdin from other programs in golang

Requires go

Run

go run parentprocess.go
@huobazi
huobazi / gist:e410bec08320f3ae87bb2dcec8756a8a
Created July 17, 2020 03:11 — forked from imranbaloch/gist:10895917
SqlHelper.cs class with async support
// ===============================================================================
// Microsoft Data Access Application Block for .NET
// http://msdn.microsoft.com/library/en-us/dnbda/html/daab-rm.asp
//
// cs
//
// This file contains the implementations of the SqlHelper and SqlHelperParameterCache
// classes.
//
// For more information see the Data Access Application Block Implementation Overview.
using System;
using System.Collections;
using System.Data;
using MySql.Data.MySqlClient;
using System.Linq;
using System.Xml;
namespace OBALog.Data
{
[System.Diagnostics.DebuggerStepThrough]
@huobazi
huobazi / server.md
Created February 27, 2019 00:53 — forked from jtadeulopes/server.md
Server setup with ubuntu, nginx and puma for rails app.

Update and upgrade the system

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get autoremove
sudo reboot

Configure timezone

@huobazi
huobazi / deploy.rb
Created February 21, 2019 02:32 — forked from Epigene/deploy.rb
Mina deployment file for rails applications
# Mina Deploy
# ===========
#
# Adapted from Creative deploy stack in Manabalss v4, Mar.2015, updated to support staging on Jun.2015
# On first deploy do: mina setup --verbose
# Then do : mina deploy[initialize] --trace
#
# Usage examples:
# mina deploy[soft,seed,compile] to=staging # deploy task with all options | a simple `mina deploy` will deploy to production
# mina rake[db:seed] # for multi-argument tasks # mina 'rake[payments:refund[arg1\,arg2]]'
@huobazi
huobazi / makecerts.sh
Created November 20, 2017 01:33 — forked from rgstephens/makecerts.sh
Make Self Signed Certificate
#!/bin/bash
# https://stackoverflow.com/questions/19665863/how-do-i-use-a-self-signed-certificate-for-a-https-node-js-server
FQDN=$1
KEYDIR=keys
# make directories to work from
#mkdir -p server/ client/ all/
mkdir -p $KEYDIR
# Create your very own Root Certificate Authority
@huobazi
huobazi / self-CA.sh
Created November 20, 2017 01:33
Be your own Certificate Authority
# Kudos to https://datacenteroverlords.com/2012/03/01/creating-your-own-ssl-certificate-authority/
# Create the Root Key
# The first step is to create the private root key which only takes one step.
# In the example below, I’m creating a 2048 bit key:
openssl genrsa -out rootCA-key.pem 2048
# The next step is to self-sign this certificate.
openssl req -x509 -new -nodes -key rootCA-key.pem -sha256 -days 1024 -out rootCA-cert.pem
@huobazi
huobazi / generate_local_certificate.sh
Created November 20, 2017 01:32 — forked from adiog/generate_local_certificate.sh
Generate local certificate
#!/usr/bin/env bash
SERVER=$1
OUTPUT=$2
#Overview
# The following is an extremely simplified view of how SSL is implemented and what part the certificate plays in the entire process.
# Normal web traffic is sent unencrypted over the Internet. That is, anyone with access to the right tools can snoop all of that traffic. Obviously, this can lead to problems, especially where security and privacy is necessary, such as in credit card data and bank transactions. The Secure Socket Layer is used to encrypt the data stream between the web server and the web client (the browser).
# SSL makes use of what is known as asymmetric cryptography, commonly referred to as public key cryptography (PKI). With public key cryptography, two keys are created, one public, one private. Anything encrypted with either key can only be decrypted with its corresponding key. Thus if a message or data stream were encrypted with the server's private key, it can be decrypted only using its corresponding public key, ensuring that the