Skip to content

Instantly share code, notes, and snippets.

@ewancook
ewancook / transcribe.py
Last active December 15, 2020 11:54
Command Line Conversion (Transcriber)
#!/usr/bin/env python3
import argparse
from multiprocessing import freeze_support
from transcriber.converter.dbfworker import utils
from transcriber.converter.dbfworker.worker import DBFWorker
from transcriber.dbf.parser import Parser
TAG_LABEL = "Tagname"
@ewancook
ewancook / pyrrole_conversion.py
Last active October 23, 2020 21:33
Oxidation of Pyrrole to Polypyrrole (Ammonium Persulphate; SDBS)
import argparse
from matplotlib import pyplot, ticker
from scipy import integrate
def f(time, concs, k1, k2, chain_length):
dPY = dPYdt(concs, k1, k2)
return [dPY] + [
x(dPY, chain_length) for x in [dAMPSdt, dSDBSdt, dPPYdt, dAMSdt, dSAdt]
@ewancook
ewancook / day1.cpp
Last active December 1, 2019 13:28
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
int calculate_fuel(int mass) {
return std::floor((float)mass/3-2);
}
@ewancook
ewancook / order_engine.go
Last active January 5, 2020 22:13
Order Book Updating (Kraken)
package orderengine
import (
"sort"
)
// Book represents an order book
type Book []*Order
// Order is a single order to be placed
@ewancook
ewancook / bellman_ford.go
Last active March 9, 2024 08:14
Arbitrage with Bellman Ford
package bellmanford
import (
"math"
)
// Graph represents a graph consisting of edges and vertices
type Graph struct {
edges []*Edge
vertices []uint
@ewancook
ewancook / depriester.py
Last active May 5, 2019 19:47
Computational DePriester Chart
from math import log, exp
tolerance = 1e-5
coefficients = {
"methane": (-292860.0, 8.24450, -0.89510, 59.8465, 0),
"ethene": (-600076.875, 7.90595, -0.84677, 42.94594),
"ethane": (-687248.25, 7.90699, -0.88600, 49.02654),
"propene": (-923484.6875, 7.71725, -0.87871, 47.67624),
"propane": (-970688.5625, 7.15059, -0.76984, 0, 6.90224),
@ewancook
ewancook / crisis.go
Last active June 10, 2019 17:07
fixr: buying crisis tickets
package main
import (
"fmt"
"math/rand"
"time"
"github.com/ewancook/fixr"
"github.com/howeyc/gopass"
)
@ewancook
ewancook / main.go
Created April 1, 2019 18:20
Hydrogenation Reactor
package main
import (
"flag"
"fmt"
"math"
"github.com/cpmech/gosl/la"
"github.com/cpmech/gosl/ode"
"github.com/cpmech/gosl/plt"
@ewancook
ewancook / darcy.bas
Created March 23, 2019 16:41
Darcy Friction Factor (VBA)
Function f(e, D, Re)
' Returns: Darcy friction factor
' Parameters:
' e: absolute roughness
' D: duct diameter
' Re: Reynold's number
A = -2 * Log10(e / D / 3.7 + 12 / Re)
B = -2 * Log10(e / D / 3.7 + 2.51 * A / Re)
C = -2 * Log10(e / D / 3.7 + 2.51 * B / Re)
f = (A - (B - A) ^ 2 / (C - 2 * B + A)) ^ -2
@ewancook
ewancook / fix.bat
Last active February 20, 2018 10:40
Fixes the modelling error (Process Control Toolkit) on recent versions of Windows
@echo off
if not "%1"=="am_admin" (powershell start -verb runas '%0' am_admin & exit)
move %~dp0msflxgrd.ocx %windir%\SysWOW64\msflxgrd.ocx >nul
%windir%\SysWOW64\regsvr32.exe %windir%\SysWOW64\msflxgrd.ocx
echo Should be fixed! Press any key to exit.
pause >nul