Skip to content

Instantly share code, notes, and snippets.

View mhingston's full-sized avatar

Mark Hingston mhingston

View GitHub Profile
@mhingston
mhingston / random-password.sh
Created February 18, 2018 19:49
Generate a random password using /dev/urandom
#!/bin/bash
if [[ $1 =~ ^[0-9]+$ ]]
then
cat /dev/urandom | tr -dc '[:graph:]' | head -c $1; echo
else
cat /dev/urandom | tr -dc '[:graph:]' | head -c 20; echo
fi
@mhingston
mhingston / luks-setup.sh
Created February 19, 2018 13:33
LUKS Setup
# replace volume-alias with your preferred alias and /mnt/encrypted with your preferred mount point
fdisk /dev/xvdb
cryptsetup luksFormat /dev/xvdb1
cryptsetup luksOpen /dev/xvdb1 volume-alias
mkfs.ext4 /dev/mapper/volume-alias
mkdir /mnt/encrypted
mount /dev/mapper/volume-alias /mnt/encrypted
umount /dev/mapper/volume-alias
cryptsetup luksClose volume-alias
@mhingston
mhingston / ipfs-js-stub
Created February 25, 2018 13:24
IPFS-JS Stub
const main = () =>
{
const node = new Ipfs();
node.on('ready', () =>
{
document.getElementById('files').addEventListener('change', handleFileSelect, false);
});
const handleFileSelect = (event) =>
@mhingston
mhingston / PBKDF2.cs
Last active November 25, 2022 07:16
PBKDF2 for node and C#
using System;
using System.Security.Cryptography;
public class PBKDF2
{
private int hashBytes;
private int saltBytes;
private int iterations;
public PBKDF2(int _hashBytes, int _saltBytes, int _iterations)
@mhingston
mhingston / AES.cs
Last active September 10, 2024 23:16
AES-256-CBC for C# and Node
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
class AES
{
public static string Encrypt(string plainText, string keyString)
{
byte[] cipherData;
@mhingston
mhingston / smartDate.js
Last active October 15, 2018 10:59
Smart date (SQL)
const toSmartDate = (date) =>
{
const year = date.getFullYear() * 10000;
const month = (date.getMonth()+1) * 100;
const day = date.getDate();
return year + month + day;
}
const fromSmartDate = (smartDate) =>
{
@mhingston
mhingston / ffmpeg
Created December 15, 2018 21:10
Create video from audio + image using ffmpeg
ffmpeg -loop 1 -framerate 1 -i image.jpg -i music.mp3 -c:v libx264 -preset veryslow -crf 0 -c:a copy -shortest output.mkv
@mhingston
mhingston / stub.cs
Created February 4, 2019 19:22
Stub example working with EPPlus and MailKit
foreach (DataRow task in tasks)
{
DataRow manufacturer = GetManufacturer(Convert.ToInt32(task["ManufacturerID"]));
DataRowCollection recipients = GetRecipients(Convert.ToInt32(task["ManufacturerID"]));
if (recipients.Count > 0)
{
DataSet results = GetResults(Convert.ToDateTime(task["StartDate"]), Convert.ToDateTime(task["EndDate"]), Convert.ToInt32(task["ManufacturerID"]));
ExcelPackage package = new ExcelPackage();
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");