Skip to content

Instantly share code, notes, and snippets.

@MrTin
MrTin / flexible_dict.py
Created March 6, 2025 18:56
FlexibleDict
"""
Flexible Data Access Utilities
==============================
This module provides utilities for flexible, safe access to data structures
with mixed access patterns (attribute access, dictionary access) and automatic
handling of nested structures.
Key features:
- Access data via attributes or dictionary keys transparently
@MrTin
MrTin / json-schema-to-validation.js
Created January 9, 2025 08:01
JSON Schema Validation with support for conditionals
export const jsonSchemaToValidation = (schema, watchedValues = {}) => {
const rules = {};
// Process conditional requirements from allOf
const getConditionalRequiredFields = () => {
const conditionalRequired = new Set(schema.required || []);
if (schema.allOf) {
schema.allOf.forEach(condition => {
if (condition.if && condition.then) {
@MrTin
MrTin / example.md
Created December 3, 2024 16:29
GraphQL & Pydantic validation & react-hook-form

Validation using Pydantic

from pydantic import BaseModel, validator, ValidationError

class EventData(BaseModel):
    title: str
    start_time: str
    end_time: str
@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();
// }