Skip to content

Instantly share code, notes, and snippets.

View Josscii's full-sized avatar
💭
??

Josscii Josscii

💭
??
View GitHub Profile
@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()
@Josscii
Josscii / RxSwift.md
Last active May 16, 2020 08:09
理解 RxSwift 文章备份

https://academy.realm.io/posts/krzysztof-siejkowski-mobilization-2017-rxswift-deep-cuts/ https://www.polidea.com/blog/8-Mistakes-to-Avoid-while-Using-RxSwiftPart-1/


RxSwift - Mistakes to Avoid. Part 1

Part 1: not disposing a subscription

Judging by the number of talks, articles and discussions related to reactive programming in Swift in general and the RxSwift library in particular, it looks like the community has been taken by the storm. The concept of reactiveness, however, is not a new shiny thing. The idea of using it for the development within the Apple ecosystem had been played with for a long time. Frameworks like ReactiveCocoa had existed for years and did an awesome job at bringing the reactive programming to the Objective-C. When Swift appeared with its new and exciting features, the way was paved for RxSwift, the elegant and compact port of C#-originated Reactive Extensions. It became even more convenient to go full in on the “signals as your apps’ building blocks” model.