Skip to content

Instantly share code, notes, and snippets.

@hmshwt
hmshwt / script.sh
Created November 21, 2020 14:25 — forked from vielhuber/script.sh
PostgreSQL: Backup and restore pg_dump with password on command line #sql
# best practice: linux
nano ~/.pgpass
*:5432:*:username:password
chmod 0600 ~/.pgpass
# best practice: windows
edit %APPDATA%\postgresql\pgpass.conf
*:5432:*:username:password
# linux
@hmshwt
hmshwt / sshd_config
Created August 5, 2020 14:30 — forked from Tristor/sshd_config
Hardened SSH Server Config 03/2016
# TCP port to bind to
# Change to a high/odd port if this server is exposed to the internet directly
Port 22
# Bind to all interfaces (change to specific interface if needed)
ListenAddress 0.0.0.0
# Force SSHv2 Protocol
Protocol 2
@hmshwt
hmshwt / app.js
Created August 4, 2020 20:02 — forked from thofnar/app.js
// General Requires
var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
// Database Requires
var mongo = require('mongodb');
var monk = require('monk');
var dbConfig = require('./db.js');
Rank Type Prefix/Suffix
1. Prefix my+
2. Suffix +online
3. Prefix the+
4. Suffix +web
5. Suffix +media
6. Prefix web+
7. Suffix +world
8. Suffix +net
9. Prefix go+
import cv2
import numpy as np
#from skimage.measure import compare_ssim
from skimage.metrics import structural_similarity
import click
@click.command()
@click.option("-o" , "--output" , default = None , type=str , help = "Output File")
@click.argument("image1" , type = str)
@hmshwt
hmshwt / 2fa
Created April 3, 2020 12:22 — forked from MineRobber9000/2fa
2-factor authentication terminal app in Python
#!/usr/bin/env python
import os, os.path, stat, sys, base64
# TOTP lib inlined
import time, hmac, base64, hashlib, struct
def pack_counter(t):
return struct.pack(">Q", t)
@hmshwt
hmshwt / policy.md
Created December 19, 2018 13:21 — forked from pgolding/policy.md
s3 bucket policy for presigned URLs generated by serverless lambda functions

AWS Presigned URLs

Presigned URLs are useful for fine-grained access control to resources on s3.

For example, if storing larger text blocks than DynamoDB might allow with its 400KB size limits s3 is a useful option.

Ignoring various ACL methods and using presigned URLs, it's possible to create lambda functions that can generate the required upload and download URLs.

Using the default IAM roles and lambda proxy configuration of serverless, lambdas are assigned an IAM role for the application (so that a logical group of functions can share resources - e.g. for a CRUD REST API). Each function then assumes the IAM role via its own function name.

@hmshwt
hmshwt / datadog-iam-stack.yml
Created October 25, 2018 20:48 — forked from evnm/datadog-iam-stack.yml
A CloudFormation template describing an IAM policy+role pair which grants cross-account read access for monitoring AWS infrastructure in Datadog
---
AWSTemplateFormatVersion: "2010-09-09"
Description: Creates a stack containing an IAM role used to grant
Datadog monitoring access to AWS infrastructures. See
http://docs.datadoghq.com/integrations/aws/#installation for
details.
Parameters:
DatadogAwsAccountId:
@hmshwt
hmshwt / postgres-json-cheatsheet.md
Created July 15, 2018 13:17 — forked from rmtsrc/postgres-json-cheatsheet.md
Using JSON in Postgres by example

PostgreSQL JSON Cheatsheet

Using JSON in Postgres by example.

Quick setup via Docker

  1. Download and install: Docker Toolbox
  2. Open Docker Quickstart Terminal
  3. Start a new postgres container:
    docker run --name my-postgres -e POSTGRES_PASSWORD=mysecretpassword -d postgres
@hmshwt
hmshwt / setup.sh
Last active July 11, 2018 13:21 — forked from r00k/setup.sh
#!/bin/sh
# Set up Rails app. Run this script immediately after cloning the codebase.
# Exit if any subcommand fails
set -e
# Copy over configs
if ! [ -f .env ]; then
cp .sample.env .env