Skip to content

Instantly share code, notes, and snippets.

@badsyntax
badsyntax / gist:375dfe6258695e5b488d0860ef47ad18
Created March 13, 2024 08:41
remove dotnet bin and obj
find . -iname "bin" -o -iname "obj" | xargs rm -rf
@badsyntax
badsyntax / useHasAncestorRoute.ts
Last active October 19, 2023 07:05
React Navigation hook to check if the current (nested) route has an ancestor route.
import type {
FormsStackParamList,
RootStackParamList,
} from '@your/app';
import type {
NavigationState,
ParamListBase,
PartialState,
Route,
} from '@react-navigation/native';
@badsyntax
badsyntax / cloc.sh
Created October 11, 2023 16:31
react native cloc
cloc --exclude-dir=vendor,.xcodeproj,xcuserdata,build,Pods,node_modules,.gradle,dist,yarn.lock,package-lock.json .
@badsyntax
badsyntax / QueryClientProvider.ts
Last active September 9, 2023 08:20
React Native, React Query Offline Persisted Queries & Mutations
import React, { type PropsWithChildren } from 'react';
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client';
import { onlineManager } from '@tanstack/react-query';
import { queryClient } from './queryClient';
import { storagePersister } from './storagePersister';
export function QueryClientProvider(props: PropsWithChildren) {
return (
<PersistQueryClientProvider
client={queryClient}
@badsyntax
badsyntax / paths.ts
Last active March 13, 2024 11:14
Fast & Flexible TypeScript dot notation key extraction that supports nested objects to a depth of 10
/**
* Example usage:
*
* // default depth of 3: (fastest)
* type keys = Paths<SomeNestedObject> // returns "property" | "nested.property" | "nested.nested.property"
*
* // depth of 10: (can be slow)
* type keys = Paths<SomeNestedObject, 10>
*
* // depth of 10 with keys of type string and number: (slowest)
@badsyntax
badsyntax / ExpressionWhereFinder.cs
Last active March 3, 2023 17:43
c# predicate builder, useful for constructing linq predicates
internal class ExpressionWhereFinder : ExpressionVisitor
{
private readonly IList<MethodCallExpression> _whereExpressions = new List<MethodCallExpression>();
public IEnumerable<MethodCallExpression> GetWhere(Expression expression)
{
Visit(expression);
return _whereExpressions;
}
wget -O- https://apt.releases.hashicorp.com/gpg | gpg --dearmor | sudo tee /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
@badsyntax
badsyntax / example.cs
Created April 29, 2022 11:55
example dotnet 6 code to sign an apple JWT from p8 certificate file
public class TokenSigningRequest
{
public string AppleTeamId { get; set; }
public string AppleServiceId { get; set; }
public string AppleKeyId { get; set; }
public string P8key { get; set; }
}
[HttpPost]
public async Task<IActionResult> CreateSignedToken([FromBody, BindRequired] TokenSigningRequest requestBody)
@badsyntax
badsyntax / multiple-gource.sh
Created April 8, 2022 08:19 — forked from PhiSYS/multiple-gource.sh
Create multiple repositories visualization video using gource and ffmpeg
#!/usr/bin/bash
declare -a repos=(
"$HOME/Projects/myproject/testing/.git"
"$HOME/Projects/myproject/testing-bundle/.git"
"$HOME/Projects/myproject/service-skeleton/.git"
"$HOME/Projects/myproject/documentation-web/.git"
"$HOME/Projects/myproject/documentation-api/.git"
"$HOME/Projects/myproject/coding-standard/.git"
"$HOME/Projects/myproject/context/microservice1/.git"
@badsyntax
badsyntax / azure-pipelines.yml
Last active February 18, 2022 12:58
Azure pipelines install dotnet on mac mini arm64
steps:
- script: |
DOTNET_VERSION="6.0.1xx"
DOTNET_TEMP_DIRECTORY=$(cat /dev/urandom | env LC_ALL=C tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
DOTNET_INSTALL_LOCATION="$(Agent.TempDirectory)/$DOTNET_TEMP_DIRECTORY"
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --architecture arm64 --channel "$DOTNET_VERSION" --install-dir "$DOTNET_INSTALL_LOCATION"
PATH="$PATH:$DOTNET_INSTALL_LOCATION"
echo "##vso[task.setvariable variable=PATH;]$PATH"
displayName: Install .NET 6.0 SDK