Show newer

已更新到 Mastodon v3.4.1 (实际上是更新到latest commit),两三个月没合代码,rebase了一早上 :genshin_hutao_yawn:

王小美 boosted

KMP算法实现字符串匹配和替换,JS ver.

class Solution {
  public static matchTable(str: string) {
    const strLen = str.length;
    const table: number[] = [];
    for (let pos = 0; pos < strLen; pos++) {
      let prefix: string[] = [];
      let suffix: string[] = [];
      for (let cursor = 0; cursor <= pos; cursor++) {
        prefix.push(str.slice(0, cursor));
        suffix.push(str.slice(cursor + 1, pos + 1));
      }
      prefix = prefix.filter((s) => s);
      suffix = suffix.filter((s) => s);
      const match: string[] = [""];
      prefix.forEach((pf) => {
        suffix.forEach((sf) => {
          if (pf === sf) {
            match.push(pf);
          }
        });
      });
      table.push(Math.max(...match.map((s) => s.length)));
    }
    return table;
  }

  public static matchString(target: string, search: string): number {
    const matchTable = this.matchTable(search);
    const targetLen = target.length;
    const searchLen = search.length;
    if (targetLen < searchLen) return -1;
    let pos = 0;
    while (pos <= targetLen - searchLen) {
      for (let cursor = 0; cursor < searchLen; cursor++) {
        if (target[pos + cursor] === search[cursor]) {
          if (cursor === searchLen - 1) {
            return pos;
          } else {
            continue; // for
          }
        } else {
          pos += cursor + 1 - matchTable[cursor];
          break; // for
        }
      }
    }
    return -1;
  }

  public static replace(A = "hello world", B = "hello", C = "Mars") {
    const lenA = A.length;
    const lenB = B.length;
    let res = A;
    const pos = this.matchString(res, B);
    if (pos >= 0) {
      res = res.slice(0, pos) + C + res.slice(pos + lenB, lenA);
      return res;
    } else {
      this.replace(res, B, C);
    }
    return res;
  }
}

console.log(Solution.replace("hello world", "world", "mars"));
王小美 boosted

埋头写了一个月,没跑eslint,今天一跑完蛋 :genshin_diona_restless:

王小美 boosted
王小美 boosted

Vue3 useKeepAliveWindowScrollTop hook 

import { onDeactivated, watch, onActivated } from 'vue'
import { useWindowScroll } from '@vueuse/core'
import { useState } from '@/hooks'

export default function () {
  const { scrollTop, scrollLeft } = (function () {
    const { x, y } = useWindowScroll()
    return { scrollTop: y, scrollLeft: x }
  })()

  const [scrollTopCache, setScrollTopCache] = useState(0)
  const [isScrollTopSet, setIsScrollTopSet] = useState(false)

  watch(scrollTop, (value) => {
    if (!isScrollTopSet.value) return
    setScrollTopCache(value)
  })

  onActivated(() => {
    window.scrollTo(scrollLeft.value ?? 0, scrollTopCache.value)
    setIsScrollTopSet(true)
  })

  onDeactivated(() => {
    setIsScrollTopSet(false)
  })
}
王小美 boosted
王小美 boosted
王小美 boosted
王小美 boosted
王小美 boosted
王小美 boosted

等了三年终于返场了,阿离是我玩的最多的一个英雄,可惜今年那个牛年限定皮肤的手感不好,创造营那个bulinbulin的不舒服,花间舞嘛,用了上千局,确实有点腻了 :weibo_d_erha:

王小美 boosted

Congratulations to Day 3's winners @ElySimpTq, @Wolfthedark15! Please send the required information to arknights.event@yo-star.com. Retweet the original post each day and you might have a chance to win all the rewards!

Arknights_EN: Dear Doctor, we're holding a giveaway event to celebrate Arknights' 1.5 anniversary. Retweet this post with your wish (words or images) for Arknights and 2 tags: , and you will get a chance to win the following rewards!

:sys_twitter: twitter.com/ArknightsEN/status

Update

@use 'sass:math';
@mixin _flex-gap($gap, $row: true, $wrap: false) {
  $margin: math.div($gap, 2);
  $transform: calc(#{$margin} * -1);
  $size: calc(100% + #{$margin} * 2);
  @if $row {
    margin-left: #{$transform};
    width: #{$size};
  } @else {
    margin-top: #{$transform};
    height: #{$size};
  }
  > * {
    @if $row {
      margin-left: $margin;
      margin-right: $margin;
    } @else {
      margin-top: $margin;
      margin-bottom: $margin;
    }
  }
}

@mixin flex-gap($gap, $flex-flow: 'row nowrap') {
  @if $flex-flow== 'row nowrap' or $flex-flow== 'row-reverse nowrap' {
    @include _flex-gap($gap, true);
  } @else if $flex-flow== 'column nowrap' or $flex-flow== 'column-reverse nowrap' {
    @include _flex-gap($gap, false);
  } @else {
    @include _flex-gap($gap, true, true);
    @include _flex-gap($gap, false, true);
  }
}
Show thread
Show older
小森林

每个人都有属于自己的一片森林,也许我们从来不曾走过,但它一直在那里,总会在那里。迷失的人迷失了,相逢的人会再相逢。愿这里,成为属于你的小森林。