Skip to content

Instantly share code, notes, and snippets.

@kencoba
kencoba / 01_IAMRole.yml
Created September 22, 2024 08:04
AWS CloudFormation template that create an IAM Role and an InstanceProfile for Session Manager
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template to create an IAM Role and Instance Profile for EC2 to connect with AWS Systems Manager (Session Manager).
Parameters:
RoleName:
Type: String
Description: Name of the IAM Role for SSM Session Manager.
Default: SSMRoleForEC2 # You can change the default value or provide it during stack creation
InstanceProfileName:
@kencoba
kencoba / 04_EC2_docker.yml
Created September 22, 2024 08:01
AWS CloudFormation template that launch EC2 instance with Docker.
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template to launch an EC2 instance with User Data, using Instance Profile for SSM Session Manager access.
Parameters:
Prefix:
Type: String
Default: MyApp
Description: Prefix for all resource names
InstanceType:
@kencoba
kencoba / 03_SecurityGroup.yml
Created September 22, 2024 07:59
AWS CloudFormation template that create a Security Group.
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template to create a Security Group allowing inbound traffic on port 3306 for MariaDB.
Parameters:
VpcId:
Type: AWS::EC2::VPC::Id
Description: VPC ID to create the security group in.
Prefix:
Type: String
Default: MyApp
@kencoba
kencoba / 02_VPC.yml
Created September 22, 2024 07:58
AWS CloudFormation template that create a VPC with a public subnet and a private subnet.
AWSTemplateFormatVersion: '2010-09-09'
Description: CloudFormation template to create a VPC with one public subnet and one private subnet, with customizable CIDR blocks and a common prefix for all resource names.
Parameters:
VpcCidr:
Type: String
Default: 10.0.0.0/16
Description: CIDR block for the VPC
PublicSubnetCidr:
Type: String
@kencoba
kencoba / PatternsOfTransactions.java
Created August 15, 2024 02:52
Cover all patterns of transactions.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
/**
*
* Cover all patterns of transactions.
*
* @author kencoba
@kencoba
kencoba / ProofsOnBooks.v
Created March 19, 2024 08:46
Sample proofs from books.
(* 新妻弘,「演習 群・環・体 入門」,共立出版株式会社 より *)
Require Import ZArith.
Open Scope Z_scope.
Theorem thm_1_1 : forall a b c : Z , a + b = a + c -> b = c.
Proof.
intros a b c H.
apply Z.add_cancel_l with (p := a).
assumption.
Qed.
@kencoba
kencoba / CounterServlet.java
Created June 3, 2023 11:40
A sample servlet for understanding between a request and a sesson.
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
@kencoba
kencoba / trans.rb
Created October 16, 2020 09:50
Transaction simulator with Ruby
class Request
end
class Read < Request
attr_reader :var
def initialize(var)
@var = var
end
@kencoba
kencoba / trans.py
Created October 16, 2020 09:50
Transaction simulator with Python.
class Request:
pass
class Read(Request):
def __init__(self, var):
self.var = var
class Write(Request):
@kencoba
kencoba / main.rs
Created September 29, 2020 01:36
A translation from Ruby to Rust in the book :pp.018-020[「もっとプログラマ脳を鍛える数学パズル」](https://www.shoeisha.co.jp/book/detail/9784798153612)
fn main() {
println!("{n}P{r} = {x}", n = 5, r = 2, x = permutation(5, 2));
println!("{n}C{r} = {x}", n = 5, r = 2, x = combination(5, 2));
}
pub fn permutation(n: i64, r: i64) -> i64 {
let mut result = 1;
for i in (n - r + 1)..=n {
result *= i;
}