Skip to content

Instantly share code, notes, and snippets.

@samkeen
samkeen / ec2-instance-subnet-id.md
Last active January 23, 2024 17:07
Get the subnet and VPC id of a running EC2 instance

First get the Interface mac address, then use that to run the full command

INTERFACE=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/)
SUBNET_ID=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/subnet-id)
VPC_ID=$(curl --silent http://169.254.169.254/latest/meta-data/network/interfaces/macs/${INTERFACE}/vpc-id)

echo SUBNET_ID
# Supply a custom prompt to a LangChain QA Chain
system_template = """Use the following pieces of context to answer the question at the end. If you don't know the answer, just say that you don't know, don't try to make up an answer.
{context}
Question: {question}
Helpful Answer:"""
messages = [
SystemMessagePromptTemplate.from_template(system_template),
HumanMessagePromptTemplate.from_template("{question}"),
import boto3
# This code deletes buckets on AWS S3.
# It is designed to be run on a local machine with credentials for an AWS account that has the
# necessary permissions to delete buckets.
# It will delete the contents of the buckets before deleting the bucket itself.
# It will not attempt to delete a bucket that does not exist.
# BUCKETS is a list of bucket names that should be deleted. If a bucket in the list does not
# exist, it will be skipped.
@samkeen
samkeen / logger.py
Created March 13, 2020 22:02 — forked from impredicative/logger.py
Python json logging using structlog and stdlib logging
"""
Usage example:
from logger import get_logger
log = get_logger()
log.info('my_event', my_key1='val 1', my_key2=5, my_key3=[1, 2, 3], my_key4={'a': 1, 'b': 2})
List of metadata keys in each log message:
event
_func
Ec2InPrivateSubnetWithouttNatGtwy:
Type: AWS::EC2::Instance
Properties:
ImageId: !Ref LatestAmiId
InstanceType: !Ref InstanceType
# KeyName: NO SSH Key needed
IamInstanceProfile: !Ref Ec2InstanceProfile
NetworkInterfaces:
# The SSM Agent running on the EC2 instances must be able to connect to Session Manager's
# public endpoint. You can also set up a PrivateLink connection to allow instances running
@samkeen
samkeen / TestingCodeigniter.md
Created August 12, 2011 14:54
Article describing how to test Codeigniter apps

(Integration) Test Infecting Codeigniter

Intro

This is not an article on the theoretical proper way to implement a testing policy and/or infrastructure. This is much more real world than that. This is about finding yourself in a situation were you need to refactor or add features to an existing substantial code base. Before undertaking such an adventure you would like to lay down some tests for regression purposes. The hitch is that the code is in a framework that hasn't put testing support first.

Many PHP frameworks qualify for the statement above but the one we will talk about in this article is Codeigniter. I wont use this article to debate the quality of the Codeigniter code base. It is what it is and finds itself used for a very many (in production) websites. What this article is about is addressing the situation that there are many developers out there that may find themselves working on a product utilizing a framework such as Codeigniter

@samkeen
samkeen / git-svn-workflow.md
Last active April 17, 2019 07:33
git svn workflow

Clone

# -s is there to signify that my Subversion repository has a standard layout (trunk/, branches/, and tags/)
$ git-svn clone -s http://example.com/my_subversion_repo local_dir

Gitignore

# check in strategy
$ git svn show-ignore > .gitignore

just local strategy

env:
variables:
LAMBDA_PKG_BUCKET_PREFIX: mia
phases:
install:
commands:
@samkeen
samkeen / vpc-with-NAT-gateway-bastion-host.template.json
Last active June 22, 2018 14:20
Same as lean version, but with NAT Gateway and Bastion host
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "VPC Across 3 AZs",
"Parameters": {
"EnvName": {
"Type": "String",
"Default": "Dev",
"AllowedValues": [
"Dev", "Test", "Prod"
],