Skip to content

Instantly share code, notes, and snippets.

View brandonscript's full-sized avatar
Turning caffeine into code

Brandon Shelley brandonscript

Turning caffeine into code
View GitHub Profile
@brandonscript
brandonscript / Image.tsx
Created May 5, 2023 16:47
Material-UI v5 component wrapper for next/image
import classNames from "classnames";
// This is from another project isn't properly published yet,
// but you can grab it from https://github.com/brandonscript/mui-flexy
import { FlexBox, FlexBoxProps } from "components/ui/flexbox";
import deepmerge from "deepmerge";
import { toFiniteInt } from "lib/numbers";
import { toSentenceCase } from "lib/strings";
import NextImage, { ImageProps as NextImageProps } from "next/image";
@brandonscript
brandonscript / Flex.md
Last active August 27, 2022 04:09
Flex.tsx is a thin wrapper set of components for MUI v5's Box and Grid components that provides easy x/y coordinates and row/column props for flexbox positioning
@brandonscript
brandonscript / WalkPath+Origin.py
Last active May 18, 2021 02:52
WalkPath: A wrapper for pathlib.Path – deeply search the specified path and return all files and dirs (using os.walk), mapped to WalkPath objects that maintain a hierarchical matrix of pathlib.Path objects.
#!/usr/bin/env python
from pathlib import Path
from typing import Union, Iterable
def is_sys_file(path: Union[str, 'Path', 'WalkPath']) -> bool:
"""Checks to see if the path provided is a system file.
Args:
path (str or Pathlike): Path to check
@brandonscript
brandonscript / UIImage-imageRotatedByDegrees.m
Created November 15, 2014 17:52
UIImage image rotated by degrees
// Requires macros:
#define RADIANS_TO_DEGREES(radians) ((radians) * (180.0 / M_PI))
#define DEGREES_TO_RADIANS(angle) (angle / 180.0 * M_PI)
- (UIImage *)imageRotatedByDegrees:(CGFloat)degrees
{
// calculate the size of the rotated view's containing box for our drawing space
UIView *rotatedViewBox = [[UIView alloc] initWithFrame:CGRectMake(0,0,self.size.width, self.size.height)];
CGAffineTransform t = CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(degrees));
@brandonscript
brandonscript / UIImage-fixRotation.m
Created November 15, 2014 17:50
UIImage rotation fix
- (UIImage *)fixRotation
{
if (self.imageOrientation == UIImageOrientationUp) return self;
CGAffineTransform transform = CGAffineTransformIdentity;
switch (self.imageOrientation) {
case UIImageOrientationDown:
case UIImageOrientationDownMirrored:
transform = CGAffineTransformTranslate(transform, self.size.width, self.size.height);
transform = CGAffineTransformRotate(transform, M_PI);
@brandonscript
brandonscript / AutoLayout_keyboard_iOS8.m
Last active August 29, 2015 14:06
AutoLayout UIScrollView adjustments with arbitrary keyboard sizes on iOS 8
// If you're using Interface Builder, set your UITextView or UIScrollView bottom constraint to the bottom layout guide, constant=0, then create an IBOutlet for the constraint.
// If you're writing it in code, create that constraint programatically and make sure it's a @property.
- (void)viewDidAppear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidShow:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardDidHide:) name:UIKeyboardDidHideNotification object:nil];
// You're probably going to do this, but it's not actually part of the example
_textView.delegate = self;