Skip to content

Instantly share code, notes, and snippets.

View svenvarkel's full-sized avatar

Sven Varkel svenvarkel

View GitHub Profile
@svenvarkel
svenvarkel / gist:1936f343eb20a90fc94abc1cc2c4e0e5
Created October 25, 2023 07:49
BeanieInfiniteRecursionTestCase
import asyncio
import unittest
from enum import Enum
from datetime import datetime, UTC
from typing import ClassVar, Optional, List
from pymongo import IndexModel, ASCENDING
from pydantic import BaseModel, Field, Extra
from beanie import Document, BackLink, Link, init_beanie
@svenvarkel
svenvarkel / create_indexes.js
Created January 20, 2021 09:37
Create indexes on MongoDB replica set member
#!/usr/bin/env bash
if [ -z "$1" ];
then
echo "Usage: $0 <index file path>"
exit 1
fi
export INDEX_FILE="$1"
systemctl stop mongod
su mongodb --shell /bin/bash -c 'mongod --dbpath /mongodb/data --port 47017 --wiredTigerDirectoryForIndexes --pidfilepath=/tmp/mongod.pid &'
while ! nc -z localhost 47017 </dev/null; do sleep 5; done
@svenvarkel
svenvarkel / centroid-and-center-difference-on-a-rectangular-polygon
Last active September 27, 2019 08:21
This gist contains GeoJSON to illustrate center and centroid differences on a rectangular polygon
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"stroke": "#555555",
"stroke-width": 2,
"stroke-opacity": 1,
"fill": "#555555",
@svenvarkel
svenvarkel / Dockerfile
Created September 26, 2019 13:09
Dockerfile for SailsJS project
FROM node:10
# Set the workdir /var/www/myapp
WORKDIR /var/app/current
# Copy the package.json to workdir
COPY package.json ./
COPY package-lock.json ./
# Copy application source
COPY .sailsrc ./
@svenvarkel
svenvarkel / docker-compose.yml
Last active October 7, 2019 18:57
docker-compose stack for SailsJS API with ReactJS frontend app on top of MongoDB, Redis and Nginx
version: "3.7"
services:
rabbitmq:
image: rabbitmq:3-management
environment:
RABBITMQ_DEFAULT_VHOST: "/myproject"
RABBITMQ_DEFAULT_USER: "dev"
RABBITMQ_DEFAULT_PASS: "dev"
volumes:
- type: volume
@svenvarkel
svenvarkel / aws_ec2_nginx_certbot_autorenew.sh
Last active January 16, 2019 23:36
This script renews the LetsEncrypt certificates in a firewalled EC2 machine inside AWS VPC
#!/usr/bin/env bash
#
# This script would help to automate renewal of LetsEncrypt TLS certificates in a Linux machine
# running nginx web server on AWS EC2.
# What it does:
# 1. it stops nginx
# 2. it opens incoming firewall ports 80 and 443 for certbot host verification
# 3. it runs certbot to renew certificates. Certbot launches a standalone HTTP server on port 80 or 443
# 4. it closes incoming firewall ports 80 and 443
# 5. it starts nginx
@svenvarkel
svenvarkel / socks_on_and_off
Created January 9, 2018 11:45
Poor man's SOCKS proxy via SSH. Add the following lines to your ~/.bash_profile and then socks_on / socks_off
alias socks_on="ssh -D 8666 -C -N -f -M -S ~/.socks.socket $USER@<your_office_gateway>; networksetup -setsocksfirewallproxystate Wi-Fi on;"
alias socks_off="networksetup -setsocksfirewallproxystate Wi-Fi off; ssh -S ~/.socks.socket -O exit $USER@<your_office_gateway>;"
@svenvarkel
svenvarkel / centroid.difference.map.geojson
Last active April 6, 2017 12:10
Centroid difference
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@svenvarkel
svenvarkel / gist:0cb7d53139eb0258640c65bd4542ef6b
Last active March 29, 2017 17:20
Configure tag Name as hostname for New Relic
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/60_configure_newrelic_hostname.sh":
mode: "000755"
owner: root
group: root
content: |
#!/bin/bash
set -xe
export EC2_TAG_NAME=$(/opt/aws/bin/ec2-describe-tags --filter "resource-type=instance" --filter "resource-id=$(/opt/aws/bin/ec2-metadata -i | cut -d ' ' -f2)" --filter "key=Name" | cut -f5)
@svenvarkel
svenvarkel / usPostStreetSuffixAbbreviationMap.js
Created December 19, 2016 17:19
This gist contains US Post street suffix abbreviation map. It can be used as a part of US addresses normalization.
const suffixMap = {
"ALY": [
"ALLEE",
"ALLEY",
"ALLY",
"ALY"
],
"ANX": [
"ANEX",
"ANNEX",