Skip to content

Instantly share code, notes, and snippets.

View dugagjin's full-sized avatar
🤠

Dugagjin Lashi dugagjin

🤠
View GitHub Profile
@dugagjin
dugagjin / info.md
Last active January 7, 2019 10:10
react fetch example

Overview of how React works

I think it would be helpful to start with a quick overview of how React works, and how async rendering will impact class components.

Conceptually, React does work in two phases:

  • The render phase determines what changes need to be made to e.g. the DOM. During this phase, React calls render and then compares the result to the previous render.
  • The commit phase is when React applies any changes. (In the case of React DOM, this is when React inserts, updates, and removes DOM nodes.) React also calls lifecycles like componentDidMount and componentDidUpdate during this phase.

The commit phase is usually very fast, but rendering can be slow. For this reason, async mode will break the rendering work into pieces, pausing and resuming the work to avoid blocking the browser. This means that React may invoke render phase lifecycles more than once before committing, or it may invoke them with

@dugagjin
dugagjin / Lazy.tsx
Created June 26, 2018 19:57 — forked from donaldpipowitch/Lazy.tsx
Lazy loading a React component with TypeScript 2.2
// this is our imaginary package "react-lazy"
import React, { Component, createElement } from 'react';
import { Redirect } from 'react-router-dom';
import { observer } from 'mobx-react';
import { observable } from 'mobx';
/**
* This is generic module interface. We assume that we can access React components.
*/
export interface FetchedModule {
@dugagjin
dugagjin / service-workers.md
Created June 26, 2018 13:38 — forked from Rich-Harris/service-workers.md
Stuff I wish I'd known sooner about service workers

Stuff I wish I'd known sooner about service workers

I recently had several days of extremely frustrating experiences with service workers. Here are a few things I've since learned which would have made my life much easier but which isn't particularly obvious from most of the blog posts and videos I've seen.

I'll add to this list over time – suggested additions welcome in the comments or via twitter.com/rich_harris.

Use Canary for development instead of Chrome stable

Chrome 51 has some pretty wild behaviour related to console.log in service workers. Canary doesn't, and it has a load of really good service worker related stuff in devtools.

@dugagjin
dugagjin / C dijkstra headerfile
Created January 21, 2016 17:09
C++/ C/ openGL
#define infinite 999
#define mapDimension 6
typedef struct City City;
struct City {
int distance;
int previousCity;
int visited;
};
clear all;
% LU Decomposition method:
A = [1 1 6; 1 5 -1; 4 2 -2];
b = [8; 5; 4];
[L,U] = lu(A); % matlab function is: x = A\b
x = U\(L\b);
% Gaussseidel method:
% 9x + 3y + z = 13; 6x + 8z = 2; 2x + 5y - z = 6
@dugagjin
dugagjin / overgangsverschijnselen 2
Created January 9, 2016 23:04
overgangsverschijnselen 2
% Maak een bodeplot van het systeem met polen: p1,2 = -40 +- 100j en
% nullen: z = -100. Versterking is K = 100. Stel de FRF H op met Fs/2 = 128
% en N = 1280. Gebruik 2*real(ifft(H,2*N)) om het impulsantwoord te
% berekenen, en selecteer daaruit de eerste 128 punten. Vanaf nu is dus
% Fs = 256 en N = 128. Construeer ook de tijdsvector
clear all;clf;
polen1 = -40 + 100j;
polen2 = -40 - 100j;
@dugagjin
dugagjin / overgangsverschijnselen 1
Created January 9, 2016 22:07
overgangsverschijnselen
clear all;clf;
% Overgangsgedrag: Maak een bodeplot van het tweede ordesysteem met polen :
% p1/2 = -1 +- 2pi*5j en versterking K = 2pi*5². Bereken daarna het
% impulsantwoord als volgt door middel van h = 2*real(ifft(H,2*N)) waarbij
% je dan enkel de eerste N punten gebruikt (h=h(1:N)). Construuer ook een
% tijdsvector.
polen1 = -1 + 2*pi*5*j;
polen2 = -1 - 2*pi*5*j;
K = (2*pi*5).^2;
@dugagjin
dugagjin / lineaire tijdsinvariante systemen 1
Last active January 9, 2016 22:08
lineaire tijdsinvariante systemen
% Maak de FRF van een eerste ordesysteem, gegeven de transferfunctie: H(jw)
% = A/1+jw*Tau. Waarbij Tau = 0.5 en A = 1. Maak een Bodeplot, duid het -3 dB punt
% aan door middel van een rood cirkel.
clear all;clf;
A = 1;
Tau = 1/2;
w = linspace(0,100,10000);
s = j * w;
H = A ./ (Tau*s+1);
@dugagjin
dugagjin / onderdrukking leakage
Last active January 9, 2016 21:04
onderdrukking leakage
clear all; clf;
figure(1);
Fs = 1024;
Ts = 1/Fs;
f1 = 20.5;
f2 = 200.5;
N = 1024;
Te = N*Ts;
@dugagjin
dugagjin / leakage 1
Last active January 24, 2016 01:11
leakage
% Maak een sinus met f = 2 Hz, en bemonster deze met fs = 10 Hz. Neem N =
% 10,11,...,15. Plot telkens het tijdssignaal en het frequentiespectrum.
% Herschaal het frequentiespectrum met N om de invloed van het aantal
% punten op de schaling van het spectrum te ontwijken.
clear all; clf;
Te = 1;
f = 2;
Fs = 10; % Samplefreqentie
Ts = 1/Fs; % periode