Skip to content

Instantly share code, notes, and snippets.

@jgontrum
jgontrum / rdr-subdomain
Created September 17, 2016 09:19
Redirect a subdomain/domain to a service running on a local port.
#!/bin/bash
if [ "$#" -ne 2 ]
then
echo "Add a subdomain redirection to nginx."
echo "Usage: <subdomain> <port>"
exit 1
fi
echo "Redirecting the subdomain '$1' to local port '$2'."
@jgontrum
jgontrum / berlin.trainstations.geojson
Last active February 21, 2017 10:08 — forked from anonymous/overpass.geojson
data exported by overpass turbo
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from sys import stdin
if __name__ == '__main__':
i = 1
for line in stdin:
if not line.strip():
print()
i = 1
continue
@jgontrum
jgontrum / minimal_example.py
Created March 24, 2019 14:49
PyTorch Embedding Updates
import torch
import numpy as np
import torch.nn as nn
import itertools
corpus = [
("this is a very good sentence number one".split(), [1.0, 0.0]),
("a rather bad example".split(), [0.0, 1.0]),
("an even better sentence to use".split(), [1.0, 0.0]),
("negative sentence very short".split(), [0.0, 1.0])
@jgontrum
jgontrum / jwt_fast_api.py
Created August 29, 2019 12:21
JWT & FastAPI
import os
from typing import Dict, List, Optional
import requests
from jose import jwt, jwk
from jose.utils import base64url_decode
JWK = Dict[str, str]
JWKS = Dict[str, List[JWK]]
import boto3
import json
client = boto3.client('events')
rule = client.put_rule(
Name="MyRuleId",
ScheduleExpression="rate(2 minutes)",
State="ENABLED"
)
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
},
rule = client.put_rule(
Name="MyRuleId",
ScheduleExpression="rate(2 minutes)",
State="ENABLED",
RoleArn="MyRoleARN"
)
lambda_client = boto3.client('lambda')
lambda_client.add_permission(
FunctionName="MyLambdaFunctionARN",
StatementId="IUseTheSameHereAsTheRuleIdButYouDoAsYouPlease",
Action="lambda:InvokeFunction",
Principal="events.amazonaws.com",
SourceArn=rule["RuleArn"]
)
import boto3
import json
client = boto3.client('events')
lambda_client = boto3.client('lambda')
def add_schedule():
rule = client.put_rule(
Name="MyRuleId",
ScheduleExpression="rate(2 minutes)",