vapor

Random Alphanumeric String Linux Swift 3

醉酒当歌 提交于 2019-12-01 22:21:19
Im having 2 problems when trying to generate a random string in Linux with Swift 3. arc4random_uniform is not available in Linux only on BSD. SO i was able to get away with using random() function. And this worked when i was generating random numbers of a variable size (See code below) func generateRandomNumber() -> Int { var place = 1 var finalNumber = 0; #if os(Linux) for _ in 0..<5 { place *= 10 let randomNumber = Int(random() % 10) + 1 finalNumber += randomNumber * place } #else for _ in 0..<5 { place *= 10 let randomNumber = Int(arc4random_uniform(10)) finalNumber += randomNumber * place

How to send a POST request to Firebase Cloud Messaging API in Vapor

不想你离开。 提交于 2019-12-01 21:21:09
I am trying to make a POST request to a Firebase Notifications API using Vapor 1.5 and Firebase Legacy Protocol, but I get failure response. response is JSON(node: Node.Node.object(["multicast_id": Node.Node.number(5936281277445399934), "failure": Node.Node.number(0), "canonical_ids": Node.Node.number(0), "results": Node.Node.array([Node.Node.object(["message_id": Node.Node.string("0:1527074314969790%c7ade8b9f9fd7ecd")])]), "success": Node.Node.number(1)])) EDIT Making the request through POSTMan fails with error "The request was missing an Authentication Key (FCM Token)." class

How to use timer in Vapor (server-side Swift)?

北城以北 提交于 2019-12-01 05:22:12
Can I use timer, such as NSTimer in Vapor (server-side Swift)? I hope my server written in Vapor can do some tasks proactively once in a while. For example, polling some data from the web every 15 mins. How to achieve this with Vapor? If you can accept your task timer being re-set whenever the server instance is recreated, and you only have one server instance, then you should consider the excellent Jobs library. If you need your task to run exactly at the same time regardless of the server process, then use cron or similar to schedule a Command . Kerusan If you just need a simple timer to be

白话比原链跨链技术

荒凉一梦 提交于 2019-11-30 02:30:48
随着Bystack的主侧链架构的推出,主侧链之间的跨链问题也成为比原链团队的主要攻克工程难题,当前比原链已经推出了两种跨链的机制,各有不同的侧重点,可能因为本身的跨链技术比较晦涩,本篇想以较为通俗的方式向社区介绍比原链最新的跨链技术。 一些预备知识 跨链简单的来说就是解决如何让一条链上的token转移到另一条链上,本质是将一条链上的价值转移到另一条链,跨链需要保证以下几点: 1. 确保已跨链的资产的妥善保管,不能在原链上能够继续流通,要防止被窃取或者挪用; 2. 确保两条链上转移的资产是等同的,不能A链上减少了100价值的资产,而B链上只增加了50价值的资产; 3. 转移的资产能够安全的再转移回原链上,不能价值只是单向转移,或者转移过去无法转移回来; 基于这些要求,诞生出很多不同的跨链方案,主要是公证人机制,侧链/中继和哈希时间锁等方案,除此之外还有分布式私钥,和公证人机制+侧链混合技术。这里不对这些技术进行展开,如果有兴趣的朋友,可以推荐阅读V神给R3写的关于跨链的文章《Chain Interoperability》。 比原链的跨链选型 比原链的跨链模型也脱离不了上面叙述的跨链模型,当前主要使用的是公证人机制和哈希时间锁的模式。 因为侧链Vapor本身是没有资产的,所以我们使用公证人机制将主链的资产转移到侧链上(实际上是在主链锁定资产,在Vapor侧链创造资产)

vapor toolbox broken after upgrading swift

老子叫甜甜 提交于 2019-11-29 17:39:42
问题 Vapor toolbox is crashing when trying to use it after upgrading to Swift 3.1. dyld: lazy symbol binding failed: Symbol not found: __TTSfq4n_s___TFVSS13CharacterView38_measureExtendedGraphemeClusterForwardfT4fromVVSS17UnicodeScalarView5Index_Si Referenced from: /usr/local/bin/vapor Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib dyld: Symbol not found: __TTSfq4n_s___TFVSS13CharacterView38

Vapor server and companion iOS app examples

我怕爱的太早我们不能终老 提交于 2019-11-29 02:32:58
One of the reasons advocates of swift server side give for the use of swift is that it allows iOS developers to develop backends for their apps. But, I do not see many example of this usage pattern. There is a chat-ios example but that is using websockets. Are there any server and companion iOS app examples available? One of the difficulties of using a custom server is handling the possible poor comms in iOS app usage. I would like to see if any project out there have handled this well. One of the reasons for using parse/firebase is the builtin client side support for syncing/retry. Are there

Parameters after opening bracket

痴心易碎 提交于 2019-11-28 13:00:50
I am doing my first steps in Vapor, the web framework for Swift. The first piece of code that called my attention was this: app.get("welcome") { request in return "Hello" } I don't understand the syntax here. I mean, I'm calling app.get() method, but I'm also defining some kind of function where request is a parameter. I know that this will result in a get method accessible by a /welcome URL and will return "Hello". What is not clear for me is how this piece of code works and how the compiler interprets it. Alexander This is called trailing closure syntax . I give a nice rundown of the various

Vapor server and companion iOS app examples

て烟熏妆下的殇ゞ 提交于 2019-11-27 16:48:01
问题 One of the reasons advocates of swift server side give for the use of swift is that it allows iOS developers to develop backends for their apps. But, I do not see many example of this usage pattern. There is a chat-ios example but that is using websockets. Are there any server and companion iOS app examples available? One of the difficulties of using a custom server is handling the possible poor comms in iOS app usage. I would like to see if any project out there have handled this well. One

Parameters after opening bracket

点点圈 提交于 2019-11-27 07:16:40
问题 I am doing my first steps in Vapor, the web framework for Swift. The first piece of code that called my attention was this: app.get("welcome") { request in return "Hello" } I don't understand the syntax here. I mean, I'm calling app.get() method, but I'm also defining some kind of function where request is a parameter. I know that this will result in a get method accessible by a /welcome URL and will return "Hello". What is not clear for me is how this piece of code works and how the compiler

Can't access FireBase Database via HTTP/REST error 403 Forbidden

安稳与你 提交于 2019-11-27 01:45:59
Swift + Vapor framework for server + Xcode 8.1 I am trying to read Firebase Realtime Database making HTTP requests to my DB, but I get permission denied. These are the steps: 1. create JWT sign it with secret key downloaded from "console.developers.google.com" 2. send POST request to OAuth2 server and get access token 3. send GET request to firebase database with access token received from OAuth2 server. I get "Permission denied", HTTP/1.1 403 Forbidden // the header of the JSON Web Token (first part of the JWT) let headerJWT = ["alg":"RS256","typ":"JWT"] // the claim set of the JSON Web Token