Skip to content

Instantly share code, notes, and snippets.

View kvarela's full-sized avatar

Karim Varela kvarela

View GitHub Profile
@kvarela
kvarela / function.ts
Last active December 15, 2021 19:24
Sample function connecting to typeorm
import * as lambda from 'aws-lambda'
import connectionOptions from '../db/ConnectionOptions'
import { Connection } from 'typeorm'
import { Database } from '../db'
import { User } from '../entities'
import 'reflect-metadata'
import 'envkey'
exports.api = async (event: lambda.APIGatewayProxyEvent, serverlessContext: lambda.Context) => {
// This enables Lambda function to complete
import { Connection, ConnectionManager, ConnectionOptions, createConnection, getConnectionManager } from 'typeorm'
import { inspect } from 'util'
import { SnakeNamingStrategy } from './SnakeNamingStrategy'
import 'envkey'
/**
* Database manager class
*/
export class Database {
private connectionManager: ConnectionManager
# You possess bitcoins in the form of UTXOs sorted by date and you need to send your friend X bitcoins.
# Find a date range whose outputs that will result in the least amount of change.
# Ideal solution will use Python whose function find_range(utxos, x) will give back the start and end dates.
# Each utxo has value and date (in unix time)
class UTXO(object):
def __init__(self, value, date):
self.value = value
self.date = date # unix time