Skip to content

Instantly share code, notes, and snippets.

View thebeebs's full-sized avatar
🏠
Working from home

Martin Beeby thebeebs

🏠
Working from home
View GitHub Profile
@thebeebs
thebeebs / AsyncExample.js
Last active September 15, 2020 19:41
An example of using Async Await to create some text in a guaranteed order.
// Calling the function using promises.
addElement("first promise sexy syntax")
.then(x => addElement("second promise syntax"))
.then(x => addElement("third promise syntax"))
.then(x => addElement("fourth promise syntax"))
// Calling the function using Async/Await
async function myFunction(){
await addElement("first async");
await addElement("second async");
@thebeebs
thebeebs / webAudio.js
Created December 20, 2016 14:16
Web Audio Example
var context= new (window.AudioContext || window.webkitAudioContext)();
var oscillator = context.createOscillator();
oscillator.frequency.value = 5000;
oscillator.start();
oscillator.connect(context.destination);
// Only be heard by those under 40
// oscillator.frequency.value = 15000;
// Only be heard by those under 18
<div id="app">
<button @click="disconnect" v-if="status === 'connected'">Disconnects </button>
<button @click="connect" v-if="status === 'disconnected'">Connect</button> {{ status }}
<br /><br />
<div v-if="status === 'connected'">
<form @submit.prevent="sendMessage" action="#">
<input v-model="message"><button type="submit">Send Message</button>
</form>
<ul id="logs">
<li v-for="log in logs" class="log">
@thebeebs
thebeebs / s3.cs
Created August 12, 2019 20:49
The following C# code example creates two objects with two PutObjectRequest requests: The first PutObjectRequest request saves a text string as sample object data. It also specifies the bucket and object key names. The second PutObjectRequest request uploads a file by specifing the file name. This request also specifies the ContentType header an…
using Amazon.S3;
using Amazon.S3.Model;
using System;
using System.Threading.Tasks;
namespace Amazon.DocSamples.S3
{
class UploadObjectTest
{
private const string bucketName = "*** bucket name ***";
@thebeebs
thebeebs / cdk-bucket.cs
Created August 12, 2019 21:03
Creating a bucket using the CDK
new Bucket(this, "MyFirstBucket", new BucketProps
{
Versioned = true
});
@thebeebs
thebeebs / lambda.cs
Created August 12, 2019 21:21
Simple Lambda Example
using Amazon.Lambda.Core;
// Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.
[assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
namespace demoLambda
{
public class Function
{
@thebeebs
thebeebs / gist:6f9af41001df66c606be102fd349a8bf
Last active September 3, 2019 14:29
PowerShell Commands
Install-Module AWSLambdaPSCore -Scope CurrentUser
Get-AWSPowerShellLambdaTemplate
New-AWSPowerShellLambda -ScriptName RDPLockDown -Template Basic
Publish-AWSPowerShellLambda -ScriptPath .\RDPLockDown.ps1 -Name RDPLockDown -Region us-east-1
@thebeebs
thebeebs / gist:14163a865788eb0ded1dedb12b8f9877
Created September 3, 2019 14:15
PowerShell Lambda Script
#Requires -Modules @{ModuleName='AWSPowerShell.NetCore';ModuleVersion='3.3.343.0'}
$rulesRemoved = 0
Get-EC2SecurityGroup | ForEach-Object -Process {
$securityGroupId = $_.GroupId
$_.IpPermission | ForEach-Object -Process {
if($_.ToPort -eq 3389) {
@thebeebs
thebeebs / S0-60207104
Created March 4, 2020 21:29
A solution to the questiond 60207104 on stack overflow.
static void Main(string[] args)
{
var prog = new Program();
prog.MainAsync().Wait();
}
private async Task MainAsync()
{
var kmsClient = new AmazonKeyManagementServiceClient(RegionEndpoint.EUCentral1);
@thebeebs
thebeebs / InjectDelayPolicy.cs
Last active May 21, 2020 15:59
Embarrassing
private static async Task<T> WrapAsync<T>(Func<object[], object> target, object[] args, string name)
{
try
{
return await new ChaosWrap<InjectException>().Execute<T>(() => (Task<T>) target(args));
}
catch (Exception e)
{
Console.WriteLine($"Async method `{name}` throws {e.GetType()} exception.");
return default;