Skip to content

Instantly share code, notes, and snippets.

View mhingston's full-sized avatar

Mark Hingston mhingston

View GitHub Profile
@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");
@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 / 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 / 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 / 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 / quotes.md
Last active March 18, 2018 09:43
A collection of quotes

"I am, somehow, less interested in the weight and convolutions of Einstein’s brain than in the near certainty that people of equal talent have lived and died in cotton fields and sweatshops." -- Steven Jay Gould

"The truth is, you don't struggle with depression, you struggle with the reality we live in." -- Keanu Reeves

"Culture is not your friend. Culture is for other peoples’ convenience and the convenience of various institutions, churches, companies, tax collection schemes, what have you. It is not your friend. It insults you. It disempowers you. It uses and abuses you. None of us are well-treated by culture." -- Terence McKenna

>"It is no measure of health to be well adjusted to a profoundly sick society."

@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 / 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 / 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 / app.js
Created February 5, 2018 14:00
Use ACRCloud (https://www.acrcloud.com) to identify songs from a digital radio station and email you when the same artist plays 3 times in a row.
/*
Use ACRCloud (https://www.acrcloud.com) to identify songs from a digital radio station and email you when the same artist plays 3 times in a row which could be useful for certain radio competitions (e.g. http://www.heart.co.uk/radio/win-with-hearts-30k-triple-play/). This is just a proof on concept.
npm init -y
npm install --save lodash mailgun-js express body-parser
1) Edit the config as below, you'll need a Mailgun API key for sending emails.
2) Run this app server behind a reverse proxy like NGINX.
3) Setup broadcast monitoring on ACRCloud.