Giter Site home page Giter Site logo

experiences-for-coding's Issues

Javascript异步理解

直接扔代码

interface TaskFunction {
    (done: (result?: any) => void): void;
}

function all(taskFns: TaskFunction[], callback: (results: any[]) => void): void {
    var results: string[] = []; 

    var pending = taskFns.length;

    taskFns.forEach((taskFn, index) => {
        taskFn(result => {
            if (index in results) {
                return;
            }

            results[index] = result;

            if (--pending == 0) {
                callback(results);
            }
        });
    });
}

all([
    done => {
        done('hello');
    },
    done => {
        setTimeout(() => {
            done(', ');
        }, 100);
    },
    done => {
        setInterval(() => {
            done('world');
        }, 1000);
    },
    done => {
        done('!');
    }
], results => {
    console.log(results.join('')); // 输出 hello, world!
})

关于大范围使用in_array的效率问题

在循环中的in_array()问题

昨天做一个时间匹配的时候需要大范围内的进行循环对比 我的思路是循环用in_array()对比是否包含某个字,立神说循环次数太多了... 原来要将要查找的值直接转换成键,然后去对比等不等于,这样是黑红二分叉查询。要比我的思路快很多~~

Laravel Eloquent ORM获取的数据格式

之前认为laravel取多条数据的时候因为拿到的单条数据是一个对象,所以认为每个记录拿出来都要执行一次toArray()方法.

但是... 没有好好读文档的错啊. 在review的时候被立神看出来了

$bmlist  = Appointment::all();
$baoming = [];

foreach ($bmlist as $bm) {
    $baoming[] = $bm->toArray();
}

return $baoming;

改进后的代码:

$baoming = Appointment::all()->toArray();
return $baoming;

看自己绕这么大个弯儿好像说句fuck!

linux环境变量相关

在自己home目录里可以找到相对应的.bash*文件

  • .bashrc 这里可以添加一些自定义的sh命令,可以很方便的执行
  • .bash_history 这个文件主要负责记录用户所操作的命令 对于记录的量是可以设置的
  • .bash_profile 这个文件是系统的每个用户设置环境信息,当用户第一次登录时,该文件被执行.
  • .bash_logout 这个文件在用户退出是会被执行

线性表

具有像线一样性质的表,由零个或者多个数据元素构成的有限序列.

Laravel的composer包开发

之前开发由于用到一个短信平台的SDK,就为Laravel专门开发了这个平台的SDK包.基于composer的.

但是把逻辑代码全部实现以后测试的时候发现通过LaravelConfig类的get()方法拿不到自定义的配置项. 百思不得其解找了很久.

最后发现,是在用Config::get()方法获取配置的时候包名和配置名大小写的问题而导致的...

代码层面的设计

写着写着突然发现在代码的实现上有很大的改进空间.

之前写的代码很乱,发现在把代码模块化,低耦合重构后会好很多,也可以让别人看上去思路更清晰.

还有利于编写单元测试.. (捂脸...能说写的次数真心不多么..)

Win10下Homestead无法启动解决办法

There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: E_FAIL
VBoxManage.exe: error: Failed to create the host-only adapter
VBoxManage.exe: error: Code E_FAIL (0x80004005) - Unspecified error (extended info not available)
VBoxManage.exe: error: Context: "int __cdecl handleCreate(struct HandlerArg *,int,int *)" at line 66 of file VBoxManageHostonly.cpp

出现这个问题的时候帮朋友解决掉了,但是发现其实网络还是没有通的,后来发现它是用一个类似来宾用户登录的. 然后给到一些权限连接的virtualbox里面的机子.

但是发现只适用于部分用户!

然后win7同样出现了这样的问题. 百思不得其解. 然后猜测是无权限创建与虚拟机外的主机的共享文件夹. 在这样的猜测下,试着,试着将homestead.yaml里的共享文件夹下面的nfs.png关掉以后,顺利开启.

image

那么这个nfs是个什么东西呢?下面的百度给出的解释:

NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。

这样看来确实是vagrant的配置在virtualbox与外部主机进行通信的时候发生问题了呢...
然而对这块不大明白,还没找到个所以然.. 如有疏忽的地方,欢迎大牛指正~

virtualbox报R3问题

Unable to load R3 module D:\app\virtualbox/VBoxDD.DLL (VBoxDD): GetLastError=1790 (VERR_UNRESOLVED_ERROR).

这是我的错误日志,是使用vagrant的过程中虚拟机打不开找到的.百思不得其解,google之~ 发现这里出现的问题主要是因为windows7的三个主题破解文件引起的,在网上有专门针对恢复的一种工具UniversalThemePatcher! 前车之鉴....

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.