Skip to content

Instantly share code, notes, and snippets.

View zulrang's full-sized avatar

Roger Collins zulrang

View GitHub Profile
@zulrang
zulrang / dynamo_async_writer.py
Last active January 8, 2024 23:57
Async DynamoDB Batch Writer using aioboto3 (typed)
import aioboto3
from types_aiobotocore_dynamodb.service_resource import Table
class DynamoDBBatchWriter:
"""
A class that batches up to 25 writes to DynamoDB. Flushes automatically when the batch reaches 25 items,
5 seconds pass, or when the `flush()` method is called.
This class is not thread-safe.
@zulrang
zulrang / gochan.py
Last active December 28, 2023 21:18
Simulating Goroutine and Channel functionality in Python
import asyncio
from typing import Any, AsyncGenerator, Coroutine, Generator, Never
class Channel:
def __init__(self, maxsize: int = 0):
self._queue: asyncio.Queue = asyncio.Queue(maxsize=maxsize)
async def push(self, item):
return await self._queue.put(item)
Thu May 7 15:18:29 UTC 2020
#!/usr/bin/python.exe -u
import subprocess
import boto3
# constants
INSTANCE_NAME = 'Development'
SSHFS_CMD = '/usr/bin/sshfs'
MOUNT_POINT = '/awsec2'
@zulrang
zulrang / devssh.py (Windows)
Last active March 16, 2018 01:43
"Cloud9" with local editor, terminal, and file system
#!/usr/bin/python.exe -u
import subprocess
import boto3
# constants
INSTANCE_NAME = 'Development'
SSHFS_CMD = 'C:/Tools/sshfs/sshfs.exe'
PRIVATE_KEY_FILE = 'C:/Certs/aws.pem'
DRIVE_LETTER = 'n'
function getMiddle(s){
var m = s.length / 2
return s.slice(m - 1 + s.length % 2, m + 1)
}
function flatten(arr) {
var result = [];
// iterate through array
for(var i = 0; i < arr.length; i++) {
// check if number or array
if(typeof arr[i] === "object") {
// push values of array recursively
Array.prototype.push.apply(result, flatten(arr[i]));
} else if (typeof arr[i] === "number") {
// push number to end of array
@zulrang
zulrang / RestControllerTrait.php
Created December 31, 2015 17:57 — forked from beanmoss/RestControllerTrait.php
Playing with Laravel Lumen: simple RESTful trait.
<?php namespace App\Http\Controllers;
use Illuminate\Http\Request;
trait RestControllerTrait
{
public function index()
{
$m = self::MODEL;
return $this->listResponse($m::all());