野狗API的初步使用

作为一名热爱探索的的前端工程师,业余时间的追求一点点新技术也是日常便饭。众里寻他千百度,在偶然的机会下,我遇到了你,第一次看到你的官方网页



我就爱上了你,就想探索你。简约的官方风格,不高调,不奢华,有着和谷歌般的设计规则。我甚至喜欢,然后就迫不及待的注册开发你。



因此好不犹豫的注册了你,并新建了2个appid。
我是前端程序员,理想是做一个全栈工程师,不能成为全栈工程师,也愿意做一名全干工程师。可惜后端不会,但是野狗可以。这个为开发提供方便的数据存储方式,并可以实时通信,太牛逼了。于是就开发了第一个利用野狗的小程序。聊天室,





这是注册页面,每个人都有唯一的id好,随机的注册后进入调用野狗实例的页面



进入里面就可以聊天了,当您已经注册了,就可以直接进去聊天。用的localStorage存储用户信息



利用野狗api可以查询自己所需要的数据,同时可以删除自己想要的数据,对于不会开发服务器的后端人员,提供了极大的方便。同时运行速度很快,差不多比cdn上的数据还快点。很是牛逼
var ref = new Wilddog("https://john.wilddogio.com/");
主要api有


```
请输入代码


    ```ref.on("value", function(snapshot) {
                            $(".commentDiv").empty();
                            var count = 0;
                            snapshot.forEach(function(item) {
                                if (item.child("nicname").val() == userName) {
                                    count++;
                                    $(".commentDiv").append('<p class="' + item.key() + '">' + item.child("nicname").val() + ':' + item.child("sayword").val() + '</p>');
                                }
                            })
                            if (count == 0) {
                                $(".commentDiv").append('<p style="margin-top:100px;width:100%;text-align:center" class="noRecord">' + '没有这个人的记录</p>')
                            }
                            ref.off("value");
                    


```这是删除


     ref.on('child_removed', function(snapshot) {
                    console.log("=============child_removed==========================");
                    console.log(snapshot.child("sayword").val());
                    $("p." + snapshot.key()).remove();
                });


```
github地址:http://holidaying.github.io/widdog/comment.html。请大家批评指出。
同时野狗公众号我也一直关注者,不得不说野狗推送的文章都是干货。

几乎野狗推送的文章,我都看过,每天早上上班的时候,公交车里打开的订阅号看到的文章也是你。在前端的路上
我会一直支持你们,希望你们的产品越来越多的人知道,希望你们能帮助更多的人。









       
野狗优化算法是一种基于种群的全局优化算法,其灵感来源于野狗捕食时的行为。这种算法的主要特点是通过不断的迭代和自适应调整来找到最优解。下面是野狗优化算法的Python代码示例: ```python import numpy as np class WOA: def __init__(self, func, dim, max_iter=100, lb=-100, ub=100, population=10): self.func = func self.dim = dim self.max_iter = max_iter self.lb = lb self.ub = ub self.population = population def init_population(self): return np.random.uniform(low=self.lb, high=self.ub, size=(self.population, self.dim)) def get_fitness(self, population): fitness = np.zeros(self.population) for i in range(self.population): fitness[i] = self.func(population[i]) return fitness def update_position(self, population, leader_pos): a = 2 - 2 * np.linspace(0, 1, self.max_iter) ** 2 r1 = np.random.rand(self.population, self.dim) r2 = np.random.rand(self.population, self.dim) A = 2 * a * r1 - population) new_population = leader_pos - A * D return new_population def run(self): population = self.init_population() fitness = self.get_fitness(population) best_index = np.argmin(fitness) best_fitness = fitness[best_index] best_position = population[best_index] for i in range(self.max_iter): a = 2 - 2 * (i / (self.max_iter - 1)) ** 2 A = 2 * a * np.random.rand(self.dim) - a C = 2 * np.random.rand(self.dim) b = 1 l = (a - 1) * np.random.rand() + 1 p = np.random.rand() if p < 0.5: if np.abs(A) < 1: new_population = self.update_position(population, best_position) else: rand_leader_index = np.random.randint(0, self.population) rand_leader_pos = population[rand_leader_index] new_population = self.update_position(population, rand_leader_pos) else: distance_to_leader = np.abs(C * best_position - population) new_population = distance_to_leader * np.exp(b * l) * np.cos(2 * np.pi * l) + best_position new_population[new_population < self.lb] = self.lb new_population[new_population > self.ub] = self.ub new_fitness = self.get_fitness(new_population) new_best_index = np.argmin(new_fitness) if new_fitness[new_best_index] < best_fitness: best_fitness = new_fitness[new_best_index] best_position = new_population[new_best_index] population = new_population fitness = new_fitness return best_position, best_fitness ``` 以上是一个简单的野狗优化算法的Python实现,需要提供目标函数、维度、最大迭代次数、上下界和种群大小等参数。在`run()`方法中进行算法的迭代,并返回最优解及其对应的函数值。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

西安小哥

劳动不易

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值