Skip to content

Instantly share code, notes, and snippets.

View robertsosinski's full-sized avatar

Robert Sosinski robertsosinski

View GitHub Profile
@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 / daily.sh
Created April 30, 2012 01:41
PostgreSQL Backup Scripts
#!/bin/bash
filepath="/data/postgresql/9.1/main-backups"
cd $filepath
for database in `ls $filepath/daily`; do
filename=`date +"$filepath/daily/$database/$database-daily-%w-%a.dmp" | tr '[:upper:]' '[:lower:]'`
if [ -e $filename ]; then
@robertsosinski
robertsosinski / Notifier.scala
Created May 20, 2014 20:21
Listening to Asynchronous Listen/Notify with Scala and Akka
package io.reactive.sandbox.actors
import java.sql.DriverManager
import org.postgresql.PGConnection
import akka.actor.{Actor, ActorLogging, ActorRef}
case class Subscription(channel: String)
case class UnSubscription(channel: String)
@robertsosinski
robertsosinski / db.rake
Created December 25, 2012 15:23
Database rake tasks for Sequel
namespace :db do
desc "Migrates the database to the target version, or to the lastest version if no target is given"
task :migrate, [:target, :current] => :environment do |t, args|
opts = {}
opts[:target] = args[:target].to_i if args[:target]
opts[:current] = args[:current].to_i if args[:current]
Sequel::Migrator.run(DB, "db/migrate", opts)
Rake::Task["db:dump"].invoke if Rails.env.development?
end
@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": [
require 'spec_helper'
describe Api::V9::Authenticatable, :type => :controller do
before do
class EndpointsController < ActionController::Base
include Api::V9::Authenticatable
def index
render :text => 'foo'
@robertsosinski
robertsosinski / varnish.vcl
Created August 29, 2011 22:53
A Varnish config for Rails
backend default {
.host = "127.0.0.1";
.port = "3000";
}
acl admin {
"127.0.0.1";
}
sub vcl_recv {
@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