Skip to content

Instantly share code, notes, and snippets.

View amcsi's full-sized avatar
🏠
Working from home

Attila Szeremi amcsi

🏠
Working from home
View GitHub Profile
@amcsi
amcsi / responseEnvelope.ts
Created February 8, 2024 11:06
Response envelope
type ResponseEnvelopeYuki<T> = ResponseEnvelopeSuccess<T> | ResponseEnvelopeFailure;
type ResponseEnvelopeSuccess<T> = {
success: true;
} & T;
type ResponseEnvelopeFailure = {
success: false;
errorMessage: string;
import { useSelector, useDispatch } from 'react-redux';
import { useState, useEffect } from 'react';
function EditPostComponent({id}) {
const dispatch = useDispatch();
// The initially loaded post
const post = useSelector(state => state.posts.postData);
useEffect(() => {
public static function provideCreate()
{
return [
[new Expectation('The password must be at least 9 characters.', 'pass')],
[new Expectation('The password must contain at least one uppercase and one lowercase letter.', 'passwordx')],
[new Expectation('The password must contain at least one number.', 'Passwordx')],
[new Expectation("Your chosen password is not secure enough: This is a very common password. Add another word or two. Uncommon words are better. Capitalization doesn't help very much.", 'Password1')],
[new Expectation("Your chosen password is not secure enough: This is similar to a commonly used password. Add another word or two. Uncommon words are better. Capitalization doesn't help very much. Predictable substitutions like '@' instead of 'a' don't help very much.", 'P@ssw0rd1')],
[new Expectation('Your chosen password is not secure enough: Repeats like "abcabcabc" are only slightly harder to guess than "abc". A
function useWebsocketWithCallback(callback, ...args) {
const {lastMessage} = useWebsocket(...args);
const lastMessageRef = useRef();
lastMessageRef.current = lastMessage;
useEffect(() => {
if (lastMessage !== lastMessageRef.current) {
callback(lastMessage);
}
}, [lastMessage]);
}