Skip to content

Instantly share code, notes, and snippets.

View CharlieGreenman's full-sized avatar
🦘
razroo.com | Code Hive Mind

Charlie Greenman CharlieGreenman

🦘
razroo.com | Code Hive Mind
View GitHub Profile
@CharlieGreenman
CharlieGreenman / gist:19264e128fb7b41cf8e84f915f2da067
Created July 17, 2024 21:34
Atomic counter using AWS, Typescript/Node + AWS
// ATOMIC COUNTER
// no other operations can happen before or after state of the data being modified
const updateParams: DocumentClient.UpdateItemInput = {
TableName: GENERIC_TABLE,
Key: { pk: `ORG#${organizationId}`, sk: `USER#${userId}` },
ReturnValues: 'UPDATED_NEW',
UpdateExpression: 'SET #itemCounter = if_not_exists(#itemCounter, :start) + :inc, #activeItems = if_not_exists(#activeItems, :start) + :inc',
ExpressionAttributeNames: {
'#itemCounter': 'itemCounter',
'#activeItems': 'activeItems'
@CharlieGreenman
CharlieGreenman / scroll-into-view-directive-before.directive.ts
Last active July 12, 2024 21:00
Directive to scroll into view. Showing the before and after using input signals
import { isPlatformBrowser } from '@angular/common';
import {
Directive,
ElementRef,
Inject,
OnChanges,
PLATFORM_ID,
Renderer2,
SimpleChanges,
input,
@CharlieGreenman
CharlieGreenman / Makefile
Created April 21, 2024 23:49
Typescript x Node Lambda Layers - Syntax for creating a lambda layer that uses a makefile to build typescript
# file path of makefile: src/functions/shared/Makefile
build-SharedLambdaLayer:
rm -Rf node_modules
npm install
npm run build
cp -rf dist/* ${ARTIFACTS_DIR}
npm prune --production
cp -rf node_modules ${ARTIFACTS_DIR}
@CharlieGreenman
CharlieGreenman / server.ts
Last active April 21, 2024 03:38
server.ts for serverless-express purposes
import 'zone.js/node';
import { APIGatewayEvent, Context, APIGatewayProxyResult } from 'aws-lambda';
import { APP_BASE_HREF } from '@angular/common';
import * as express from 'express';
import { CommonEngine } from '@angular/ssr';
import { existsSync } from 'fs';
import { join } from 'path';
export const REQUEST = new InjectionToken<Request>('REQUEST');
export const RESPONSE = new InjectionToken<Response>('RESPONSE');
@CharlieGreenman
CharlieGreenman / track-by-property.pipe.ts
Last active January 11, 2024 18:23
Track by property for Angular. Useful for cdk-tree to allow it to use immutable data and be performance conscious
// Import the core angular services.
import { Pipe } from "@angular/core";
import { PipeTransform } from "@angular/core";
// ----------------------------------------------------------------------------------- //
// ----------------------------------------------------------------------------------- //
interface TrackByFunctionCache {
[ propertyName: string ]: <T>( index: number, item: T ) => any;
}
@CharlieGreenman
CharlieGreenman / large-node-modules.sh
Created February 23, 2023 14:47
find node modules that are higher than 1mb
du -sh ./node_modules/* | sort -nr | grep '\dM.*'
@CharlieGreenman
CharlieGreenman / rz-breakpoint scss function
Last active September 18, 2022 12:25
Razroo breakpoint scss function that we use to keep all responsive items consistent across application
```
// breakpoints to be used in conjunction with media queries across app
@function rz-breakpoint($breakpoint) {
$breakpoints: (
'extra-small': 599,
'small': 959,
'medium': 1279,
'large': 1919,
'extra-large': 5000,
);
module.exports = (on, config) => {
on('before:browser:launch', (browser = {}, args) => {
console.log(config, browser, args);
if (browser.name === 'chrome') {
args.push("--disable-features=CrossSiteDocumentBlockingIfIsolating,CrossSiteDocumentBlockingAlways,IsolateOrigins,site-per-process");
args.push("--load-extension=cypress/extensions/Ignore-X-Frame-headers_v1.1");
}
return args;
});
};
@CharlieGreenman
CharlieGreenman / sample.ts
Created January 28, 2020 02:39
Compodoc / Jsdoc example
/**
* Display only completed todos
*/
displayCompleted() {
this.currentFilter = 'completed';
EmitterService.get(this.id).emit('displayCompleted');
}
/**
* Display all todos
*/
@CharlieGreenman
CharlieGreenman / package.json
Last active November 14, 2019 11:10
moment.js typings snippet from package.json file
{
"name": "moment",
...
"typings": "./moment.d.ts",
...
}