Skip to content

Instantly share code, notes, and snippets.

View secretorange's full-sized avatar

Lee Gunn secretorange

View GitHub Profile
@secretorange
secretorange / GoogleAnalytics.tsx
Created August 20, 2022 05:37
Simple React GoogleAnalytics tracker. No dependencies.
import { useEffect, useState } from 'react';
import { useLocation } from 'react-router';
interface IProps {
key: string;
}
export function GoogleAnalytics({ key }: IProps) {
const location = useLocation();
@secretorange
secretorange / CookieConsent.tsx
Last active August 20, 2022 05:29
Simple Cookie Consent banner in React without dependencies.
import { useEffect, useState } from 'react';
import { Link } from 'react-router-dom';
import { getCookie, setCookie } from './utils';
export default function CookieConsent(){
const [consent, setConsent] = useState(false);
useEffect(() => {
const consent = getCookie("consent");
@secretorange
secretorange / state-service.ts
Last active June 3, 2022 09:01
A simple single file Angular State Service
@Injectable({
providedIn: "root",
})
export class ExampleAppStateService extends StateService {
public get company(): StateItem<CompanyModel> {
return this.get("company", () => new StateItem<CompanyModel>());
}
public get project(): StateItem<ProjectModel> {
return this.get(
@secretorange
secretorange / React Forms
Created August 19, 2021 10:20
React Forms components that *mutate* the main object. Useful for large forms if you want performance and not fussed about immutability.
import React, { useContext } from "react";
const FormContext = React.createContext({
obj: null,
events: null,
} as IFormContext);
export class FormEvents {
onChange?: (args: any) => void;
}
#Issues installing on windows and running post install script
First, setup postgres user:
Run: net user postgres dbpasswordhere /add
Run: compmgmt.msc -> Click Local Users and Groups -> Users -> postgres ->Member of -> Add… -> Administrators -> OK
Run: runas /user:postgres cmd.exe -> cd \ -> postgresql-install.exe -> installed successfully without errors. Checked data folder and confirmed files created successfully.
Run: compmgmt.msc -> Local Users and Groups -> Users -> postgres -> Member of -> Administrators -> Remove
Run: compmgmt.msc -> Local Users and Groups -> Users -> postgres -> Member of -> Add… -> Power Users -> OK
@secretorange
secretorange / DynamoScanPagination.cs
Last active November 3, 2023 14:21
How to manually paginate whilst scanning using AWS DynamoDB and C# SDK
public async Task<IPaged<Item>> Pagination(string serialisedPaginationInfo, int size)
{
// We will fill our 'page' until it's met the pageSize or we complete our search (i.e. scan ALL records)
var page = new List<DM.Document>();
// Get a reference to the table. Only the lower level API seems to suppot manual pagination
var table = Dynamo.GetTargetTable<Item>();
var pagination = String.IsNullOrWhiteSpace(serialisedPaginationInfo)
? new PaginationInfo()
-- TABLE ROW COUNTS
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
-- GET RID OF OLD VERSIONS
IF OBJECT_ID('tempdb..#tmp') IS NOT NULL
DROP TABLE #tmp
Select TOP 10000 VersionID into #tmp FROM cmsDocument
WHERE versionID NOT IN (SELECT D.versionId FROM cmsDocument D
WHERE D.versionId IN (SELECT versionId FROM (SELECT CV.versionId, published, newest, RANK() OVER(ORDER BY CV.versionDate DESC) RowNum
FROM cmsContentVersion CV JOIN cmsDocument DD ON CV.versionId = DD.versionId
WHERE DD.nodeId = D.nodeId) AS tmp
@secretorange
secretorange / CacheInvalidationRequestBuilder.cs
Last active December 19, 2018 09:53
Builds a signed GET request to invalidate an AWS API Gatewat endpoint https://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
using System.Text;
namespace Aws
{
public static class CacheInvalidationRequestBuilder
@secretorange
secretorange / LambdaEntryPoint.cs
Last active August 29, 2023 18:52
Get access to the Lambda alias at Startup which you can then use to load environment specific config
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using System.IO;
using AWSBoot.Boot;
using Microsoft.Extensions.Configuration;
using Amazon.Lambda.AspNetCoreServer.Internal;