Skip to content

Instantly share code, notes, and snippets.

View Josscii's full-sized avatar
💭
??

Josscii Josscii

💭
??
View GitHub Profile
@Josscii
Josscii / OverrideCatalystScaleFactor.swift
Created April 7, 2025 05:50 — forked from JunyuKuang/OverrideCatalystScaleFactor.swift
Disable 77% scaling for Mac Catalyst apps. (Swift)
let overrideCatalystScaleFactor: Void = {
guard let sceneViewClass = NSClassFromString("UINSSceneView") as? NSObject.Type else {
return
}
if sceneViewClass.instancesRespond(to: NSSelectorFromString("scaleFactor")) {
// old
swizzleInstanceMethod(
class: sceneViewClass,
originalSelector: NSSelectorFromString("scaleFactor"),
swizzledSelector: #selector(swizzle_scaleFactor)
@Josscii
Josscii / parseflomo.js
Created April 30, 2022 07:55
parse flomo html to md file
const jsdom = require("jsdom");
const { JSDOM } = jsdom;
const fs = require("fs");
const files = [
"202012.html",
"202111.html",
"202112.html",
"202201.html",
"202202.html",
@Josscii
Josscii / GlobalSpinnerContextProvider.tsx
Created April 18, 2022 05:35
how to use context with children to avoid rerender
import GlobalSpinner from '@/components/GlobalSpinner'
import { contextFactory } from './helpers/contextFactory'
import { useToggleState } from '@/hooks/useToggleState'
type GlobalSpinnerContextProviderProps = {
children: React.ReactNode
}
const GlobalSpinnerContextProvider = (
props: GlobalSpinnerContextProviderProps
@Josscii
Josscii / contextFactory.ts
Last active April 18, 2022 05:27
react typescript context helper
import { createContext, useContext } from 'react'
export const contextFactory = <A extends unknown | null>() => {
const context = createContext<A | undefined>(undefined)
const useCtx = () => {
const ctx = useContext(context)
if (ctx === undefined) {
throw new Error('useContext must be used inside of a Provider with a value.')
}
return ctx
@Josscii
Josscii / SkeletonLoader.tsx
Created February 12, 2022 08:05
try to create skeleton with styled component
import { FunctionComponent } from "react";
import styled, { keyframes, css } from "styled-components";
const SkeletonLoader: FunctionComponent<{
isLoading?: boolean;
}> = (props) => {
return (
<Content isLoading={props.isLoading}>
{props.isLoading && <Loader />}
{props.children}
@Josscii
Josscii / InnerShadow.swift
Last active July 30, 2021 10:20
create inner shadow - forget original source
// use after view has been layout
extension UIView
{
// different inner shadow styles
public enum innerShadowSide
{
case all, left, right, top, bottom, topAndLeft, topAndRight, bottomAndLeft, bottomAndRight, exceptLeft, exceptRight, exceptTop, exceptBottom
}
@Josscii
Josscii / dart.md
Last active September 9, 2021 23:21
dart cheat sheet

string interpolation

var a = 3;
print("$a 123");
print("${a+1} 123");

final const

@Josscii
Josscii / GradientView.swift
Last active July 16, 2020 06:19
GradientView 方便布局
class GradientView: UIView {
var gradientLayer: CAGradientLayer {
return layer as! CAGradientLayer
}
override class var layerClass: AnyClass {
return CAGradientLayer.self
}
}
@Josscii
Josscii / maxLength.swift
Created June 3, 2020 23:12
UITextField 和 UITextView 限制最大输入长度
import UIKit
class ViewController: UIViewController {
var textField: UITextField!
var textView: UITextView!
private let maxLength = 20
override func viewDidLoad() {
super.viewDidLoad()