Skip to content

Instantly share code, notes, and snippets.

View pauldotknopf's full-sized avatar

Paul Knopf pauldotknopf

View GitHub Profile
@pauldotknopf
pauldotknopf / Example.cs
Last active December 21, 2018 12:53
Shared connections/transactions with AsyncLocal.
public async Task<Case> StartCase(int caseId, int userId)
{
using (var connection = new ConScope(_dataService))
using (var transaction = new TransScope())
{
// A transaction is used inside of the settings service as well.
// It uses the same "ConScope" and "TransScope" types internally,
// allowing us to share a single IDbConnection and IDbTransaction.
var caseContext = await _settingsService.GetSetting<CaseContext>();
if (caseContext.CurrentCaseId == caseId)
-- MySQL dump 10.13 Distrib 5.5.62, for debian-linux-gnu (x86_64)
--
-- Host: localhost Database: huginn_production
-- ------------------------------------------------------
-- Server version 5.5.62-0ubuntu0.14.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
@pauldotknopf
pauldotknopf / functions.sh
Created April 12, 2019 21:24
Helps commands for converting between decimal/binary/hex formats.
function dec-to-hex() {
echo "ibase=10;obase=16;$1" | bc
}
function dec-to-bin() {
echo "ibase=10;obase=2;$1" | bc
}
function hex-to-dec() {
echo "ibase=16;obase=A;$1" | bc
@pauldotknopf
pauldotknopf / export.sh
Created May 5, 2021 15:02
Export all collections from a mongo db
#!/bin/bash
DB=$1
COLLECTIONS=$(mongo localhost:27017/$DB --quiet --eval "db.getCollectionNames()" | tr -d '\[\]\"[:space:]' | tr ',' ' ')
for collection in $COLLECTIONS; do
echo "Exporting $DB/$collection ..."
mongoexport -d $DB -c $collection -o $collection.json
done
@pauldotknopf
pauldotknopf / TideChanges.cs
Created March 26, 2023 13:00
C# .NET method function to plot the tide changes.
public static double PlotFromHighToLow(double highTide, double lowTide, double distance, double at)
{
var halfAmplitude = Math.Abs(highTide - lowTide) / 2;
var center = halfAmplitude + lowTide;
var y = halfAmplitude * Math.Sin(((Math.PI / (distance)) * (at + (distance / 2)))) + center;
return y;
}
public static double PlotFromLowToHide(double lowTide, double highTide, double distance, double at)