<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: StuartCreed</title>
    <description>The latest articles on Forem by StuartCreed (@stuartcreed).</description>
    <link>https://forem.com/stuartcreed</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F293071%2F77469c1f-da25-4be9-a48b-a2b14518bf80.JPG</url>
      <title>Forem: StuartCreed</title>
      <link>https://forem.com/stuartcreed</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/stuartcreed"/>
    <language>en</language>
    <item>
      <title>How to return old data in same query as updating a table in postgres</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Tue, 11 Feb 2025 08:30:46 +0000</pubDate>
      <link>https://forem.com/stuartcreed/how-to-return-old-data-in-same-query-as-updating-a-table-in-postgres-oho</link>
      <guid>https://forem.com/stuartcreed/how-to-return-old-data-in-same-query-as-updating-a-table-in-postgres-oho</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;WITH
    "old_data" AS (
        SELECT
            "id",
            "colour"
        FROM
            "random_table"
        WHERE
            "random_table"."id" IN (643)
    )
UPDATE "random_table" AS "ti"
SET
    "colour" = 'blue'
FROM
    "old_data" AS "od"
WHERE
    "ti"."id" = "od"."id"
RETURNING
    "ti"."id",
    "ti"."status",
    "od"."status" AS "old_status"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>postgres</category>
    </item>
    <item>
      <title>How to turn off bixby talkback on Samsung</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Thu, 05 Sep 2024 11:58:51 +0000</pubDate>
      <link>https://forem.com/stuartcreed/how-to-turn-off-talkback-in-bixby-4nk1</link>
      <guid>https://forem.com/stuartcreed/how-to-turn-off-talkback-in-bixby-4nk1</guid>
      <description>&lt;p&gt;Hold all three buttons down for a while. On the top left one it is the upper side that you need to hold down&lt;/p&gt;

</description>
    </item>
    <item>
      <title>nvm</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Mon, 20 May 2024 07:59:29 +0000</pubDate>
      <link>https://forem.com/stuartcreed/nvm-1o1a</link>
      <guid>https://forem.com/stuartcreed/nvm-1o1a</guid>
      <description>&lt;p&gt;&lt;code&gt;nvm ls&lt;/code&gt; to view all installed versions of node.&lt;br&gt;
&lt;code&gt;nvm install 20&lt;/code&gt; to install node version 20&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Using local node variables</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Tue, 09 Apr 2024 14:51:15 +0000</pubDate>
      <link>https://forem.com/stuartcreed/using-local-node-variables-40p3</link>
      <guid>https://forem.com/stuartcreed/using-local-node-variables-40p3</guid>
      <description>&lt;p&gt;To print all node variables currently in your terminal:&lt;br&gt;
&lt;code&gt;printenv&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To add a node variable: &lt;br&gt;
&lt;code&gt;export NEW_ENVIRONMENT_VARIABLE='something....'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You can also:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;echo $DB_&lt;/code&gt; then tab to can parameters&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SourceMaps with React</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Sun, 17 Dec 2023 20:56:41 +0000</pubDate>
      <link>https://forem.com/stuartcreed/sourcemaps-with-react-26o8</link>
      <guid>https://forem.com/stuartcreed/sourcemaps-with-react-26o8</guid>
      <description>&lt;p&gt;&lt;a href="https://javascript.plainenglish.io/debug-your-react-app-like-a-ninja-with-source-maps-c63010b3a6e7"&gt;https://javascript.plainenglish.io/debug-your-react-app-like-a-ninja-with-source-maps-c63010b3a6e7&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JvhqHgxy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpdvroc01yzhdxjpmjty.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JvhqHgxy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rpdvroc01yzhdxjpmjty.png" alt="Image description" width="800" height="1044"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note that if we are using babel this will be translated to _this2 &lt;br&gt;
&lt;a href="https://medium.com/@tommarren/the-mystery-of-this2-2af4ed10dd28"&gt;https://medium.com/@tommarren/the-mystery-of-this2-2af4ed10dd28&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;why this sometimes shows as undefined in devtools:&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/47530878/why-chrome-dev-tools-cant-reflect-this-correctly-in-a-promise?rq=4"&gt;https://stackoverflow.com/questions/47530878/why-chrome-dev-tools-cant-reflect-this-correctly-in-a-promise?rq=4&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Serve your REACT site on AWS S3</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Sun, 10 Dec 2023 22:47:07 +0000</pubDate>
      <link>https://forem.com/stuartcreed/serve-your-react-site-on-aws-s3-1lh6</link>
      <guid>https://forem.com/stuartcreed/serve-your-react-site-on-aws-s3-1lh6</guid>
      <description>&lt;p&gt;Overview is SPA architecture and example is here: &lt;a href="https://aws.amazon.com/blogs/networking-and-content-delivery/improve-single-page-application-spa-performance-with-a-same-domain-policy-using-amazon-cloudfront/"&gt;https://aws.amazon.com/blogs/networking-and-content-delivery/improve-single-page-application-spa-performance-with-a-same-domain-policy-using-amazon-cloudfront/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NOTE THIS ONLY WORKS WITH REST API ON API GATEWAY. THIS WON'T WORK WITH HTTP API (THE CHEAPER OPTION).&lt;/p&gt;

&lt;p&gt;&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/HostingWebsiteOnS3Setup.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/website-hosting-custom-domain-walkthrough.html"&gt;https://docs.aws.amazon.com/AmazonS3/latest/userguide/website-hosting-custom-domain-walkthrough.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://repost.aws/knowledge-center/cloudfront-https-requests-s3"&gt;https://repost.aws/knowledge-center/cloudfront-https-requests-s3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;WITH GATEWAY INVOLVED:&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-a-react-based-single-page-application-to-amazon-s3-and-cloudfront.html"&gt;https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/deploy-a-react-based-single-page-application-to-amazon-s3-and-cloudfront.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FVQxH04v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/893wslnmy5hjg79e26o8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FVQxH04v--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/893wslnmy5hjg79e26o8.png" alt="Image description" width="800" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/aws-samples/react-cors-spa/tree/main"&gt;https://github.com/aws-samples/react-cors-spa/tree/main&lt;/a&gt;&lt;br&gt;
To make cloudfront work in SPA mode:&lt;br&gt;
&lt;a href="https://stackoverflow.com/questions/16267339/s3-static-website-hosting-route-all-paths-to-index-html"&gt;https://stackoverflow.com/questions/16267339/s3-static-website-hosting-route-all-paths-to-index-html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cloudfront setup would look like this:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BVeCSGJp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rsbw9738eqse1km565t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BVeCSGJp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0rsbw9738eqse1km565t.png" alt="Image description" width="800" height="265"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pn8AslvZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibf4gwn0u15pdqp6mtyn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pn8AslvZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ibf4gwn0u15pdqp6mtyn.png" alt="Image description" width="800" height="225"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To hide your invoke url of API to the public (to ensure that all traffic is going through cloudfront - with WAF protection):&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html"&gt;https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html&lt;/a&gt;&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html#api-gateway-lambda-authorizer-create"&gt;https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html#api-gateway-lambda-authorizer-create&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Create a lambda authoriser with the following lambda definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;export const handler = function(event, context, callback) {
    console.log('Received event:', JSON.stringify(event, null, 2));

    // A simple request-based authorizer example to demonstrate how to use request 
    // parameters to allow or deny a request. In this example, a request is  
    // authorized if the client-supplied headerauth1 header, QueryString1
    // query parameter, and stage variable of StageVar1 all match
    // specified values of 'headerValue1', 'queryValue1', and 'stageValue1',
    // respectively.

    // Retrieve request parameters from the Lambda function input:
    var headers = event.headers;
    var queryStringParameters = event.queryStringParameters;
    var pathParameters = event.pathParameters;
    var stageVariables = event.stageVariables;

    // Parse the input for the parameter values
    var tmp = event.methodArn.split(':');
    var apiGatewayArnTmp = tmp[5].split('/');
    var awsAccountId = tmp[4];
    var region = tmp[3];
    var restApiId = apiGatewayArnTmp[0];
    var stage = apiGatewayArnTmp[1];
    var method = apiGatewayArnTmp[2];
    var resource = '/'; // root resource
    if (apiGatewayArnTmp[3]) {
        resource += apiGatewayArnTmp[3];
    }

    // Perform authorization to return the Allow policy for correct parameters and 
    // the 'Unauthorized' error, otherwise.
    var authResponse = {};
    var condition = {};
    condition.IpAddress = {};

    if (headers.headerauth1 === "headerValue1"
        &amp;amp;&amp;amp; queryStringParameters.QueryString1 === "queryValue1"
        &amp;amp;&amp;amp; stageVariables.StageVar1 === "stageValue1") {
        callback(null, generateAllow('me', event.methodArn));
    }  else {
        callback("Unauthorized");
    }
}

// Help function to generate an IAM policy
var generatePolicy = function(principalId, effect, resource) {
    // Required output:
    var authResponse = {};
    authResponse.principalId = principalId;
    if (effect &amp;amp;&amp;amp; resource) {
        var policyDocument = {};
        policyDocument.Version = '2012-10-17'; // default version
        policyDocument.Statement = [];
        var statementOne = {};
        statementOne.Action = 'execute-api:Invoke'; // default action
        statementOne.Effect = effect;
        statementOne.Resource = resource;
        policyDocument.Statement[0] = statementOne;
        authResponse.policyDocument = policyDocument;
    }
    // Optional output with custom properties of the String, Number or Boolean type.
    authResponse.context = {
        "stringKey": "stringval",
        "numberKey": 123,
        "booleanKey": true
    };
    return authResponse;
}

var generateAllow = function(principalId, resource) {
    return generatePolicy(principalId, 'Allow', resource);
}

var generateDeny = function(principalId, resource) {
    return generatePolicy(principalId, 'Deny', resource);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then update the API gateway to use a new authoriser:&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/apigateway/latest/developerguide/configure-api-gateway-lambda-authorization-with-console.html"&gt;https://docs.aws.amazon.com/apigateway/latest/developerguide/configure-api-gateway-lambda-authorization-with-console.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notes for later on cloudfront functions to strip /api prefix:&lt;br&gt;
&lt;a href="https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/function-code-choose-purpose.html"&gt;https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/function-code-choose-purpose.html&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function handler(event) {
    var request = event.request;
    var uri = request.uri;

    // Remove /api from the URI
    if (uri.startsWith('/api')) {
        request.uri = uri.replace('/api', '');
    }

    return request;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
    </item>
    <item>
      <title>GraphQL with Apollo - in progress</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Sat, 09 Dec 2023 10:41:20 +0000</pubDate>
      <link>https://forem.com/stuartcreed/graphql-with-apollo-in-progress-40jo</link>
      <guid>https://forem.com/stuartcreed/graphql-with-apollo-in-progress-40jo</guid>
      <description>&lt;p&gt;n+1 issues for overfetching&lt;br&gt;
&lt;a href="https://medium.com/paypal-tech/graphql-resolvers-best-practices-cd36fdbcef55"&gt;https://medium.com/paypal-tech/graphql-resolvers-best-practices-cd36fdbcef55&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.apollographql.com/docs/apollo-server/data/fetching-data/#batching-and-caching"&gt;https://www.apollographql.com/docs/apollo-server/data/fetching-data/#batching-and-caching&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>List all of your buckets in Lambda</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Wed, 06 Dec 2023 20:22:45 +0000</pubDate>
      <link>https://forem.com/stuartcreed/list-all-of-your-buckets-in-lambda-5f4p</link>
      <guid>https://forem.com/stuartcreed/list-all-of-your-buckets-in-lambda-5f4p</guid>
      <description>&lt;p&gt;import {S3Client, ListBucketsCommand} from '@aws-sdk/client-s3';&lt;br&gt;
const s3 = new S3Client({region: 'us-west-2'});&lt;/p&gt;

&lt;p&gt;export const handler = async (event) =&amp;gt; {&lt;br&gt;
  const data = await s3.send(new ListBucketsCommand({}));&lt;br&gt;
  return data.Buckets;&lt;br&gt;
};&lt;/p&gt;

</description>
      <category>lamda</category>
    </item>
    <item>
      <title>Example HTML response Lambda</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Wed, 06 Dec 2023 19:34:42 +0000</pubDate>
      <link>https://forem.com/stuartcreed/example-html-response-lambda-4le</link>
      <guid>https://forem.com/stuartcreed/example-html-response-lambda-4le</guid>
      <description>&lt;p&gt;export const handler = async (event) =&amp;gt; {&lt;br&gt;
  const response = {&lt;br&gt;
    statusCode: 200,&lt;br&gt;
    headers: {&lt;br&gt;
        "Content-Type": "text/html"&lt;br&gt;
    },&lt;br&gt;
    body: &lt;code&gt;&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&amp;lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&amp;gt;&amp;lt;/head&amp;gt;&amp;lt;body&amp;gt;&amp;lt;div&amp;gt;test&amp;lt;/div&amp;gt;&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;/code&gt;&lt;br&gt;
  };&lt;br&gt;
  return response;&lt;br&gt;
};&lt;/p&gt;

</description>
      <category>lamdba</category>
    </item>
    <item>
      <title>Visual Studio Code Setup</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Wed, 28 Dec 2022 21:27:21 +0000</pubDate>
      <link>https://forem.com/stuartcreed/visual-studio-code-setup-3f8g</link>
      <guid>https://forem.com/stuartcreed/visual-studio-code-setup-3f8g</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20lgmyewlycgl0ko4hvv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20lgmyewlycgl0ko4hvv.png" alt="Image description" width="800" height="352"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;autosave on and autoformat using prettier in settings &lt;code&gt;cmd + ,&lt;/code&gt;. Install gitlens and eslint.&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>mssql cheatsheet - in progress</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Wed, 28 Dec 2022 21:00:31 +0000</pubDate>
      <link>https://forem.com/stuartcreed/mssql-cheatsheet-in-progress-o6e</link>
      <guid>https://forem.com/stuartcreed/mssql-cheatsheet-in-progress-o6e</guid>
      <description>&lt;p&gt;To find the structural information about a table in mssql:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sp_help table_name
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Use the top helper like &lt;code&gt;select top 10 * from table_name&lt;/code&gt; to limit the number of results from a select wildcard&lt;/p&gt;

</description>
      <category>emptystring</category>
    </item>
    <item>
      <title>Handy codepens on flex grow, shrink and basis</title>
      <dc:creator>StuartCreed</dc:creator>
      <pubDate>Tue, 19 Apr 2022 10:14:59 +0000</pubDate>
      <link>https://forem.com/stuartcreed/handy-codepens-on-flex-grow-shrink-and-basis-426o</link>
      <guid>https://forem.com/stuartcreed/handy-codepens-on-flex-grow-shrink-and-basis-426o</guid>
      <description>&lt;p&gt;&lt;a href="https://codepen.io/JayTutorials/pen/eeqGMr"&gt;https://codepen.io/JayTutorials/pen/eeqGMr&lt;/a&gt;&lt;br&gt;
&lt;a href="https://codepen.io/marshath/pen/qZOxoN/"&gt;https://codepen.io/marshath/pen/qZOxoN/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;flex grow default = 0&lt;br&gt;
flex shrink default = 1&lt;/p&gt;

</description>
      <category>flex</category>
      <category>css</category>
    </item>
  </channel>
</rss>
