Skip to content

Instantly share code, notes, and snippets.

View sdawood's full-sized avatar

Shaady Dawood sdawood

View GitHub Profile
@sdawood
sdawood / minikube-refresh-ecr-token-secret.sh
Created October 9, 2024 15:33
Refresh AWS ECR token and update imagePullSecret for minikube local Deployment of AWS ECR hosted container images
#!/bin/bash
ACCOUNT_ID=$AWS_ACCOUNT_ID
REGION=$AWS_REGION
aws ecr get-login-password --region ${REGION} | docker login --username AWS --password-stdin "${ACCOUNT_ID}.dkr.ecr.${REGION}.amazonaws.com"
dockerconfigjson=$(cat ~/.docker/config.json | base64 -w0)
# This local minikube secret should be used as imagePullSecret in Deployment manifests applied to minikube
#
@sdawood
sdawood / remove-all-youtube-liked-videos.js
Last active March 22, 2026 18:57
How to remove (unlike) all liked videos on youtube, June, 2023
/*
* inspired by https://gist.github.com/astamicu/eb351ce10451f1a51b71a1287d36880f
* modified to remove all liked Youtube videos and to work with Youtube as of June 2023
*/
setInterval(function () {
videos = document.getElementsByTagName('ytd-playlist-video-renderer');
// when a video is removed, the tag gets an 'is-dimissed' attribute, which tripped the original script
var notDismissedIndex = 0;
@sdawood
sdawood / remove-all-youtube-watch-later-videos.js
Last active June 29, 2023 00:05
How to remove all videos from Youtube Watch later list
/* Quoted from:
* https://www.alphr.com/delete-all-watch-later-videos-youtube/
* The above used xpath with a span, which doesn't work for Youtube as of June 2023
*/
setInterval(function () {
document.querySelector('#primary button[aria-label="Action menu"]').click();
var things = document.evaluate( '//yt-formatted-string[contains(text(),"Remove from")]',
document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
for (var i = 0; i < things.snapshotLength; i++) { things.snapshotItem(i).click(); }
@sdawood
sdawood / GraphQLMoment.js
Created January 22, 2022 09:16 — forked from rijvirajib/GraphQLMoment.js
A GraphQL Date type using Moment as the parser allowing for any date input, formatted using moment.format()
import moment from 'moment';
import {GraphQLScalarType, GraphQLError, Kind} from 'graphql';
module.exports = new GraphQLScalarType({
name: 'Date',
/**
* Serialize date value into string
* @param {moment} value date value
* @return {String} date as string
*/
@sdawood
sdawood / throttled-client.js
Created July 20, 2018 04:37
Consuming the Async Generator with Throttling
const {RateLimiter} = require('limiter');
async function main(rate, interval) {
const rateLimiter = new RateLimiter(rate, interval);
for await (const iter of queryBatches('ExampleTable', {keyConditionExpressoin: {...}, expressionAttributeValues: {...}})) {
const {ConsumedCapacity} = iter.metadata();
for (const value of iter) {
// You can use functional-pipelines to reduce or transduce the iterator as needed
@sdawood
sdawood / limiter-get-tokens.js
Created July 20, 2018 04:21
Patching limiter with async getTokens
const {RateLimiter} = require('limiter');
RateLimiter.prototype.getTokens = async function (count) {
const that = this;
if (count <= this.tokenBucket.bucketSize) {
return new Promise((resolve, reject) => {
this.removeTokens(count, (err, remaining) => {
if (err) {
return reject(err);
}
@sdawood
sdawood / query-all.js
Created July 20, 2018 04:12
Reducing the Async Generator into an Array
const F = require('functional-pipelines')
async function queryAll(table, {keyConditionExpression, expressionAttributeValues, strict, limit} = {}, options = {}, params = {}) {
return F.reduceAsync(F.append(/*reducingFn*/), () => [], querySequence(table, {keyConditionExpression, expressionAttributeValues, limit, strict}, options, params));
}
@sdawood
sdawood / query-sequence-generator.js
Created July 20, 2018 04:07
Async Generator of values
async function* querySequence(table, {keyConditionExpression, expressionAttributeValues, strict = false, limit} = {}, options = {}, params = {}) {
return yield* queryBatches(table, {keyConditionExpression, expressionAttributeValues, strict, limit, flatten: true}, options, params); // see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/yield*
}
@sdawood
sdawood / query-batches-generator.js
Last active July 20, 2018 04:25
Async Generator of Batches
const F = require('functional-pipelines');
async function* queryBatches(table, {keyConditionExpression, expressionAttributeValues, strict = false, limit, flatten = false} = {}, options = {}, params = {}) {
let LastEvaluatedKey;
let Count;
let ScannedCount;
let ConsumedCapacity;
let itemsBatch = [];
let resultsCount = 0;
let yieldCount = 0;
@sdawood
sdawood / async-query.js
Created July 20, 2018 03:33
Async Wrapper for DocumentClient.query
async function query(table, {keyConditionExpression, expressionAttributeValues} = {}, options = {}, params = {}) {
const docClient = new AWS.DynamoDB.DocumentClient({...options});
const requiredParams = {
TableName: table,
KeyConditionExpression: keyConditionExpression,
ExpressionAttributeValues: expressionAttributeValues,
ReturnConsumedCapacity: 'TOTAL'
};
return docClient.query({...requiredParams, ...params}).promise();
}