Skip to content

Instantly share code, notes, and snippets.

@c7x43t
c7x43t / BigIntToUInt16ArraySerialization.js
Last active April 13, 2023 10:53
Serialize a javascript BigInt space efficient and fast to an UInt8Array and back.
const big_zero = BigInt(0);
const big_16 = BigInt(16);
const big_2p16m1 = BigInt(2**16-1); // 0xFFFFn
function bigIntToUint16Array(bigInt) {
const bitLength = Math.ceil(Math.log2(Number(bigInt) + 1));
const arrayLength = (bitLength + 15) >>> 4;
const uint16Array = new Uint16Array(arrayLength);
let tempValue = bigInt;
for (let i = 0; i < arrayLength; i++) {
日立製作所は4日、家電量販店などが勝手に値引きできない家電の「指定価格制度」を始めた。長年、量販店に握られてきた価格の決定権をメーカーの手に戻そうとする動きで、国内家電大手ではパナソニックに次ぐ2社目。今後、業界でどこまで広がるかが注目される。 子会社の日立グローバルライフソリューションズ(GLS)が4日、11月に発売する最新のドラム式洗濯乾燥機「ビッグドラム」2機種を発表した。価格は洗濯容量13キロの製品が37万円前後(税込み)、12キロが33万円前後(同)の予定。価格は日立による指定で、制度に参加する量販店や通販サイトなど、「正規取扱店」約1万5千店舗で販売する。 メーカーによる価格の拘束は独占禁止法で禁じられている。ただ、今回の制度は店からの返品を受け付け、売れ残りのリスクを日立が負う形にすることで、法的な問題をクリアしたという。今後、11月以降に発売する洗濯機や冷蔵庫などの白物家電の1割程度、主に付加価値の高い製品を対象にする見込みだ。
@c7x43t
c7x43t / magento.sh
Created December 15, 2023 13:02
Notes on magento and how to execute commands without memory limit and with debug information.
Essentially:
PHP_MEMORY_LIMIT=-1 php -d memory_limit=-1 -d display_errors=1 -d display_startup_errors=1 bin/magento {command} -vvv
PHP_MEMORY_LIMIT=-1 php -d memory_limit=-1 -d display_errors=1 -d display_startup_errors=1 bin/magento deploy:mode:set production -vvv
PHP_MEMORY_LIMIT=-1 php -d memory_limit=-1 -d display_errors=1 -d display_startup_errors=1 bin/magento indexer:reindex -vvv
PHP_MEMORY_LIMIT=-1 php -d memory_limit=-1 -d display_errors=1 -d display_startup_errors=1 bin/magento deploy:mode:set default -vvv
php bin/magento maintenance:status
php bin/magento maintenance:disable
@c7x43t
c7x43t / flexsearch.fuzzy.js
Created October 29, 2024 16:13
Flexsearch fuzzy search
// Initialize a FlexSearch Document index with typo-tolerance and partial matching for products
const flexIndex = new FlexSearch.Document({
preset: 'match',
charset: "latin:advanced",
tokenize: "full",
resolution: 20,
document: {
id: "id",
index: [
{
const campaigns = [
@foreach($facebookCampaigns as $campaign)
{ id: '{{ $campaign->id }}', text: `{!! addslashes($campaign->name) !!}` },
@endforeach
];
window.campaigns = campaigns;
const products = [
@foreach($wooCommerceProducts as $product)
{ id: '{{ $product->product_id }}', text: `{!! addslashes($product->name) !!}` },
@endforeach
// Motivation:
var formatted = new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR',
}).ormat(1332123.55);
// This will format currency however 1 million iterations take 27.000 ms
// Caching the formatter is faster at 440 ms
var formatter = new Intl.NumberFormat('de-DE', {
style: 'currency',
currency: 'EUR',