Skip to content

Instantly share code, notes, and snippets.

@SoftwareDevPro
SoftwareDevPro / big_o_1.txt
Created September 18, 2020 00:31
Big O Notation
O(1)
O(1) describes an algorithm that will always execute in the same time (or space) regardless of the size of the input data set.
bool IsFirstElementNull(IList<string> elements)
{
return elements[0] == null;
}
@SoftwareDevPro
SoftwareDevPro / update_item_aws_dyndb.js
Created September 16, 2020 19:34
Update of a top-level attribute in a DynamoDb AWS table
async function updateItem (table, ue, eav) {
const params = {
TableName: table,
Key: {
userId: 'johnDoe'
},
UpdateExpression: ue,
ExpressionAttributeValues: eav,
ReturnValues: 'UPDATED_NEW'
}
@SoftwareDevPro
SoftwareDevPro / query_item_aws_dyndb.js
Created September 15, 2020 23:01
Query an item from an AWS DynamoDb table
async function query (table, kce, eav) {
const params = {
TableName: table,
KeyConditionExpression: kce,
ExpressionAttributeValues: eav
}
try {
let result = await ddb.query(params).promise()
return result
@SoftwareDevPro
SoftwareDevPro / deleteitem_aws_dyndb.js
Created September 14, 2020 23:24
Deletes a single item from the table in Aws DynamoDb
async function deleteItem (tableName, keyParam) {
const params = {
TableName: tableName,
Key: keyParam
}
try {
await ddb.delete(params).promise()
} catch (error) {
@SoftwareDevPro
SoftwareDevPro / get_partial_item_aws_dyndb.js
Created September 11, 2020 23:17
Return partial data from an Item in an AWS DynamoDb
async function getPartialData(table, projectExp, expAttr, key, value) {
const params = {
TableName: table,
ProjectionExpression: projectExp,
ExpressionAttributeNames: expAttr,
Key: { key: value }
}
try {
const result = await ddb.get(params).promise()
@SoftwareDevPro
SoftwareDevPro / get_item_aws_dyndb.js
Created September 9, 2020 23:40
Get an item from a DynamoDb Table
Get Item from DynamoDb Table
async function getItem(tableName, key, value) {
const params = {
TableName: tableName,
Key: {
key: value
}
}
@SoftwareDevPro
SoftwareDevPro / itoa.c
Created September 8, 2020 01:01
C implementation of itoa (integer to ascii)
/* reverse: reverse string s in place */
void reverse(char s[])
{
int i, j;
char c;
for (i = 0, j = strlen(s)-1; i<j; i++, j--) {
c = s[i];
s[i] = s[j];
s[j] = c;
@SoftwareDevPro
SoftwareDevPro / scan_aws_dyndb.js
Created September 5, 2020 01:06
Returns all items from a given table in DynamoDb
async function scan(table) {
try {
let result = await ddb.scan({ TableName: table }).promise()
console.log(result);
} catch (err) {
console.error(err);
}
}
@SoftwareDevPro
SoftwareDevPro / create_aws_dddb_item.js
Created September 3, 2020 22:52
Create an Item in a DynamoDB table
async function createItem () {
const createdUpdated = (new Date()).getTime();
let params = {
TableName: tableName,
Item: {
'userId': 'userId',
'createdAt': createdUpdated,
'updatedAt': createdUpdated
}
}
@SoftwareDevPro
SoftwareDevPro / roman_to_integer.py
Created September 3, 2020 01:50
Roman Numerals To Integer
# Dictionary of roman numbers to their integer equivalent
ROMAN_NUMERALS = { 'I' : 1, 'V' : 5, 'X' : 10, 'L' : 50, 'C' : 100, 'D' : 500, 'M' : 1000 }
# to_integer, takes in a string that represent a roman number, and
# returns its integer equivalent
def to_integer(roman):
result = 0
# for every roman character passed, it N + 1 is greater/equal then the