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
@Component({
selector: 'wt-logo',
template: `
<img [src]="getLogoUrl()">
<button (click)="company = 'wishtack'">WISHTACK</button>
<button (click)="company = 'google'">GOOGLE</button>
`
})
export class LogoComponent {
@yjaaidi
yjaaidi / speech-recognition-playground.js
Last active October 11, 2018 09:03
Speech Recognition Playground
recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.lang = 'fr-FR';
recognition.onresult = console.log;
recognition.start();
@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],
@yjaaidi
yjaaidi / angular-tagged-template.ts
Created March 8, 2019 14:37
Angular Tagged Template
/**
* @todo when `deps` will be added to `Component` definition,
* we could return `{deps, template}` then use it like this:
* ```
* @Component({
* selector: 'wt-root',
* ...ngTemplate`<${Child}></${Child}>`
* })
* ```
@Component({
template: ``
})
export class AppComponent extends Renderable {
render() {
return (
<h1>Hello World!</h1>
)
}
}
@NgModule({
imports: [
RoutingModule.forRoot([
{
path: 'sandwich',
loadChildren: './sandwich/sandwich-views.module#SandwichViewsModule'
}
])
]
})
@NgModule({
imports: [
RoutingModule.forChild([
{
path: 'catalog',
# Or, you can lazy load catalog if you wish.
component: SandwichCatalogViewComponent
}
]),
SandwichCatalogViewModule
@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 / 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 / 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(