Skip to content

Instantly share code, notes, and snippets.

View khaliqgant's full-sized avatar
💯
👨🏿‍💻

Khaliq khaliqgant

💯
👨🏿‍💻
View GitHub Profile
@khaliqgant
khaliqgant / debug.hcl
Created March 29, 2022 11:48
[Terraform Debug] Debug Flag #terraform #infrastructure
TF_LOG=TRACE terraform foo
https://www.terraform.io/internals/debugging
@khaliqgant
khaliqgant / for_each.hcl
Created March 29, 2022 11:47
[Terraform Output] Output from for_each #terraform #infrastructure
# object
output "repo_ids" {
value = {
for idx,repo in aws_ecr_repository.repo : idx => repo.registry_id
}
}
# list
output elastic_ips {
value = [for eip in aws_eip.eip : eip.id]
@khaliqgant
khaliqgant / tuple.hcl
Created March 29, 2022 11:46
[Terraform Tuple->Set] Convert a tuple to a set #terraform #infrastructure
resource "aws_network_interface" "subnets" {
for_each = { for subnet in module.vpc.public_subnets : subnet.id => subnet }
subnet_id = each.value.key
}
// reference: https://selleo.com/til/posts/cnfrqv1ipl-foreach-over-tuples-in-terraform
@khaliqgant
khaliqgant / tmpl.hcl
Last active March 29, 2022 11:47
[Terraform Template File] Template file with variables #terraform #infrastructure
data "template_file" "codebuild" {
template = file("${path.module}/policies/role-policy.json")
vars = {
aws_s3_bucket_arn = module.aws_s3_bucket.arn[0]
}
}
role-policy.json
@khaliqgant
khaliqgant / ternary.hcl
Created March 29, 2022 11:45
[Terraform Multi Line Ternary] Ternary condition that spans multiple lines #terraform #infrastructure
locals {
iam_access_creds = (
var.create ?
var.create_livewire_accesser ?
[module.iam[0].access_key_id, module.iam[0].access_key_secret, module.iam-restriction[0].access_key_id, module.iam-restriction[0].access_key_secret] :
[module.iam[0].access_key_id, module.iam[0].access_key_secret] :
[]
)
}
@khaliqgant
khaliqgant / like.sql
Created March 16, 2022 08:50
[Postgres Like Query] Text matching using like #postgres #database
username LIKE '%zveer%'
https://www.tutorialspoint.com/postgresql/postgresql_like_clause.htm
@khaliqgant
khaliqgant / json.sql
Created March 16, 2022 08:48
[Postgres Dump A Table As JSON] Dump a table in JSON format #postgres #database
\t
\a
\o data.json
select json_agg(t) FROM (SELECT * from schedules_required_shifts) t;
// https://dba.stackexchange.com/questions/90482/export-postgres-table-as-json
@khaliqgant
khaliqgant / dump.sql
Last active March 16, 2022 09:10
[Postgres Create Dump & Restore] Fast way to create a postgres dump #postgres #database
# dump
pg_dump -h localhost -U postgres -p 5432 -Fc -Z 9 --file=local.dump
# restore
pg_restore -h localhost -U postgres -Fc -j 8 -p 5432 -vvv -d postgres local.dump
# source: https://stackoverflow.com/questions/15692508/a-faster-way-to-copy-a-postgresql-database-or-the-best-way
@khaliqgant
khaliqgant / drop_db.sql
Last active August 3, 2022 20:21
[Postgres Drop Database] Drop live database and create public schema #postgres #database
# with auth
> psql -h 10.000.0.0 -d mydb -U myuser
> psql postgres postgres
drop schema public cascade;
create schema public;
\q and enter to exit
@khaliqgant
khaliqgant / 1_overlap.js
Last active March 16, 2022 08:52 — forked from mxriverlynn/1_overlap.js
[Date Range Overlap] checking for date range overlap #javascript
// this function takes an array of date ranges in this format:
// [{ start: Date, end: Date}]
// the array is first sorted, and then checked for any overlap
function overlap(dateRanges){
var sortedRanges = dateRanges.sort((previous, current) => {
// get the start date from previous and current
var previousTime = previous.start.getTime();
var currentTime = current.start.getTime();