Skip to content

Instantly share code, notes, and snippets.

View robertsosinski's full-sized avatar

Robert Sosinski robertsosinski

View GitHub Profile
@robertsosinski
robertsosinski / blackjack.js
Created June 11, 2022 15:52
Blackjack Strategy
// All potential actions that can be taken
let action = [
'hit', // 0
'stand', // 1
'double', // 2
'split', // 3
'blackjack' // 4
];
// Used for hard hands, when the player hand does not have an Ace (11)
-- 1. must be between 3 and 20 characters,
-- 2. must be only:
-- a. lowercase letters,
-- b. numbers,
-- c. individual dashes.
-- 3. must start with a letter,
-- 4. must not end with a dash.
'^[a-z]([-](?![-])|[a-z0-9]){1,18}[a-z0-9]$'
@robertsosinski
robertsosinski / keybase.md
Last active January 12, 2021 16:56
keybase.md

Keybase proof

I hereby claim:

  • I am robertsosinski on github.
  • I am sosinski (https://keybase.io/sosinski) on keybase.
  • I have a public key ASAPxI5BFCvyApljKvTgZLqHO2P5ae6jaG_jncmP2EI1iQo

To claim this, I am signing this object:

@robertsosinski
robertsosinski / create-encrypted-ssm-parameter.js
Created September 6, 2019 20:03
Create an encrypted SSM Parameter using a Custom Cloud Formation Resource
const aws = require("aws-sdk");
const https = require("https");
const url = require("url");
// Sends a response to the pre-signed S3 URL
function sendResponse(event, context, callback, responseStatus, responseData) {
const responseBody = JSON.stringify({
Status: responseStatus,
Reason: `See the details in CloudWatch Log Stream: ${context.logStreamName}`,
PhysicalResourceId: event.ResourceProperties.Name,
@robertsosinski
robertsosinski / stddev.sql
Created June 19, 2019 20:11
Calculating out-of-bounds values using standard deviation
with nums as (
select * from (values (18), (3), (3), (2), (4), (2), (5), (3), (12), (0.00003), (4), (2)) as n (x)
), a as (
select
stddev(nums.x) as sdev,
abs(avg(nums.x)) as aavg,
numrange(
(abs(avg(nums.x) - stddev(nums.x))),
(abs(avg(nums.x) + stddev(nums.x)))
) as bounds
@robertsosinski
robertsosinski / config.yml
Last active June 14, 2019 15:48
Example AWS Config Custom Rule Lambda
AWSTemplateFormatVersion: 2010-09-09
Description: Configure Config Rules
Resources:
ConfigS3BucketPublicReadProhibitedRule:
Type: AWS::Config::ConfigRule
Properties:
ConfigRuleName: s3-bucket-public-read-prohibited
Description: Checks that your Amazon S3 buckets do not allow public read access. The rule checks the Block Public Access settings, the bucket policy, and the bucket access control list (ACL).
MaximumExecutionFrequency: TwentyFour_Hours
@robertsosinski
robertsosinski / aws-sdk-cli-sts.js
Created May 8, 2019 21:33
AWS SDK CLI STS Usage
let fs = require("fs");
let path = require("path");
let AWS = require("aws-sdk");
let cliPath = path.resolve(process.env.HOME, ".aws", "cli");
/*
NOTES: Make sure you alias the SHA1 fingerprinted cache token to the profile name
E.G. ln -s ~/.aws/cli/cache/09a19nczc3zvza58zrftetyfso7yw9d48u6ugsel.json profile
@robertsosinski
robertsosinski / SSHKeyRole
Last active July 5, 2017 22:01
Use AWS IAM for ssh key management
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"iam:GetSSHPublicKey",
"iam:ListSSHPublicKeys"
],
"Resource": [
@robertsosinski
robertsosinski / dice.ex
Last active January 5, 2017 00:53
Functional Dice Rolling
defmodule Dice do
def sum_probability(dice, target) do
prob = :math.pow(6, dice) |> round
total = 6 * dice
"#{sum_probability(dice, target, total)} / #{prob}"
end
defp sum_probability(dice, target, _total) when target < dice do
0
@robertsosinski
robertsosinski / dice.rb
Created January 4, 2017 22:36
Dice Rolling
$odds = 0
def sumProbability(dice, target)
if dice == 1
"1 / 6"
else
prob = 6 ** dice
total = 6 * dice
if target < dice