This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function updateItem (table, ue, eav) { | |
| const params = { | |
| TableName: table, | |
| Key: { | |
| userId: 'johnDoe' | |
| }, | |
| UpdateExpression: ue, | |
| ExpressionAttributeValues: eav, | |
| ReturnValues: 'UPDATED_NEW' | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function query (table, kce, eav) { | |
| const params = { | |
| TableName: table, | |
| KeyConditionExpression: kce, | |
| ExpressionAttributeValues: eav | |
| } | |
| try { | |
| let result = await ddb.query(params).promise() | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function deleteItem (tableName, keyParam) { | |
| const params = { | |
| TableName: tableName, | |
| Key: keyParam | |
| } | |
| try { | |
| await ddb.delete(params).promise() | |
| } catch (error) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Get Item from DynamoDb Table | |
| async function getItem(tableName, key, value) { | |
| const params = { | |
| TableName: tableName, | |
| Key: { | |
| key: value | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 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; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function scan(table) { | |
| try { | |
| let result = await ddb.scan({ TableName: table }).promise() | |
| console.log(result); | |
| } catch (err) { | |
| console.error(err); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function createItem () { | |
| const createdUpdated = (new Date()).getTime(); | |
| let params = { | |
| TableName: tableName, | |
| Item: { | |
| 'userId': 'userId', | |
| 'createdAt': createdUpdated, | |
| 'updatedAt': createdUpdated | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 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 |