Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Awake or Sleeping

Michael Bunsen mihow

💭
Awake or Sleeping
View GitHub Profile
@ian-whitestone
ian-whitestone / zappa_package_cleaner.py
Last active Sep 8, 2021
Remove additional files and/or directories from Zappa deployment package via zip callback https://ianwhitestone.work/Zappa-Zip-Callbacks/
View zappa_package_cleaner.py
"""
Read accompanying blog post: https://ianwhitestone.work/Zappa-Zip-Callbacks
"""
import os
import re
import shutil
import tarfile
import zipfile
@DWboutin
DWboutin / directUploadToS3.js
Created Mar 31, 2019
Direct image url to S3 wiht axios and nodejs
View directUploadToS3.js
import AWS from 'aws-sdk';
import stream from 'stream'
import axios from 'axios';
export default async (url, filename, callback) => {
const s3 = new AWS.S3({ params: { Bucket: process.env.STATIC_MAPS_BUCKET }});
let contentType = 'application/octet-stream'
let promise = null
const uploadStream = () => {
@picadoh
picadoh / cloudwatch.tf
Last active Nov 5, 2021
EC2 Instance Scheduling (Stop/Start) with Terraform
View cloudwatch.tf
### Cloudwatch Events ###
# Event rule: Runs at 8pm during working days
resource "aws_cloudwatch_event_rule" "start_instances_event_rule" {
name = "start_instances_event_rule"
description = "Starts stopped EC2 instances"
schedule_expression = "cron(0 8 ? * MON-FRI *)"
depends_on = ["aws_lambda_function.ec2_start_scheduler_lambda"]
}
# Runs at 8am during working days
@jeffjohnson9046
jeffjohnson9046 / kill-all-connections-to-db.sql
Created Jun 18, 2018
How to kill all connections to a Postgres database
View kill-all-connections-to-db.sql
-- Accepted answer from here: https://stackoverflow.com/questions/5408156/how-to-drop-a-postgresql-database-if-there-are-active-connections-to-it
SELECT pg_terminate_backend(pg_stat_activity.pid)
FROM pg_stat_activity
WHERE pg_stat_activity.datname = '[your database name goes here]'
AND pid <> pg_backend_pid();
@denniswebb
denniswebb / swagger-ui.tf
Created Oct 11, 2016
Terraform template for deploying Swagger-UI to S3 website.
View swagger-ui.tf
variable "region" {default = "us-west-2"}
variable "website_dns" {default = "swagger-ui.webblab.info"}
variable "r53_zone_id" {default = "Z1S59LUERGUH56"}
variable "swagger_ui_version" {default = "v2.2.5"}
provider "aws" {
region = "${var.region}"
}
resource "aws_s3_bucket" "main" {
@DeveloperPaul123
DeveloperPaul123 / DMX_ETH_17_Motor.cpp
Created Sep 19, 2016
Arcus Ethernet Motor Class based on QT
View DMX_ETH_17_Motor.cpp
/**
* Constructor. Miscellaneous initilization of some variables.
*/
DMX_ETH_17_Motor::DMX_ETH_17_Motor() {
isConnected = false;
mSocket = new QTcpSocket();
}
/**
* Returns whether or not the motor is connected.
@raprasad
raprasad / test_unmanaged_models.md
Last active Nov 18, 2021
Ignoring migrations during Django testing (unmanaged databases, legacy databases, etc)
View test_unmanaged_models.md

Scenario

  • Django 1.9 application with two databases:
    • Legacy database with readonly access via unmanaged models. Both Django models (models.py) and related migrations have "managed" set to False
      • 'managed': False
    • Default database holding django specific tables (e.g. auth_user, django_content_type, etc)

Testing Woes

@dahjelle
dahjelle / pre-commit.sh
Created Jul 13, 2016
Pre-commit hook for eslint, linting *only* staged changes.
View pre-commit.sh
#!/bin/bash
for file in $(git diff --cached --name-only | grep -E '\.(js|jsx)$')
do
git show ":$file" | node_modules/.bin/eslint --stdin --stdin-filename "$file" # we only want to lint the staged changes, not any un-staged changes
if [ $? -ne 0 ]; then
echo "ESLint failed on staged file '$file'. Please check your code and try again. You can run ESLint manually via npm run eslint."
exit 1 # exit with failure status
fi
done
@awesomebytes
awesomebytes / reduce_faces.py
Created Apr 6, 2016
Executing meshlab from commandline reduce faces of a mesh iteratively
View reduce_faces.py
#!/usr/bin/env python
import sys
import os
import subprocess
# Script taken from doing the needed operation
# (Filters > Remeshing, Simplification and Reconstruction >
# Quadric Edge Collapse Decimation, with parameters:
# 0.9 percentage reduction (10%), 0.3 Quality threshold (70%)
@syafiqfaiz
syafiqfaiz / how-to-copy-aws-rds-to-local.md
Last active Nov 16, 2021
How to copy production database on AWS RDS(postgresql) to local development database.
View how-to-copy-aws-rds-to-local.md
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
    • the database is restored