This file contains 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
function doYourStuff() { | |
const yourString = "foobar" | |
const uniqueString = findUniqueString(yourString) | |
// continue with your logic with unique string | |
} | |
function findUniqueString(baseString) { | |
let uniqueString = baseString | |
// number of iterations should be super small, probably unnecessary to have a max threshold |
This file contains 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
-- Create a new trigger | |
CREATE OR REPLACE FUNCTION public.notify_parqet_api_signup() | |
RETURNS TRIGGER AS $$ | |
DECLARE | |
parqet_user_id varchar; | |
social_provider_id varchar; | |
BEGIN | |
-- Extract ID from social provider, can be null | |
social_provider_id := NEW.raw_user_meta_data->>'provider_id'; |
This file contains 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 (user, context, callback) { | |
const axios = require('axios'); | |
const isSocial = context.connectionStrategy === context.connection; | |
// if it is the first login (hence the `signup`) and it is a social login | |
if (context.stats.loginsCount === 1 && isSocial) { | |
let loginMethod = ''; | |
const connectionName = user.identities[0].provider.toLowerCase(); |
This file contains 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 acquireLock(name) { | |
// Open connection to database | |
const collection = await db.collection('locks'); | |
try { | |
// Insert an entry to the database, using the _id field, which already has a unique key constraint | |
await collection.insertOne({ _id: name }); | |
// No exception was thrown, so we successfully acquired a lock | |
return true; |
This file contains 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
/** | |
* Create the MongoDB collection and an expiring index on a field named "expiresAt". | |
* | |
* db.createCollection('locks'); | |
* db.locks.createIndex( { "expiresAt": 1 }, { expireAfterSeconds: 0 } ) | |
**/ | |
async function acquireLock(name, ttlSeconds) { | |
const collection = await db.collection('locks'); |
This file contains 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
// Scheduled job running at 4:30 am | |
cron.scheduleJob('30 4 * * *', async () => { | |
// Acquire distributed lock | |
await lockService.acquireAndExecute({ name: 'translateAssets', ttlSeconds: 60 * 60 }, async () => { | |
// code to translate assets | |
}) | |
This file contains 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
{ | |
"_id": "1232312323", | |
"name": "Apple", | |
"isin": "US123456890", | |
"marketCap": 1233413233.123, | |
"ipoDate": "2000-01-01", | |
"lastPrice": 123.23, | |
"dividends": [ | |
{ | |
"date": "2022-01-01", |
This file contains 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
db.assets.find({ | |
ipoDate: { $gt: ISODate('2015-01-01')}, | |
"dividends.date": { $gt: ISODate('2022-07-01') } | |
}) |
This file contains 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
db.assets.find({ | |
"myArray.0": { $exists: true } | |
}) |
This file contains 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
db.assets.find({ | |
myArray: { | |
$elemMatch: { | |
myProperty: 'val' | |
} | |
} | |
}) |