Skip to content

Instantly share code, notes, and snippets.

View Ambro17's full-sized avatar
💭
Coding

Nahuel Ambrosini Ambro17

💭
Coding
  • Shiphero
  • Los Cardales, Argentina
View GitHub Profile
@hyzyla
hyzyla / app.py
Created August 27, 2020 09:44
aiohttp + strawberry + aiodataloader example
from __future__ import annotations
from aiohttp import web
from strawberry.http import process_result
import loader
import graph
routes = web.RouteTableDef()
@mgaitan
mgaitan / git-recent-branches
Last active August 23, 2024 20:01
List or checkout recently used branches in git
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
List the most recent branches you have been working on, and checkout any of them.
# Install
Put this file somewhere in your PATH, and set execution permissions.
Git will recognize it as the "recent-branches" subcommand.
@a7v8x
a7v8x / graphql_introspection_query.graphql
Last active November 5, 2023 12:36
GraphQL introspection query - for fetching the whole schema (from GraphiQL IDE) for https://atheros.ai/blog/graphql-introspection-and-introspection-queries
query IntrospectionQuery {
__schema {
queryType { name }
mutationType { name }
types {
...FullType
}
directives {
name
description
@ranrib
ranrib / event.json
Created July 10, 2018 17:19
AWS SQS event trigger to Lambda function
{
"Records": [
{
"messageId": "74140753-924c-4084-8a74-768b6a33e982",
"receiptHandle": "AQEBRb3GKquMc9HvQSh9GDZ++ETxyjxN45wtOB449zvUlUlaBmoxyhXhr5QWyVNoUyvytHvz5GFfeZq/Af4SpBYe6j85T0rYi/TA+690UXJuv3Vc/U9ql5NLHdLSmvqvsQDVXi7TWzcX0ER+",
"body": "test",
"attributes": {
"ApproximateReceiveCount": "1",
"SentTimestamp": "1531136255184",
"SenderId": "AROAJ3ZGMT746QFJO6ZL4:sqs-lambda-tutorial-production-start-lambda",
@Morreski
Morreski / timed_cache.py
Last active September 3, 2024 00:29
Python lru_cache with timeout
from datetime import datetime, timedelta
import functools
def timed_cache(**timedelta_kwargs):
def _wrapper(f):
update_delta = timedelta(**timedelta_kwargs)
next_update = datetime.utcnow() + update_delta
# Apply @lru_cache to f with no cache size limit
@romaninsh
romaninsh / lambda-vpc-internet-access-cloudformation.yml
Last active December 22, 2021 00:26
CloudFormation template implementing Private network which can be used by Serverless to deploy Lambda into VPCs an maintaining internet access
# Add the following to your existing VPC CF stack
# create 2 subnets, lambdas like to be in multiple subnets
Private1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
CidrBlock: !Ref Private1CIDR

How to setup AWS lambda function to talk to the internet and VPC

I'm going to walk you through the steps for setting up a AWS Lambda to talk to the internet and a VPC. Let's dive in.

So it might be really unintuitive at first but lambda functions have three states.

  1. No VPC, where it can talk openly to the web, but can't talk to any of your AWS services.
  2. VPC, the default setting where the lambda function can talk to your AWS services but can't talk to the web.
  3. VPC with NAT, The best of both worlds, AWS services and web.
@cwurld
cwurld / quickstart.py
Created January 11, 2016 14:50
Google Calendar Python API with Freebusy
"""
Mostly the Google quickstart.py code with the "freebusy" service running.
Also shows how to make datetimes using pytz.
Follow these instructions to get access credentials:
https://developers.google.com/google-apps/calendar/quickstart/python
"""
@hodgesmr
hodgesmr / hijacking_flask_routing_for_fun_and_profit.py
Last active June 18, 2024 15:22
Automatically register Flask routes with and without trailing slash. This way you avoid the 301 redirects and don't have to muddy up your blueprint with redundant rules.
"""Flask Blueprint sublcass that overrides `route`.
Automatically adds rules for endpoints with and without trailing slash.
"""
from flask import Blueprint, Flask
class BaseBlueprint(Blueprint):
"""The Flask Blueprint subclass."""
background (46, 46, 46)
comment grey (121, 121, 121)
white (214, 214, 214)
yellow (229, 181, 103)
green (180, 210, 115)
orange (232, 125, 62)
purple (158, 134, 200)
pink (176, 82, 121)
blue (108, 153, 187)