Skip to content

Instantly share code, notes, and snippets.

@g33kChris
g33kChris / bar.js
Last active September 10, 2017 20:17
"Pass the Parcel"
import baz from './baz';
export const bar = (myLogger, myApiClient) => {
myLogger.debug('lets make a request!');
return baz(myLogger, myApiClient, "http://somehardcodedurl.com");
}
@g33kChris
g33kChris / bar.js
Created September 10, 2017 20:37
Inverting the dependencies
// Is depdendent on 'baz', and a dependency of foo!
// Note how it no longer passes down an api client!
export const bar = (myLogger, baz) => () => {
myLogger.debug('lets make a request!');
return baz("http://somehardcodedurl.com");
}
@g33kChris
g33kChris / BlogPostViewModelBuilder.ts
Last active April 29, 2018 19:59
Typescript Builder Pattern (Generic to Specific Implementation)
import { injectable } from 'inversify';
import BuilderBase from './BuilderBase';
import IBlogPostViewModelBuilder from './IBlogPostViewModelBuilder';
import IBlogPostViewModel from '@g33kchris/g33kchris.dto.ui/IBlogPostViewModel';
import IContentHeroViewModel from '@g33kchris/g33kchris.dto.ui/IContentHeroViewModel';
import IContentBodyViewModel from '@g33kchris/g33kchris.dto.ui/IContentBodyViewModel';
import IContentMetaViewModel from '@g33kchris/g33kchris.dto.ui/IContentMetaViewModel';
import IRelatedContentViewModel from '@g33kchris/g33kchris.dto.ui/IRelatedContentViewModel';
@g33kChris
g33kChris / Dockerfile
Created September 11, 2018 12:54
.net api dockerfile
FROM microsoft/aspnetcore-build:2.0 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
@g33kChris
g33kChris / new-library-in-app.cs
Last active December 23, 2019 23:03
GameDex Snippets
public async static Task NewLibraryInApp()
{
StorageFolder rootFolder = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFolderAsync("GameDex", CreationCollisionOption.ReplaceExisting);
await rootFolder.CreateFolderAsync("Media");
if (await StorageHelper.WriteFileAsync("gdex.json", App.GameDexModel, rootFolder))
{
StorageHelper.SetSetting("GameDexLocation", "Local", StorageHelper.StorageStrategies.Roaming);
return true;
@g33kChris
g33kChris / gatsby-config.js
Created December 23, 2019 23:07
gatsby-transformer-remark-guide
plugins: [
...
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [{
resolve: "gatsby-remark-stackblitz",
options: {
height: 600
}
@g33kChris
g33kChris / ReactContextToManageGlobalState.md
Last active October 3, 2022 18:54
Using React Context to manage global state

If you want to skip the blog post and go through the code for yourself here's the recommended reading order...

  • application-state.interface.ts and initial-state.ts (understand the state being used)
  • state-action.interface.ts
  • root.reducer.ts (the main integration point for all state reducers)
    • The other reducers show a more granualar breakdown of reducing state in the application, the state in each of the reducers are quite primitive.
  • state.provider.ts (creation of the react context and state object)
  • app.tsx (the main integration point bridging the context provider and the react component tree)
  • with-application-state.tsx (how to wrap state at any point in the component tree)
  • tags.component.ts (basic usage of the application state dispatcher within a component)
@g33kChris
g33kChris / App.tsx
Created December 30, 2019 14:36
Example Tag related search code
// Wrap the application in the InstantSearch provider so the search context is available within the application component tree
<InstantSearchProvider>
{element}
</InstantSearchProvider>