Skip to content

Instantly share code, notes, and snippets.

View yjaaidi's full-sized avatar
💭
👨🏻‍🍳 helping you cook better apps

Younes Jaaidi yjaaidi

💭
👨🏻‍🍳 helping you cook better apps
View GitHub Profile
@yjaaidi
yjaaidi / ngx-light-hello.html
Created June 11, 2022 14:23
Tinest Angular App
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>👨🏻‍🍳🅰️ Ngx Light by Younes @ Marmicode.io</title>
<meta name="description" content="👨🏻‍🍳🅰️ Ngx Light" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<script type="importmap">
{
"imports": {
@yjaaidi
yjaaidi / switch-map-on-next.js
Created September 2, 2022 18:07
switchMapOnNext rxjs operator
import * as rx from 'rxjs';
const delays = [3000, 2000, 500];
const switchMapOnNext = (project) => (source) => {
return new rx.Observable((observer) => {
let previousSubs = new rx.Subscription();
const subscription = source.subscribe((value) => {
const result$ = project(value);
const currentPreviousSubs = previousSubs;
@yjaaidi
yjaaidi / ngx-light.html
Last active June 11, 2022 14:22
Tiniest Angular Setup Ever
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>👨🏻‍🍳🅰️ Ngx Light by Younes @ Marmicode.io</title>
<meta name="description" content="👨🏻‍🍳🅰️ Ngx Light" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<script type="importmap">
{
"imports": {
@yjaaidi
yjaaidi / wait-latest-from.ts
Created April 28, 2022 07:36
RxJS waitLatestForm
import { switchMap } from 'rxjs/operators';
action$;
state$; // facade.country$ etc...
repository$;
fetch$.pipe(withLatestFrom(facade.country$));
waitLatestFrom = (action$) =>
action$.pipe(
@yjaaidi
yjaaidi / prerender-clean-up.js
Last active February 1, 2022 17:01 — forked from imevro/gist:edfe9dea12196056467f
Clean up all cached pages in prerender.io from console
const cleanUp = async () => {
const response = await fetch('https://prerender.io/api/cached-pages?page=0&pageSize=100');
const itemList = await response.json();
const csrfToken = document.cookie.replace(/^.*XSRF-TOKEN=/, '').replace(/;.*$/, '');
const promiseList = itemList.map(item => fetch(`https://prerender.io/api/remove-cached-url?url=${encodeURIComponent(item.url)}`, {
method: 'DELETE',
headers: {
@yjaaidi
yjaaidi / storybook-custom-elements-reload-hack.js
Created January 8, 2021 10:37
Storybook Angular Custom Elements reload hack
/**
* @hack detect when story is changed and reload because custom elements
* break HMR.
* Storybook will replace storybook-dynamic-app-root's children.
* Then we reload the page to redefine elements.
*/
const rootEl = document.querySelector('#root');
rootEl.addEventListener('DOMNodeRemoved', (evt) => {
if (evt.relatedNode === rootEl) {
document.location.reload();
@yjaaidi
yjaaidi / prototype-pollution.js
Created October 2, 2019 13:24
Prototype pollution example
const u1 = {firstName: 'Foo'}
const u2 = {firstName: 'John'}
const body = JSON.parse('{"__proto__": {"admin": true}}')
function vulnerableExtend(dst, src) {
Object.entries(src)
.forEach(([k, v]) => {
if (k in dst) {
vulnerableExtend(dst[k], src[k]);
@yjaaidi
yjaaidi / +title-v1.module.ts
Last active June 7, 2019 20:34
Reactive Component Loader Demo
@Component({
selector: 'wt-title-v1',
template: `<h1>v1: {{ title }}</h1>`
})
export class TitleV1Component {
@Input() title: string;
}
@NgModule({
imports: [CommonModule],
@NgModule({
imports: [
RoutingModule.forChild([
{
path: 'catalog',
# Or, you can lazy load catalog if you wish.
component: SandwichCatalogViewComponent
}
]),
SandwichCatalogViewModule
@NgModule({
imports: [
RoutingModule.forRoot([
{
path: 'sandwich',
loadChildren: './sandwich/sandwich-views.module#SandwichViewsModule'
}
])
]
})