Skip to content

Instantly share code, notes, and snippets.

@MrTin
MrTin / mdm-nuke.sh
Last active October 18, 2023 11:01
MDM Nuke
# WiFi: On
sudo profiles show -type enrollment
# Take note of domains used for enrollment
# WiFi: Off
sudo profiles remove -all
# Restart: Recovery Mode
csrutil disable; reboot
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
extends: [
'next/core-web-vitals',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'prettier',
],
plugins: ['jest', '@typescript-eslint', 'prettier'],
import { OAuthConfig, OAuthUserConfig } from 'next-auth/providers';
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
export interface BoltProfile extends Record<string, any> {
profile: Profile;
addresses: Address[];
// payment_methods: PaymentMethod[]; # TODO: Implement...
has_bolt_account: boolean;
@MrTin
MrTin / enforce_pr_title.yml
Created July 27, 2023 20:15
GitHub Action: Enforce PR Title style
name: Enforce PR Title Style
on:
pull_request:
types: [opened, edited, synchronize, reopened]
jobs:
enforce_pr_title:
name: Enforce PR Title Style
runs-on: ubuntu-latest
steps:
@MrTin
MrTin / dev.rake
Last active February 13, 2023 23:11
Rails: Download and restore database locally from production
namespace :dev do
namespace :db do
desc 'Reset database and import production data'
task restore_from_prod: :environment do
unless Rails.env.development?
puts("This task is only available in development")
next
end
tmp_path = Rails.root.join("tmp")
@MrTin
MrTin / simulate-slow-network.js
Created February 8, 2023 21:36
one-liner to sleep
await new Promise(res => setTimeout(res, 1200));
import { ExecutionContext, Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';
import { GqlExecutionContext } from '@nestjs/graphql';
// import { UserService } from 'src/user/user.service';
@Injectable()
export class GqlAuthGuard extends AuthGuard('jwt') {
// constructor(@Inject(UserService) private readonly userService: UserService) {
// super();
// }
@MrTin
MrTin / nextjs-basic-http-auth.ts
Created October 20, 2022 17:28
NextJS Basic HTTP Authentication
// src/middleware.ts
import { NextRequest, NextResponse } from 'next/server';
export const config = {
matcher: '/:path*',
};
export function middleware(req: NextRequest) {
const basicAuth = req.headers.get('authorization');
const url = req.nextUrl;
@MrTin
MrTin / pm2.js
Last active October 18, 2022 20:16
NestJS PM2
// package.json
{ "pm2": "^5.2.0" }
{ "start:prod:cluster": "pm2-runtime start ecosystem.config.js --env production" }
// ecosystem.config.js
module.exports = {
apps: [
{
name: 'api',
script: 'dist/src/main.js',
// https://www.apollographql.com/docs/apollo-server/data/errors/#unauthenticated
// Using types and unions
// https://blog.logrocket.com/handling-graphql-errors-like-a-champ-with-unions-and-interfaces/
// Wrap mutation with result{user, errors}
// https://stackoverflow.com/a/55532706
// UserInputError
// ValidationError