Posts

Showing posts from July 12, 2018

Type mismatch in Scala's for-comprehension

Type mismatch in Scala's for-comprehension I have tried to define a recursive Scala function that looks something like this: def doSomething: (List[List[(Int, Int)]], List[(Int, Int)], Int, Int) => List[Int] = (als, rs, d, n) => if (n == 0) { for (entry <- rs if (entry._1 == d)) yield entry._2 } else { for (entry <- rs; adj <- als(entry._1)) yield doSomething(als, rs.::((adj._1, adj._2 + entry._2)), d, n - 1) } Now, the compiler tells me: | | | | | | <console>:17: error: type mismatch; found : List[List[Int]] required: List[Int] for (entry <- rs; adj <- als(entry._1)) yield doSomething(als, rs.::((adj._1, adj._2 + entry._2)), d, n - 1) ^ | | | | | | <console>:17: error: type mismatch; found : List[List[Int]] required: List[Int] for (entry <- rs; adj <- als(entry._1)) yield doSomet

How to pass state in React from index.js to child elements without using Redux?

Image
How to pass state in React from index.js to child elements without using Redux? I have a sample React app which shows projects on home page. I have created components as Index > Projects > Project : React Index Projects Project My code in Index.js : Index.js class App extends React.Component { render() { return ( <Router> </Router> ); } } My code in Projects.js : Projects.js export class Projects extends React.Component { constructor(props) { super(props); this.state = { projects: [ { name: "Smithsonian Institute", desc: "Description goes here", img: "https://mir-s3-cdn-cf.net//max_1200/da.jpg" }, { name: "Beauty Inc Next Dimension"

Creating multiple markers with Angular Google Maps from an API

Creating multiple markers with Angular Google Maps from an API I'm trying to create multiple markers in a Google Map with the AGM package. While I can create multiple markers hardcoding the latitude and longitude if I try to create them with data fetched from an API I can't make it work. If I do a ngFor in a 'p' tag to show the latitude and longitude, it shows the data correctly but for some reason, it can't create the agm-markers. This is my code: component.ts gps_lats: Array<number>; gps_longs: Array<number>; constructor(private _api: ApiService) { } ngOnInit() { this._api.machinesLocation().subscribe(res => { this.gps_lats = Object.values(res['data']).map(({ lat }) => lat); this.gps_longs = Object.values(res['data']).map(({ long }) => long); }); } component.html hi @David plz provide json res of machinesLocation service – Krishna Rathore J

What is the purpose of the Priority Queue in ServiceStack's RabbitMQ Server?

What is the purpose of the Priority Queue in ServiceStack's RabbitMQ Server? I am using ServiceStack with the Rabbit MQ Server and found that service messages handled through the ServiceController.ExecuteMessage handler are processed with two threads even though "noOfThreads = 1". Here is how I am registering the handler: container.Register<IMessageService>(c => new RabbitMqServer()); var mqServer = (RabbitMqServer)container.Resolve<IMessageService>(); mqServer.RegisterHandler<CallBatchMessage>(ServiceController.ExecuteMessage, noOfThreads: 1); I found in the following about the Priority Queue in the documentation: "Starting the MQ Server spawns 2 threads for each handler, one to listen to the Message Inbox mq:Hello.inq and another to listen on the Priority Queue located at mq:Hello.priorityq. Note: You can white-list which messages to enable Priority Queue's for with mqServer.PriortyQueuesWhitelist or disable them all by setting mqServer.Di

nginx not returning Cache-Control header from upstream gunicorn

nginx not returning Cache-Control header from upstream gunicorn I'm using WhiteNoise to serve static files from a Django app running under gunicorn. For some reason, the Cache-Control and Access-Control-Allow-Origin headers returned by the gunicorn backend are not being passed back to the client through the nginx proxy. Cache-Control Access-Control-Allow-Origin Here's what the response looks like for a sample request to the gunicorn backend: % curl -I -H "host: www.myhost.com" -H "X-Forwarded-Proto: https" http://localhost:8000/static/img/sample-image.1bca02e3206a.jpg HTTP/1.1 200 OK Server: gunicorn/19.8.1 Date: Mon, 02 Jul 2018 14:20:42 GMT Connection: close Content-Length: 76640 Last-Modified: Mon, 18 Jun 2018 09:04:15 GMT Access-Control-Allow-Origin: * Cache-Control: max-age=315360000, public, immutable Content-Type: image/jpeg When I make a request for the same file via the nginx server, the two headers are missing. % curl -I -H "Host: www.myhost

react solidity event memory leak

react solidity event memory leak I am getting solidity events from componentdidmount with the following code: myDataSocks.events.ReceivedPayment({}, async (error, event) => { if (!error) { const account = event.returnValues.fromAcct; const payment = web3.utils.fromWei(event.returnValues.payment); console.log('ReceivedPayment: ', account, payment); this.notify(`You received ${payment} ether from ${account}`); let contractBalance; await web3.eth.getBalance(address).then(function(result) { contractBalance = web3.utils.fromWei(result); }); this.setState({ contractBalance }); } else { console.log('ReceivedPayment error:', error); } }); However, sometimes I am getting this error: warning.js:33 Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but it indicates a memory leak in your application.

Get ID from DataTables-Table

Get ID from DataTables-Table maybe a easy question for all of you, but I'm fairly new to JavaScript/jQuery and how AJAX calls work, so i Need a Little bit of help. At the Moment im rebuilding my DataTable-Tables to use severside-processing because they grow very big and through this becoming very slow. I allready put a fair amount of time in it to understand how ajaxcall works, etc. but there is one Problem i can't solve: I can't get the ID from the DataTables im working with. This is my HTML-Part: <table id="tbl_user" class="table table-hover display ajaxTable" width="100%;" cellspacing="0"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Kostenstelle</th> <th>Status</th> <th>Aktionen</th> </tr> </thead> </table> This is my javascrip/jQuery-Part: $('.ajaxTable').DataTable({ processing: true,

How to find duplicated Ruby methods with the same name but different code?

How to find duplicated Ruby methods with the same name but different code? The very large Ruby codebase I am working with has many instances of duplicated methods defined with the same name but some of its code is different (causing a large race condition problem). The eventual end goal is to reconcile the duplicates and have just one version of the same-named method. First I need to find all versions of a method that deviate from the "control" version of that method. Is there an optimal way to search and for and find all instances of duplicated same-named methods that deviate from one defined version? The duplicated methods are spread out across hundreds of different files and contained in one class. These are essentially helper methods that should have been centralized in one file but instead have been duplicated and often altered, but keeping the same method name. Right now I just need a good way to locate all the instances where these methods have been duplicated and are

Passing data response of first request to second request in Jmeter

Passing data response of first request to second request in Jmeter I have a POST request that is similar to this: https://abc.qa.net/teachers The response of above request is similar like this: teacherUuid":"eb57eb97-0a9d-4b51-a237-1f6610983167" Then, I have a PATCH request that is similar to this: https://abc.qa.net/teachers/{teachersUuid} Problem Statement: I want to make two request in Jmeter. The first request (POST) generates a new id for me and then I want to use the same id to make second request (PATCH) in Jmeter. Note that, the second id will be passed via URL. How I can achieve this functionality in simple way? Please read Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers? - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions.

Find the second highest value in data frame in R

Find the second highest value in data frame in R Hello for below data frame in R, may I know the simplest command (without using any additional library like deplyr) how to find the second highest salary and store the name of the employee in a variable named 2nd_high_employee? EmployeeID EmployeeName Department Salary ----------- --------------- --------------- --------- 1 T Cook Finance 40000.00 2 D Michael Finance 25000.00 3 A Smith Finance 25000.00 4 D Adams Finance 15000.00 5 M Williams IT 80000.00 6 D Jones IT 40000.00 7 J Miller IT 50000.00 8 L Lewis IT 50000.00 9 A Anderson Back-Office 25000.00 10 S Martin Back-Office 15000.00 11 J Garcia Back-Office 15000.00 12 T Clerk Back-

If a job has status completed execude code in powershell

If a job has status completed execude code in powershell After about half a day of googling without any luck I've decided to post my question here. So I want to check if a job has status completed. Here is my code so far: Start-job -name Copy -Scriptblock {Copy-Item -force -recurse -path "C:Test.temp" -destination "D:"} $x = 170 $length = $x / 100 While($x -gt 0) { $min ) [int](([string]($x/60)).Split('.')[0]) $Text = " " + $min + " mintues " + ($x % 60) + " seconds left" Write-progress "Copying file, estimated time remaning" -status $text -percentComplete ($x/$length) Start-sleep -s 1 $x-- if (Get-job -name Copy -status "Completed") { Break } } So as you can see I first start a job, then I run a loop with a countdown progress bar. This is just to give the user some kind of feedback that things are still moving. Note that the "Get-job -status "completed" doesn't work since it

xml.etree.ElementTree vs. lxml.etree: different internal node representation?

xml.etree.ElementTree vs. lxml.etree: different internal node representation? I have been transforming some of my original xml.etree.ElementTree ( ET ) code to lxml.etree ( lxmlET ). Luckily there are a lot of similarities between the two. However , I did stumble upon some strange behaviour that I cannot find written down in any documentation. It considers the internal representation of descendant nodes. xml.etree.ElementTree ET lxml.etree lxmlET In ET, iter() is used to iterate over all descendants of an Element, optionally filtered by tag name. Because I could not find any details about this in the documentation, I expected similar behaviour for lxmlET. The thing is that from testing I conclude that in lxmlET, there is a different internal representation of a tree. iter() In the example below, I iterate over nodes in a tree and print each node's children, but in addition I also create all different combinations of those children and print those. This means, if an element has c