Skip to content

Instantly share code, notes, and snippets.

View Warrenn's full-sized avatar

Warrenn Enslin Warrenn

  • Busyweb
  • South Africa
View GitHub Profile
@Warrenn
Warrenn / cloudformation-docker.yml
Last active February 25, 2024 21:28
install docker image from ecr
AWSTemplateFormatVersion: "2010-09-09"
Description: Template to deploy funding-arbitrage futures instance
Metadata:
cfn-lint:AWSTemplateFormatVersion: "2010-09-09"
Description: Template to deploy funding-arbitrage futures instance
Metadata:
@Warrenn
Warrenn / execute-nonquery
Created August 18, 2022 16:27
execute database update insert or delete
function Execute-NonQuery([psobject[]]$sqlCommands, $connectionString) {
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$connection.Open()
$command = $connection.CreateCommand()
$transaction = $connection.BeginTransaction()
$command.Connection = $connection
$command.Transaction = $transaction
try {
@Warrenn
Warrenn / powershell get-dataset
Created August 17, 2022 18:26
get a dataset from a database
function Get-DataSet($sqlCommand, $parameters, $connectionString) {
$connection = new-object system.data.SqlClient.SQLConnection($connectionString)
$command = new-object system.data.sqlclient.sqlcommand($sqlCommand,$connection)
$dataset = New-Object System.Data.DataSet
$parameters | Select-Object -ExpandProperty Keys | %{
$command.Parameters.Add($_, $parameters[$_])
}
try{
@Warrenn
Warrenn / gist:856defce94e2d3d899f5884d5e5a0a8d
Created May 4, 2022 11:51
FallbackCredentialsFactory.cs
FallbackCredentialsFactory.CredentialsGenerators.Insert(0, () =>
{
var profileName = Environment.GetEnvironmentVariable("AWS_PROFILE");
if (string.IsNullOrWhiteSpace(profileName)) return null;
var chain = new CredentialProfileStoreChain();
return !chain.TryGetProfile(profileName, out var profile) ? null : new BasicAWSCredentials(profile.Options.AccessKey, profile.Options.SecretKey);
});
@Warrenn
Warrenn / StaticAsyncMediator.cs
Created May 3, 2022 07:57
facilitates async await
public static class StaticAsyncMediator
{
private static readonly IDictionary<string, object>
CompletionSources = new ConcurrentDictionary<string, object>();
private static TaskCompletionSource<T> GetCreateSource<T>(string key)
{
var fullKey = $"{typeof(T).FullName}:{key}";
if (CompletionSources.ContainsKey(fullKey) && CompletionSources.TryGetValue(fullKey, out var returnValue))
return (TaskCompletionSource<T>) returnValue;
@Warrenn
Warrenn / EventAwaiter.cs
Created April 29, 2022 20:55
await events using Task
namespace Auto_Invest;
public static class EventAwaiter
{
public class EventArg<T>
{
public T? Args { get; set; }
public object? Sender { get; set; }
}
cat <<'EOF' > $IBEAM_GATEWAY_DIR/san.tmpl
[req]
default_bits = 2048
distinguished_name = req_distinguished_name
req_extensions = req_ext
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
cat <<'EOF' > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent-schema.tmpl
{
"agent": {
"run_as_user": "root"
},
"logs": {
"logs_collected": {
"files": {
"collect_list": [
{
$images=$(docker ps);$imageid=$images[1].Split(' ')[0];docker kill $imageid
S3Bucket:
Type: 'AWS::S3::Bucket'
Properties:
BucketEncryption:
ServerSideEncryptionConfiguration:
- ServerSideEncryptionByDefault:
SSEAlgorithm: AES256
BucketName:
Fn::Join:
- "-"