Skip to content

Instantly share code, notes, and snippets.

@k-k
k-k / s2a_auth.sh
Last active March 11, 2021 20:00
Wraps commands dependent on STS Tokens through a function using saml2aws, automatically refreshing the session token
# This function can be added to your bash or zsh rc file - then you setup aliases for
# commonly used tools which rely on AWS session tokens to be refreshed through saml2aws.
s2a_auth() {
yellow=`tput setaf 3`
reset=`tput sgr0`
now_minus_5=$(date -v "-5M" +"%Y-%m-%dT%T%z")
exp_date=$(awk -F "=" '/x_security_token_expires/ {print $2}' ~/.aws/credentials | tr -d ' ')
# If a date is not found or there is less than 5 minutes before expiration, re-auth.
@k-k
k-k / tfw_bash.sh
Last active September 2, 2020 17:54
Bash function to shorten interactions with Terraform Workspaces from the command line.
## The commands for working with terraform workspaces can be a little verbose, this just makes it easier to interact
## with the workspaces commands. It relies on `getops`, @see: https://wiki.bash-hackers.org/howto/getopts_tutorial
##
## This function can be added to your .bashrc or .zshrc.
tfw() {
# when no workspace is given, it's expected we're listing
if [ -z "$1" ]; then
terraform workspace list
return $?
@k-k
k-k / keybase.md
Created September 15, 2016 22:49

Keybase proof

I hereby claim:

  • I am kmfk on github.
  • I am kmfk (https://keybase.io/kmfk) on keybase.
  • I have a public key ASDOJCqgmXcAhSSjZjuePEXoj5qdbCkr28d0MtNwmP35TQo

To claim this, I am signing this object:

@k-k
k-k / _before_reindex.js
Last active December 23, 2015 23:19
Large difference in index size when indexes are built incrementally ( as new documents come in ) - versus built at once ( ensureIndex, reIndex, repairDatabase ).
/*
SERVER: MongoDB 2.4.3
NS: test.session
*/
/* AFTER INSERTING 20k DOCUMENTS */
db.session.stats(1024)
{
"ns": "test.session",
"count": 20130,
@k-k
k-k / MongoClient_Test.php
Created September 24, 2013 21:44
Quick test to confirm that two instances of MongoClient to separate hosts but using the same replicaSet will direct all queries to the cluster which was first instantiated.
<?php
echo "<pre>";
echo " ######### Both instances connect to the same set of servers: \n\n";
$mc1 = new MongoClient('mongodb://rs1.example.com,rs2.example.com,rs3.example.com', [ 'replicaSet' => 'my_set' ] );
$mc2 = new MongoClient('mongodb://rep1.example.com,rep2.example.com,rep3.example.com', [ 'replicaSet' => 'my_set' ] );
echo " ######### MongoClient - ReplicaSet 1: \n";
print_r( $mc1->listDBs() ); // Shows the correct Dbs
@k-k
k-k / datetomongo
Created June 12, 2013 18:25
Creates a linux command to quickly convert a date time string into an ObjectId string.
#!/usr/bin/env php
<?php
echo str_pad( dechex( strtotime( $argv[1] ) ), 8, "0", STR_PAD_LEFT ) . "0000000000000000\n";