Skip to content

Instantly share code, notes, and snippets.

@panzerdp
panzerdp / decoratedFetch.ts
Last active September 18, 2022 23:51
An extensible fetch() implementation that uses the decorator pattern
type ResponseWithData = Response & { data?: any };
interface Fetcher {
run(input: RequestInfo, init?: RequestInit): Promise<ResponseWithData>;
}
class BasicFetcher implements Fetcher {
async run(input: RequestInfo, init?: RequestInit): Promise<ResponseWithData> {
return await fetch(input, init);
}
@jordibruin
jordibruin / ReviewTabView.swift
Created October 14, 2020 23:23
Simple App Store Review showcase in SwiftUI
struct ReviewTabView: View {
var reviews: [Review] = [
Review(title: "Great app", reviewer: "Maartje Derks", text: "This app really makes my life so much easier. Can't wait to use it."),
Review(title: "Great app", reviewer: "Maartje Derks", text: "This app really makes my life so much easier. Can't wait to use it."),
Review(title: "Great app", reviewer: "Maartje Derks", text: "This app really makes my life so much easier. Can't wait to use it."),
Review(title: "Great app", reviewer: "Maartje Derks", text: "This app really makes my life so much easier. Can't wait to use it."),
]
@State var selectedIndex = 0
@State var timer = Timer.publish(every: 4, on: .main, in: .common).autoconnect()
@codingwithchris
codingwithchris / AppStateContext.tsx
Last active October 30, 2022 17:55
App State Reducer Context Example -- Easily manage the state of a small application by passing userReducer into Context.
import { createContext, useContext, useReducer, Dispatch } from 'react';
/**
* Manages the state for our entire app
*
** For larger, more complex applications, this pattern can be split into multiiple contexts.
** For example: `form`, and `user` would have theor own contexts, each with their own reducer.
*/
// Init an empty context
import SwiftUI
import PlaygroundSupport
struct app: View {
var appTitle: String
var appDesc: String
var appColor: Color
var body: some View {
HStack (alignment: .center, spacing: 14) {
VStack {
@achimoraites
achimoraites / history.component.spec.ts
Created March 21, 2020 14:18
Advanced Angular Testing with Jasmine
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { HistoryComponent } from './history.component';
fdescribe('HistoryComponent', () => {
let component: HistoryComponent;
let fixture: ComponentFixture<HistoryComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
@coodoo
coodoo / statechart-xstate.md
Last active May 26, 2022 20:00
Extensive research of statecharts with a focus on front-end development.

The case for statechart and xstate -- why it matters and how we can benefit from it

Bottom line up front

  • redux is a global data management tool, not a proper state management tool, hence causing a lot of troubles

  • statecharts is an extension to Finite State Machine (FSM) which provides explicit and safe state management capabilities, perfectly fit for front-end development

  • statecharts had been used intensivelly in all industries (be it embedded systems, hardware, electronics, aeronautics, automotive, game development and more), it's us front-end developers late to the party

@alexzuza
alexzuza / with-loading.pipe.ts
Created August 28, 2019 17:50
With loading pipe long living stream
import { Pipe, PipeTransform } from '@angular/core';
import { isObservable, of } from 'rxjs';
import { map, startWith, catchError } from 'rxjs/operators';
@Pipe({
name: 'withLoading',
})
export class WithLoadingPipe implements PipeTransform {
transform(val) {
return isObservable(val)
/**
* @name mapToObject
* @desc Converts Map to Object
* @param {Map} map
* @returns {Object}
*/
function mapToObject(map) {
return Object.assign(Object.create(null), ...[...map].map(v => ({ [v[0]]: v[1] })));
}
@justlaputa
justlaputa / unstar-all-repos.md
Last active May 1, 2024 02:42
How to unstar all your github starred repos
@matteocrippa
matteocrippa / flutter.md
Last active October 26, 2023 05:47
Flutter Cheatsheet

Flutter

A quick cheatsheet of useful snippet for Flutter

Widget

A widget is the basic type of controller in Flutter Material. There are two type of basic Widget we can extend our classes: StatefulWidget or StatelessWidget.

Stateful

StatefulWidget are all the widget that interally have a dynamic value that can change during usage. It can receive an input value in the constructor or reference to functions. You need to create two classes like: