Alamofire wrong order of JSON response

json
Question: I use Alamofire to populate a TableView. This is an extract of my code:var arrRes = [[String:AnyObject]]() Alamofire.request(api_url5).responseJSON { (responseData) -> Void in if((responseData.result.value) != nil) { let swiftyJsonVar = JSON(responseData.result.value!) if let resData = swiftyJsonVar["data"].arrayObject { self.arrRes = resData as! [[String:AnyObject]] print (api_url5) print (self.arrRes) } if self.arrRes.count > 0 { self.tblDetail.reloadData() } } } The request has a "sort" parameter which outputs the right order in Postman. But the items in the table are in the wrong order and the output I receive with print (self.arrRes) too. How can I keep the order I get from my API? Order in Postman:{ "data": [ { "we": "text", "de": "text", "se": "text", "ve": "text", "qe": "text", "ne": "text" }, { "we": "wer", "de": "wer", "se": "wer", "ve": "wer", "qe":…
Read More

How write seeder in Laravel

Uncategorized
Question: I have table taggable, it's table for Many To Many Polymorphic Relations (Tag and post):taggable_id - id of Post tag_id - id of Tag taggable type - location of post model (default value"App/Models/Posts/Post") is_search_term - boolen (0 or 1) How create a seeder which each time create same records for relations? Answer: Tag_id will be created by db automatically if it is set to primary key, taggable_id you get values from Tag model. You can try something like this; $factory->define(AppTag::class, function (FakerGenerator $faker) { return [ 'taggable_id' => random_int(DB::table('posts')->min('id'), DB::table('posts')->max('id')), 'is_search_term'=>$faker->numberBetween(0,1), 'taggable_type'=>$faker->sentence(2), ]; }); Read more
Read More

R: How to extract values from contiguous raster cells that are not touched by SpatialLines?

r
Question: I've been trying to extract values from a single attribute raster (area, in m2) that overlaps with lines (that is, a .shp SpatialLines). The problem is that, along these lines, my raster sometimes goes from one to several contiguous cells in all directions. Using the extract function only values from cells that are touched by the lines are extracted. Thus, when I add up the extracted values from all lines a significant amount of area (m2) is lost due to cells that were not touched by the line and therefore values were not extracted. I tried to work it around by: Step 1 - first aggregating my raster to a lower resolution (i.e. increasing the fact argument) and then Step 2 - rasterizing the lines using this aggregated raster…
Read More

Use elastic/elasticsearch-php to scroll documents but got 404 exception

Uncategorized
Question: I am using the official elastic/elasticsearch-php to scroll documents but got 404 exception when sending a second scroll request. Here comes the code. $client = ClientBuilder::create()->setHosts(['mykibana.domain'])->build(); $params = [ 'index' => 'my_index', 'scroll' => '30s', 'size' => 100, 'body' => [ 'query' => [ 'filtered' => [ 'query' => [ 'query_string' => [ 'query' => ""https://myapplication.domain/orders"", 'analyze_wildcard' => true ] ] ] ] ] ]; $response = $client->search($params); while (isset($response['hits']['hits']) && count($response['hits']['hits']) > 0) { // processing $response['hits']['hits']... $scrollId = $response['_scroll_id']; $response = $client->scroll([ 'scroll_id' => $scrollId, 'scroll' => '30s' ] ); } The while loop is nearly the same as scroll sample in elasticsearch documentation The error [ElasticsearchCommonExceptionsMissing404Exception] {"statusCode":404,"error":"Not Found"}. Software version: PHP 5.6.3 and elastic/elasticsearch-php 2.0. Appreciate your help! Update: I tried to use curl directly to…
Read More

C# PInvoke Signature for this C++ function

Uncategorized
Question: I have been trying to integrate a C++ dll into my C# application. I am no C++ expert but have managed to map out some of the functions but have trouble with one of the more complex ones. The C++ method signature I need to call looks like this, int ObjSearchObject2( ObjSearchObjectParm *, ObjObjectResults * ); And the structures used are defined as follows, typedef struct _ObjSearchObjectParm { int obj_defn_count; char **obj_defn_ids; char *query_String; ObjApiBoolean include_deleted; int max_results; int num_conditions; ObjSearchCondition *search_cond; ObjApiBoolean include_content; ObjApiBoolean include_metadata; } ObjSearchObjectParm; typedef struct _ObjObjectResults { ObjApiObjectHdl *object_handle; int num_results; } ObjObjectResults; typedef struct _ObjSearchCondition { char *join_relation; int num_opening_brackets; int num_closing_brackets; char *field; char *op; char *value; } ObjSearchCondition; enum ObjApiBoolean { OBJAPI_FALSE, OBJAPI_TRUE }; typedef void* ObjApiObjectHdl; Any help on this…
Read More

How to set the initials when using NLsolve, Julia

Uncategorized
Question: Please, I want to use NLsolve of Julia for solving systems of nonlinear equations. The package requires to set the initials for the unknowns of your system. With my system of equations (sorry, I can not include it here since I need at least 10 reputations to be allowed to), when I keep the initials [0.1; 1.2] as in the example from the documentation, I obtain the "paper-pencil" solution. But if I set the initials at [1.1;2.2] for example, I receive the following error: DomainError: Exponentiation yielding a complex result requires a complex argument. Replace x^y with (x+0im)^y, Complex(x)^y, or similar. Please, how should I come up with suitable values for initials for a given system of equations? Answer: A rootfinder is always dependent on the initial condition. That's…
Read More

difference between two way of converting JSON byteArray

Uncategorized
Question: I have json image response like this:"UserImage":[ 255, 216, 255, 224, 0,.....] there is two way that I make this response to byte array: 1 - JSONArray resultImage = result.getJSONArray("UserImage"); byte[] byteUserImage = resultImage.toString().getBytes(); hashUserImageMap.put(userId, byteUserImage); 2- byte[] tmp=new byte[result.getJSONArray("UserImage").length()]; for(int i=0;i
Read More

Windows 10 service firewall blocking my service

Uncategorized
Question: We have a windows service which hosts SSDP and a web service. We added the following windows firewall rules netsh advfirewall firewall add rule name="Test Rule" dir=in protocol=UDP localport="1900" action=allow netsh advfirewall firewall add rule name="Test Rule" dir=out protocol=UDP localport="1900" action=allow netsh advfirewall firewall add rule name="Test Rule" dir=in protocol=TCP localport="8080" action=allow We firstly had SSDP hosted via a single socket bound to IpAddress.Any. This worked but if the network was down when the service started it would only recieve traffic from 127.0.0.1. The web service has no issue listening to IpAddress.Any and survives network changes however that is TCP and not UDP as with SSDP. heres some code snippits _socket = new Socket( /*AddressFamily.InterNetworkV6,*/ SocketType.Dgram, ProtocolType.Udp); _socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false); _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); var localEp = new IPEndPoint(address, 1900);…
Read More

Changing Tkinter Label Text Dynamically using Label.configure()

Uncategorized
Question: I am new to GUI development and trying to build an application using Python3.6+Tkinter. I have a requirement where I need to change the default text (displayed by the Label when it was created) with a new text when the user hits a Button. To achieve that I am using label.configure(text="") To give you a simplified version of my requirement, consider following example where the Label initially displays "Welcome". When user clicks the Button, Label text should change to "Process Started" and after the process is completed the Label text should change to "Process Completed". Here do_something function runs a process which takes some time and I'm using time.sleep(5) to simulate a process that runs for 5 seconds. from tkinter import * from tkinter import ttk import time def…
Read More

How to read specific bytes from a binary file in Python?

Uncategorized
Question: I would learn to handle read and write binary data. I know that I can open a binary file with f = open(myfile, mode='rb') fb = f.read() f.close() return fb How can I access and read the range $A7-$AC in a mp3 file with this structure: Lame mp3 Tags Answer: You should take a look at Python's struct library for help with extracting binary data. import struct mp3_filename = r"my_mp3_file.mp3" with open(mp3_filename, 'rb') as f_mp3:mp3 = f_mp3.read() entry = mp3[0xA7:0xAC+1] print struct.unpack("{}b".format(len(entry)), entry) This would give you a list of integers such as:(49, 0, 57, 0, 57, 0) You pass a format string to tell Python how to intepret each of the bytes. In this example, they are all simply converted from bytes into integers. Each format specifier can…
Read More

How to change android RecyclerView child view height programatically?

android
Question: I want to change my RecyclerView items height programatically to match_parent or wrap_content due to size of content. How to change the height of child item? DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(binding.RVOperation.getContext(), DividerItemDecoration.VERTICAL); binding.RVOperation.setLayoutManager(staggeredGridLayoutManager); binding.RVOperation.addItemDecoration(dividerItemDecoration); Log.d("COUNTT", String.valueOf(binding.RVOperation.getAdapter().getItemCount())); Answer: You need to override onBindViewHolder in your RecyclerView and call setLayoutParams on the viewholder's container. example:@Override public void onBindViewHolder(SimpleItemViewHolder holder, int position){ // do whatever here // add your layout parameters here. Here I'm setting the width and height to match parent TableRow.LayoutParams params = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT); //(width,height) holder.container.setLayoutParams(params); } Source Read more
Read More

Pass through 302 respond and save the html for the redirect page

Uncategorized
Question: I have write a code to get the html code from security website. I get the 302 respond but i am not sure how to save the html for the webpage. Below is my code. #!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent; use HTTP::Request; use HTTP::Request::Common qw(POST); use HTTP::Cookies; my $URL="http://www.example.com"; my $UA = LWP::UserAgent->new(); $UA->ssl_opts( verify_hostnames => 0 ); my $req =HTTP::Request::Common::POST("$URL", Content_type=>'form-data', Content =>[ 'username'=>'user', 'password'=>'password', ] ); $req->header('Cookie' =>q(TIN=287000; LastMRH_Session=439960f5; MRHSession=78c9c47291c1fcedae166121439960f5)); my $resp=$UA->request($req); if ($resp->is_success) { my $res2 = $UA->post($resp->base, []); print $res2->decoded_content; } Below is the 302 respond i get 302 Found Found The document has moved here. Apache/2.2.3 (CentOS) Server at www Port 80 I want to get the html information from the website www.XXX.com but i only can get the 302 respond.…
Read More

Emulate browser environment server-side [on hold]

c#
Question: I'm writing a .NET Windows service application that, for reasons I can't go into, must be able to run an emulated browser in a sandbox environment, including: * evaluating/running any JavaScript, even if it loads other JavaScript * supporting full DOM manipulation via JavaScript * responding to mouse clicks and other events as a normal browser would, with C#/.NET hooks to be able to receive data on the events * simulating mouse clicks and other events In other words, it must be able to take the place of a browser. It's not for testing. I've never done anything like this before. I see Selenium as for testing only, from browsing the help, but would a Selenium WebDriver do everything I need? Alternately, what about something like the WPF Browser…
Read More