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
function useWebsocketWithCallback(callback, ...args) {
const {lastMessage} = useWebsocket(...args);
const lastMessageRef = useRef();
lastMessageRef.current = lastMessage;
useEffect(() => {
if (lastMessage !== lastMessageRef.current) {
callback(lastMessage);
}
}, [lastMessage]);
}
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
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(() => {
@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 PrintA from '../PrintA';
export const printConfig = {
A: {
component: PrintA,
nextTransaction: 'B',
},
B
}
<template>
<el-menu v-bind="$attrs">
<slot></slot>
</el-menu>
</template>
<script>
/** @class AMenu */
export default {
name: 'AMenu',
<?php
class ObjectStorage {
public $pairs = [];
public function add(object $objectKey, $value): void
{
$this->pairs[] = [$objectKey, $value];
}
@amcsi
amcsi / rogue.txt
Created December 11, 2021 00:30
Rogue mtg commander deck
Land
1 Access Tunnel
1 Bojuka Bog
1 Command Tower
1 Darkwater Catacombs
1 Dimir Aqueduct
11 Island
1 Myriad Landscape
1 Mystic Sanctuary
1 Path of Ancestry
@amcsi
amcsi / need_deduplication.rs
Created December 10, 2021 21:00
Rust code needing deduplication
impl<'a> SerializingCommon<'a> {
pub fn serialize_page<T>(serialized: &SerializingPage) -> SerializingCommon<'a>
{
SerializingCommon {
ancestors: &serialized.ancestors,
assets: serialized.assets,
components: serialized.components,
content: serialized.content,
description: serialized.description,
draft: serialized.draft,
async function lol() {
const responseBodies = await Promise.all([
fetch('http://example.com/1').then(response => response.json()),
fetch('http://example.com/2').then(response => response.json()),
]);
return {
list: responseBodies[0],
template_something: responseBodies[1],
}