群组信息 私有

administrators

 

成员列表

  • redis init
    #!/bin/sh
    #
    # Redis init script
    #
    # chkconfig:   - 85 15
    # description:  Redis is a persistent key-value database
    # processname:  redis-server
    
    ### BEGIN INIT INFO
    # Provides:       redis-server
    # Required-Start: $syslog
    # Required-Stop:  $syslog
    # Should-Start:   $local_fs
    # Should-Stop:    $local_fs
    # Default-Start:  2 3 4 5
    # Default-Stop:   0 1 6
    # Short-Description: Redis data structure server
    # Description:     Redis is a persistent key-value database
    ### END INIT INFO
    
    REDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    CLIEXEC=/usr/local/bin/redis-cli
    
    PIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/etc/redis/redis.conf"
    
    case "$1" in
        start)
            if [ -f $PIDFILE ]
            then
                echo "$PIDFILE exists, process is already running or crashed"
            else
                echo "Starting Redis server..."
                $EXEC $CONF
            fi
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                echo "$PIDFILE does not exist, process is not running"
            else
                PID=$(cat $PIDFILE)
                echo "Stopping Redis server..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown..."
                    sleep 1
                done
                echo "Redis stopped"
            fi
            ;;
        restart|force-reload)
            ${0} stop
            ${0} start
            ;;
        *)
            echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
            exit 1
    esac
    
    exit 0
    
    
    发布在 笔记
  • RE: useContext in useEffect 发布在 笔记
  • useContext in useEffect

    If you want to do it right with useEffect, you must ensure all dependencies are used in the second param. What happens if you have context as dependencies, and useEffect also changes the state of context - it will go into the infinite loop.
    Can we more useContext into useEffect? Not directly, because it against the rule of hook.

    Here is the solution using useRef.

    
      const ssOptionRef = useRef(useContext(OptionContext));
      useEffect(() => {
        const currentOptions = {
          ag: myAg,
          gender: myGender,
          event: myEvent,
          type: myType,
          scope: myScope,
        };
    
        // this is briliant - https://stackoverflow.com/questions/56240067/accessing-context-from-useeffect
        const [allOptions, setAllOptions] = ssOptionRef.current;
    
        const newOptions = { ...allOptions, ...currentOptions };
        setAllOptions(newOptions);
    
        setSSOptionsCookie(currentOptions);
      }, [myEvent, myScope, myAg, myGender, myType]);
    

    Note that there is no initialization of context when the route changes. The initialization only happens when the page is reloaded.

    发布在 笔记
  • edit video using premiere
    1. chose seq
    2. drag source into sequence
    3. under effect controls - update scale to 110, and adjust position
    4. split and cut using ctr+k to split, and select portion to ripple delete
    5. choose start using keyboard "i" and end using keyboard "o"
    6. ctrl + m to see export menu
    发布在 笔记
  • about peerDependencies

    In a package.json file, PeerDependencies are used to specify any packages that the current package requires to function properly, but should not be bundled with the package during installation. Instead, the PeerDependencies will be installed as a separate dependency of the consuming package, ensuring that only one version of the package is installed across all dependencies that require it. This helps to reduce duplication of code and potential conflicts between different versions of the same package. PeerDependencies are typically used for packages that provide interfaces or APIs that other packages need to use, such as plugins or libraries.


    Yes, it can be difficult to ensure that only one version of a package is installed across all dependencies that require it, especially if multiple packages have different version requirements for the same PeerDependency.

    However, by using PeerDependencies in combination with careful management of package versions and updating dependencies regularly, it is possible to minimize the risk of conflicts and ensure that the required packages are installed correctly.

    Some best practices for managing PeerDependencies include:

    Clearly defining the required versions of PeerDependencies in the package.json file
    Keeping all dependencies up to date to minimize version conflicts
    Testing the package with all required PeerDependencies to ensure compatibility
    Documenting the required PeerDependencies for users of the package
    Overall, while it may not always be straightforward to manage PeerDependencies, they can be a valuable tool for ensuring that packages function properly and that dependencies are installed efficiently.

    发布在 笔记
  • nextjs scrollRestoration

    By default nextjs auto scroll to the top when the router changes. Most of time, this what we wanted, but sometimes, we would like scroll could be restored, especially, user uses "Back" or "Forward" navigation.
    Here is my way:

    1. set scrollRestoration to true. in next.config.js
    2. use javascript to scroll to the top when the page is newly loaded
     isNavigation = false;
    
      handleRouteChange = (url) => {
        console.log("User navigated to:", url);
        gtag.pageview(url);
        
        if (!this.isNavigation) {
          console.log("scroll to top when load a new page");
          // console.log("URL", url);
          this.timerHandle = setTimeout(() => {
            window.scrollTo(0, 0);
            this.timerHandle = 0;
          }, 100);
    
          this.isNavigation = false;
        }
    
        NProgress.done();
      };
    
      handleBeforePopState = ({ url, as, options }) => {
        console.log("User navigated backwards or forwards");
        this.isNavigation = true;
        // Do something when user navigates back or forward
        return true;
      };
    
      handleStart = (url) => {
        // console.log(`Loading: ${url}`);
        NProgress.start();
      };
      handleStop = () => {
        NProgress.done();
      };
    
    componentDidMount = async () => {
        Router.events.on("routeChangeComplete", this.handleRouteChange);
        Router.events.on("routeChangeStart", this.handleStart);
        Router.events.on("routeChangeError", this.handleStop);
        Router.beforePopState(this.handleBeforePopState);
      };
    
      componentWillUnmount = () => {
        Router.events.off("routeChangeComplete", this.handleRouteChange);
        Router.events.off("routeChangeStart", this.handleStart);
        Router.events.off("routeChangeError", this.handleStop);
        Router.beforePopState(() => true);
        if (this.timerHandle) {
          // Yes, clear it
          clearTimeout(this.timerHandle);
          this.timerHandle = 0;
        }
      };
    
    发布在 笔记
  • RE: mongodb is so good

    Also, the index is super important in MongoDB. Don't forget you can create an index on a field that will be created.

    发布在 笔记
  • mongodb is so good

    We can update 'array' filed with a unique value with "$addToSet". How amazing is it? I used to get the field value, check the new data is in the array or not, and save the array back.

    urls = [j.url for j in a.followers]
    db.graph.update_one({"user_id": a.url}, {"$addToSet": {"following": {"$each": urls}}})
    

    The best way to do this is using $addToSet operator which ensures that there are no duplicate items added to the set and the $each modifier to add multiple values to the"following" array.

    REF: https://stackoverflow.com/questions/36518635/avoid-a-duplicate-value-when-i-update-array-using-push-on-mongodb

    发布在 笔记
  • Try to understand how to move project to ESM 发布在 笔记
  • cannot login Teams

    Cannot login Teams after messing up the 2FA in MAC.
    Finally fixed it by re-login in Safari. Somehow the corp mac linked the MS account in Safari.

    发布在 笔记