Skip to content

Instantly share code, notes, and snippets.

View Herve07h22's full-sized avatar

Herve Herve07h22

View GitHub Profile
@Herve07h22
Herve07h22 / commit_messages.md
Last active August 7, 2024 10:07
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@Herve07h22
Herve07h22 / block.ts
Created June 23, 2023 12:14
Pattern matching instead of Visitor pattern
import { match, P } from "ts-pattern";
const headerBlocType = {
Header: "header",
Paragraph: "paragraph",
Image: "image",
} as const;
interface HeadBlockData {
text: string;
@Herve07h22
Herve07h22 / self-attention.py
Created March 30, 2023 16:05
Example of self-attention model
import torch
import torch.nn as nn
class SelfAttention(nn.Module):
def __init__(self, embed_size, heads):
super(SelfAttention, self).__init__()
self.embed_size = embed_size
self.heads = heads
self.head_dim = embed_size // heads
@Herve07h22
Herve07h22 / Evaluation.ts
Last active March 10, 2023 15:04
Sample question/answer kata
import { makeAutoObservable } from "mobx";
type Choice = {
id: number;
text: string;
};
type Question = {
id: number;
text: string;
@Herve07h22
Herve07h22 / useObserver.ts
Last active December 16, 2022 12:32
Observable/Observer in React with 65 lines of TypeScript
import { useEffect, useState } from "react";
class EventBus<T> {
_handlers: Set<(t: T) => void> = new Set();
subscribe(handler: (t: T) => void) {
this._handlers.add(handler);
}
unsubscribe(handler: (t: T) => void) {
this._handlers.delete(handler);
}
@Herve07h22
Herve07h22 / counterSlice.js
Created May 28, 2021 12:40
Pourquoi je préfère les hooks
// Avec readux toolkit :
import { createSlice } from '@reduxjs/toolkit'
export const counterSlice = createSlice({
name: 'counter',
initialState: {
value: 0,
},
reducers: {
increment: (state) => {
@Herve07h22
Herve07h22 / FriendLine.js
Last active April 12, 2021 15:43
React MVVM with hooks
import {useFriend} from '../model/useFriend'
export function FriendLine ({friend}) {
const {fullname, deleteFriend} = useFriend(friend)
return (<tr>
<td>{fullname}</td>
<td><button onclick={deleteFriend} /></td>
</tr>);
}
@Herve07h22
Herve07h22 / FriendViewModel.js
Created April 12, 2021 15:06 — forked from jouana/BindingHook.js
React MVVM example
class FriendViewModel {
_personalId;
_friend;
constructor(personalId, friend) {
this._personalId = personalId;
this._friend = friend;
}
delete() {
@Herve07h22
Herve07h22 / firestoreProvider.js
Last active February 21, 2024 09:27
React-admin data & auth provider for Firebase and Firestore
// Implement a firestore data provider for react-admin
import {
GET_LIST,
GET_ONE,
CREATE,
UPDATE,
UPDATE_MANY,
DELETE,
DELETE_MANY,