Skip to content

Instantly share code, notes, and snippets.

@emmanuelnk
emmanuelnk / db.py
Last active February 14, 2024 07:57
Python SQLAlchemy Basic Model, Session, DB Connection Classes
from sqlalchemy import event
import os
import logging
import sqlalchemy
import boto3
import base64
import json
from botocore.exceptions import ClientError
logger = logging.getLogger()
@emmanuelnk
emmanuelnk / init_script
Last active March 27, 2023 09:26
Install Redis Server on Amazon Linux AMI EC2
#!/bin/sh
# From - http://www.codingsteps.com/install-redis-2-6-on-amazon-ec2-linux-ami-or-centos/
#
# redis - this script starts and stops the redis-server daemon
#
# chkconfig: - 85 15
# description: Redis is a persistent key-value database
# processname: redis-server
# config: /etc/redis/redis.conf
# config: /etc/sysconfig/redis
@emmanuelnk
emmanuelnk / expose_docker_container_hostname.sh
Last active December 4, 2020 07:32
Expose docker hostname
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container-name
@emmanuelnk
emmanuelnk / getAmiID.ts
Created November 20, 2020 15:05
Get latest Amazon EC2 AMI image ID just like in the AWS EC2 quick launch console using Node.js
import * as AWS from "aws-sdk"
export const getAMIImageID = async(imageName: string): Promise<string | undefined> => {
AWS.config.update({ region: "us-west-2" })
const ec2 = new AWS.EC2()
// see https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/EC2.html#describeImages-property
const params = {
Filters: [
{
@emmanuelnk
emmanuelnk / koa-context.ts
Last active June 7, 2022 16:32
Simple Koa Context for testing in Typescript (Mocha-chai, Jest) etc
/* eslint-disable @typescript-eslint/ban-ts-comment */
// @ts-nocheck
// Ripped from https://github.com/koajs/koa/blob/master/test/helpers/context.js
// Solution courtesy of user @fl0w. See: https://github.com/koajs/koa/issues/999#issuecomment-309270599
// I've disabled type checking in this file but you are free to add types if you wish
// if you want more comprehensive Koa Context object to test stuff like Cookies etc
// then use https://www.npmjs.com/package/@shopify/jest-koa-mocks (requires Jest)
@emmanuelnk
emmanuelnk / slack_fedora_install.sh
Created November 6, 2020 11:15
Install the latest version of Slack on Linux from the Terminal
# Fedora
# If you need an international version of Slack, use this URL:
# e.g. Korean:
# https://slack.com/intl/ko-kr/downloads/instructions/fedora
wget -q https://slack.com/downloads/instructions/fedora -O - \
| tr "\t\r\n'" ' "' \
| grep -i -o '<a[^>]\+href[ ]*=[ \t]*"\(ht\|f\)tps\?:[^"]\+"' \
| sed -e 's/^.*"\([^"]\+\)".*$/\1/g' \
@emmanuelnk
emmanuelnk / docker-compose.yml
Created October 22, 2020 14:29 — forked from devzer01/docker-compose.yml
docker-compose mongodb
version: '3'
services:
database:
image: 'mongo'
container_name: 'my-mongo-container' # give your contatner a name
environment:
- MONGO_INITDB_DATABASE=your-database-name # database name you want to make
- MONGO_INITDB_ROOT_USERNAME=my-container-root-username # set your container root username
- MONGO_INITDB_ROOT_PASSWORD=secret # set your contatner root password
volumes:
@emmanuelnk
emmanuelnk / docker_docker_compose_non_root_install.md
Last active October 21, 2020 07:23
Install and use docker and docker-compose on Linux, Ubuntu without SUDO (NON-ROOT)

Are you tired of having to run docker as root? Well look no further, the solution is here. The instructions below were tested on Ubuntu 20.04

First, if you haven't already, install and enable docker:

    sudo apt update && sudo apt install docker.io --yes 
    sudo systemctl enable --now docker

Download latest docker compose (or replace latest in url with desired version number):

@emmanuelnk
emmanuelnk / ui_select_widget.sh
Created August 12, 2020 16:00
Pure BASH interactive CLI/TUI menu (single and multi-select/checkboxes)
#!/bin/bash
# CREDITS
# Author: Markus Geiger <mg@evolution515.net>
# Permission to copy and modify is granted under the Creative Commons Attribution 4.0 license
# Updated by Bluerayne: https://gist.github.com/blurayne/f63c5a8521c0eeab8e9afd8baa45c65e
# INSPIRED BY
# - https://serverfault.com/questions/144939/multi-select-menu-in-bash-script
# https://www.bughunter2k.de/blog/cursor-controlled-selectmenu-in-bash