Skip to content

Instantly share code, notes, and snippets.

@kcharles52
kcharles52 / dynamoDBPagination.ts
Created February 24, 2023 10:52 — forked from mayank-kansal15/dynamoDBPagination.ts
This gist contain code to demonstrate how pagination can be done in DynamoDB.
function searchBlogByTitle(query: string, itemsPerPage: number, lastEvaluatedKey?: string): Promise<any> {
const FIXED_ID_FOR_SEARCH_GSI = "1233421345223";
let params: AWS.DynamoDB.DocumentClient.QueryInput = {
TableName: "Blog",
IndexName: "BlogSearch",
KeyConditionExpression: "fixedIdForSearchGSI = :pkv",
FilterExpression: "contains(titleInLowerCase, :titleV)",
ExpressionAttributeValues: {
":pkv": FIXED_ID_FOR_SEARCH_GSI,
":titleV": query.toLocaleLowerCase()
@kcharles52
kcharles52 / vscode-macos-context-menu.md
Created February 9, 2023 02:22 — forked from idleberg/vscode-macos-context-menu.md
“Open in Visual Studio Code” in macOS context-menu

Open in Visual Studio Code

  • Open Automator
  • Create a new document
  • Select Quick Action
  • Set “Service receives selected” to files or folders in any application
  • Add a Run Shell Script action
    • your default shell should already be selected, otherwise use /bin/zsh for macOS 10.15 (”Catalina”) or later
    • older versions of macOS use /bin/bash
  • if you're using something else, you probably know what to do 😉
@kcharles52
kcharles52 / useScrollRestoration.ts
Created February 3, 2023 08:20 — forked from EQuimper/useScrollRestoration.ts
NextJS save scroll position between page for back handler
import React from 'react';
import Router, { NextRouter } from 'next/router';
// Save the scroll position for the given url
function saveScrollPosition(
url: string,
element: HTMLElement,
savePosition: (url: string, pos: number) => void
) {
@kcharles52
kcharles52 / index.js
Created September 8, 2022 06:23 — forked from LearnWebCode/index.js
Puppeteer / Node.js Automation & Web Scraping Tutorial from YouTube
// in a new folder be sure to run "npm init -y" and "npm install puppeteer"
const puppeteer = require("puppeteer")
const fs = require("fs/promises")
async function start() {
const browser = await puppeteer.launch()
const page = await browser.newPage()
await page.goto("https://learnwebcode.github.io/practice-requests/")
const names = await page.evaluate(() => {
@kcharles52
kcharles52 / group-objects-by-property.md
Created February 8, 2022 07:20 — forked from mikaello/group-objects-by-property.md
Group Array of JavaScript Objects by Key or Property Value

Group array of JavaScript objects by keys

This fork of JamieMason's implementation changes the key parameter to be an array of keys instead of just a single key. This makes it possible to group by multiple properties instead of just one.

Implementation

const groupBy = keys => array =>
  array.reduce((objectsByKeyValue, obj) => {
    const value = keys.map(key => obj[key]).join('-');
@kcharles52
kcharles52 / stash-pop-recover
Created November 30, 2020 18:24 — forked from davidwalter0/stash-pop-recover
Undoing accidental git stash pop
# https://stackoverflow.com/questions/6543519/undoing-accidental-git-stash-pop
# https://stackoverflow.com/questions/89332/how-to-recover-a-dropped-stash-in-git
accepted
If you have only just popped it and the terminal is still open, you will still have the hash value printed by git stash pop on screen (thanks, Dolda).
Otherwise, you can find it using this for Linux and Unix:
git fsck --no-reflog | awk '/dangling commit/ {print $3}'
and for Windows:
@kcharles52
kcharles52 / react-select-event.jsx
Created September 16, 2020 11:22 — forked from cyrilf/react-select-event.jsx
Solution to receive an event with react-select onChange method
// Issue: `react-select` `onChange` method doesn't return a proper event
//
// Solution used:
//
// The main idea is to have an hidden `select` that will trigger a real event
// When `ReactSelect` triggers it's `onChange` we set the state with the `selectedOptions`
// these `selectedOptions` will be what populate our hidden select.
// Using the callback from `setState` (it ensures that the new values are already into our hidden select),
// we then create a change event and dispatch it into our hidden select.
// This will cause the `onChange` from this select to be triggered with a proper `event`.
@kcharles52
kcharles52 / test.py
Created September 18, 2018 11:52
Test
from django.test import TestCase
from authors.apps.authentication.models import User
class TestUser(TestCase):
def setup():
self.client = Client()
self.username = 'kato'
self.email = '[email protected]'
self.password = '123456789'
@kcharles52
kcharles52 / README-Template.md
Created July 12, 2018 10:00 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites