Splitting in Dart - dart

How to Spilt this paymentUrl.
const _paymentUrl =
'bitcoin:3QF3iP4PZPw51qB5w6Jpo8j7P4AXyS83ra?amount=0.00107000';
TO Get
{Address: "3QF3iP4PZPw51qB5w6Jpo8j7P4AXyS83ra", Amount: "0.00107000"}

It looks like a URI, and is named like a URI, so try using the Uri class:
const _paymentUrl =
'bitcoin:3QF3iP4PZPw51qB5w6Jpo8j7P4AXyS83ra?amount=0.00107000';
var bcUri = Uri.parse(_paymentUrl);
var address = bcUri.path;
var amount = bcUri.queryParameters["amount"];
var map = {"Address": address, "Amount": amount};

it seems the ? is always there, so you can split it based on it like this:
const _paymentUrl = 'bitcoin:3QF3iP4PZPw51qB5w6Jpo8j7P4AXyS83ra?amount=0.00107000';
List<String> splitPayment = _paymentUrl.split('?');
String bitcoin = splitPayment[0];
String amount = splitPayment[1];

Related

get address line in Arabic from coordinates

Am using Geocoder plugin to get address line, country, postal code, .... like this:
final coordinates = new Coordinates(26.328446, 50.153868);
var addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = addresses.first;
print(addresses);
print("${first.featureName} : ${first.addressLine}");
and this returns:
flutter: Zarqa Al Yamamah Street : Zarqa Al Yamamah Street - Al Dana Al Jenobiah, Dhahran 34453, Saudi Arabia
I want to get the same result but in Arabic .. is there is a way to achieve this with this plugin? or there is any other plugins can return address for me in Arabic?
You can get the language code ar or ar-SA. So you need to do this:
Locale loc = new Locale("ar");
Geocoder geocoder = new Geocoder(this, loc);
or this way
geocoder = new Geocoder(this, Locale.ar_SA))
Your code can be like this
Locale loc = new Locale("ar");
Geocoder geocoder = new Geocoder(this, loc))
final coordinates = new Coordinates(26.328446, 50.153868);
var addresses = await Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = addresses.first;
print(addresses);
print("${first.featureName} : ${first.addressLine}");
Do it like this:
Geocoder geocoder;
List<Address> addresses;
geocoder = new Geocoder(this, Locale.ar_SA))
addresses = geocoder.getFromLocation(latitude, longitude, 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
String address = addresses.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
String city = addresses.get(0).getLocality();
String state = addresses.get(0).getAdminArea();
String country = addresses.get(0).getCountryName();
String postalCode = addresses.get(0).getPostalCode();
String knownName = addresses.get(0).getFeatureName(); // Only if available else return NULL
See this example:
import 'package:locales/locales.dart';
import 'package:locales/currency_codes.dart';
import 'package:intl/intl.dart';
void main() {
final locale = Locale.ar_SA;
final currencyCode = CurrencyCode.sar;
final format = NumberFormat.simpleCurrency(
locale: '$locale', name: '$currencyCode', decimalDigits: 2);
print(locale);
print(currencyCode);
print(format.format(123.456));
}
https://github.com/jifalops/locales
If you want to use specific local you must use apiKey
try to replace Geocoder.local method with Geocoder.google in your code
Like this :
Coordinates coordinates = Coordinates(latLng.lat, latLng.lng);
List<Address> addresses =await Geocoder.google(apiKey,language:'ar').findAddressesFromCoordinates(coordinates);
How to get apiKey ? show Get an API Key

Using Google Sheets and Google Scripts - How do I insert an entry from a cell into a variable?

This is my first time playing with a JSON API and my java is super rusty.
I'm trying to do the following:
Pull a string from a Google Sheets cell into function getSymbol (name). In this case, the string should be "Ethereum"
Insert the name variable into a url string, which is where the JSON I want to pull lives. In this case, the API output looks like this:
[
{
"id": "ethereum",
"name": "Ethereum",
"symbol": "ETH",
"rank": "2",
"price_usd": "95.3675",
"price_btc": "0.0605977",
"24h_volume_usd": "152223000.0",
"market_cap_usd": "8713986432.0",
"available_supply": "91372705.0",
"total_supply": "91372705.0",
"percent_change_1h": "0.38",
"percent_change_24h": "1.38",
"percent_change_7d": "37.07",
"last_updated": "1494105266"
}
]
Next I want to pull the "symbol" item from the JSON and return that back to the spreadsheet. In this case, the function would take in "Ethereum" and return "ETH".
Below is my code. Whenever I run it I get an error saying my name variable is undefined, resulting in a URL that looks like this (says "undefined" instead of "ethereum"):
https://api.coinmarketcap.com/v1/ticker/undefined/?convert=USD
What am I doing wrong?
function getSymbol (name) {
var url = "https://api.coinmarketcap.com/v1/ticker/"+name+"/?convert=USD";
var response = UrlFetchApp.fetch(url);
var text = response.getContentText();
var json = JSON.parse(text);
var sym = json["symbol"];
return sym;
}
The return type is an array of objects i.e. json = [{object1},{object2}]
Even though there is just one element, you still need to access it like so
var sym = json[0]["symbol"]
//or
var sym = json[0].symbol
Your final code will look like this:
function getSymbol (name) {
var url = "https://api.coinmarketcap.com/v1/ticker/"+name+"/?convert=USD";
var response = UrlFetchApp.fetch(url);
var text = response.getContentText();
var json = JSON.parse(text);
var sym = json[0]["symbol"];
return sym;
}

Swift:How to map a single key to Multiple values?

I have successfully mapped a Single key to single value like this:
class DefaultDoubleModel :BaseObject
{
var key : String = ""
var value : String = ""
}
var toolChart :[DefaultDoubleModel]!
self.BubbleChartXaxislabel = Array(GraphDataModel.toolChart.map({ (item) -> String in
item.key
}))
self.BubbleChartValuesGraph = Array(GraphDataModel.toolChart.map({ (item) -> String in
item.value
}))
This is true for single key and single value. But i have two values in a single key. How can i collect those values in array.
For example i have like this..
{"value2":"80","value1":"120","key":"4"}
A Dictionary with tuples of strings would look like this:
var data: [String: (String, String)]()
data["4"] = ("80", "120")
print(data["4"]!.0)
You access the elements as .0 and .1.
If you want exactly two values, then you can make your DefaultDoubleModel look like this
class DefaultDoubleModel :BaseObject {
var key : String = ""
var value1 : String = ""
var value2 : String = ""
}
I think its more future proof to make it an array of Strings, like this:
class DefaultDoubleModel :BaseObject {
var key : String = ""
var values = [String]()
}
If you go with the second option, then you would map like this:
self.BubbleChartValuesGraph = GraphDataModel.toolChart.flatMap{ $0.values }

how to get the suds data in the bracket in python

all,
Anyone knows how to get the type info like "ATemplateVariable" and "BTemplateVariable" in a suds object like below in python:
variables[] =
(ATemplateVariable){
label = "labela"
uniqueName = "namea"
isRequired = True
defaultValue = 300
},
(BTemplateVariable){
label = "labelb"
uniqueName = "nameb"
isRequired = True
defaultValue = 250
},
...
I get the rest of the data like parsing a dict in python:
for var in variables:
label = var['label']
name = var['uniqueName']
...
But have no idea how to get the value like "ATemplateVariable" in each object.
Thanks very much
Zhihong

Base64 encode a string in Cloud Code

How do I base64 encode a string in cloud code? The value is for a HTTP Basic Auth.
I have tried the following two approaches and I had no success.
var string = 'AQXTTPmj-boT_yDEPQXg9ezIOIM7O:EMx6RLr8jF3S6YYo-X4bZ';
var buffer1 = new Buffer(string, 'base64');
var b3 = buffer1.toString('base64');
console.log(b3);
var string = 'AQXTTPmj-boT_yDEPQXg9ezIOIM7O:EMx6RLr8jF3S6YYo-X4bZ';
var encodeString = Base64.encode(string);
console.log(encodeString);
You send your string to the Buffer constructor and use toString method to convert it to base64 like this:
var string = 'AQXTTPmj-boT_yDEPQXg9ezIOIM7O:EMx6RLr8jF3S6YYo-X4bZ';
var buffer1 = new Buffer(string);
var b3 = buffer1.toString('base64');
console.log(b3);
Also make sure you put var Buffer = require('buffer').Buffer; on top of your main.js file.

Resources