Skip to content

Instantly share code, notes, and snippets.

View onelharrison's full-sized avatar

Onel Harrison onelharrison

View GitHub Profile
@onelharrison
onelharrison / anonymous_functions.py
Last active July 7, 2022 22:54
Code snippet showing the use of anonymous functions in Python
from collections import namedtuple
Person = namedtuple("Person", ["name", "age"])
if __name__ == "__main__":
people = [
Person("Marie Curie", 66),
Person("Katherine Johnson", 101),
Person("Ada Lovelace", 36),
]
@onelharrison
onelharrison / pure_vs_impure_functions.py
Last active July 8, 2022 16:28
Code snippet showing pure vs impure functions in Python
def strip_pure(sentence: str) -> str:
return sentence.strip()
strip_impure_call_count = 0
def strip_impure(sentence: str) -> str:
global strip_impure_call_count
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.0"
}
}
}
provider "aws" {
variable "env_name" {
description = "Environment name"
}
locals {
function_name = "text_scrambler"
function_handler = "main.handler"
function_runtime = "python3.9"
function_timeout_in_seconds = 5
import json
import random
def scramble(text: str) -> str:
return "".join(random.sample(text, len(text)))
def handler(event, context):
return {
"""
An oversimplified implementation of the Python interface for Redis
"""
class Redis:
def __init__(self, db=0):
self.db = db
self.data = {self.db: {}}
def get(self, key):
"""Gets the value associated with a key"""
return self.data.get(self.db, {}).get(key)
import redisx
r = redisx.Redis(db=1)
r.set('hello', 'world') # True
value = r.get('hello')
print(value) # 'world'
r.delete('hello') # True
print(r.get('hello')) # None
import redis
import time
# Establish a connection to the Redis database 1 at
# redis://localhost:6379
r = redis.Redis(host='localhost', port=6379, db=1)
# SET hello world
r.set('hello', 'world') # True
# GET hello
world = r.get('hello')
print(world.decode()) # "world"
name: Release
on:
push:
branches:
- main
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
import json
from faker import Faker
fake = Faker()
def handler(event, context):
return {
"statusCode": 200,
"headers": {"Content-Type": "application/json"},