Posts

Showing posts from July 13, 2018

Swift - if string is nil. don't add it to the array

Swift - if string is nil. don't add it to the array I have an Array of Image links - Array Image let alamofireSource = [AlamofireSource(urlString: Img1!)!, AlamofireSource(urlString: Img2!)!, AlamofireSource(urlString: Img3!)!, AlamofireSource(urlString: Img4!)!] slideshow.setImageInputs(alamofireSource) some posts have only one image or two or three, and so on. so, sometimes image 2 (for example) is nil, In that case, I don't want it to be added to the array, is that possible? 3 Answers 3 You can try ( Swift 4 ) let arr = [img1,img2].compactMap{$0}.map{AlamofireSource(urlString:$0)!} or let arr = alamofireSource.compactMap{$0} for Swift 3 let arr = alamofireSource.flatMap{$0} Thanks a trillion! It fixed the problem :-) – Sophie Bernard Jul 3 at 10:22

Specifically assign contrasts in R model.matrix

Specifically assign contrasts in R model.matrix If I have a variable (condition) of 2 levels and want to create a model.matrix R automatically assigns conditionB as the term in the design matrix. condition <- as.factor( c("A","A","A","B","B","B")) df <- data.frame(condition) design <- model.matrix( ~ condition) > df condition 1 A 2 A 3 A 4 B 5 B 6 B > design (Intercept) conditionB 1 1 0 2 1 0 3 1 0 4 1 1 5 1 1 6 1 1 attr(,"assign") [1] 0 1 attr(,"contrasts") attr(,"contrasts")$condition [1] "contr.treatment" Question : I would like to have my results relative to conditionA . How can I specify this in model.matrix() ? (A workaround would be to inverse the resulting FCs) What do you

How to count the number of combination of rows with a drop down list selection in datatables

How to count the number of combination of rows with a drop down list selection in datatables I would like to count the number of rows in a table after making a selection in a drop down list (Name). but the only problem here is i would like to count number of rows basing on an other attribute in my table (position). for example: if i make a selection in the Name: Tiger Nixon i would like to get total rows: 3 Position 1 : 1 rows Position 2 : 1 rows Position 3 : 1 rows Here the code I use to make a drop down list selection with attribute (Name) and it worked perfectly. $(document).ready(function () { $('#example').DataTable({ initComplete: function () { this.api().columns(0).every(function () { var column = this; var select = $('<select class="Search"><option value=""></option></select>') .appendTo($(column.header()))

How to mock and test RxJava/RxAndroid with Mockk?

How to mock and test RxJava/RxAndroid with Mockk? I want to mock and test my Presenter with the Observable , but I don't know how to do that, the main part of the code as below: Presenter Observable //in my presenter: override fun loadData(){ this.disposable?.dispose() this.disposable = Observable.create<List<Note>> {emitter-> this.notesRepository.getNotes {notes-> emitter.onNext(notes) } } .doOnSubscribe { this.view.showProgress() } .subscribe { this.view.hideProgress() this.view.displayNotes(it) } } //in test: @Test fun load_notes_from_repository_and_display(){ val loadCallback = slot<(List<Note>)->Unit>(); every { notesRepository.getNotes(capture(loadCallback)) } answers { //Observable.just(FAKE_DATA) loadCallback.invoke(FAKE_DATA) } notesListPr

Close dropdown menu after click outside of navbar using only JavaScript?

Close dropdown menu after click outside of navbar using only JavaScript? I want to make a drop-down menu which one is very simple and when after click outside of nav its automatically hide. note I already make drop-down menu but... I don't understand how to close it. here is my HTML and javascript code. <section class="dropdownone"> Dropdown One Click Dropdown home about profile </section> Possible duplicate of How do I detect a click outside an element? – Lars-Olof Kreim Jul 3 at 7:58 write an event that checks if the select dropdown is out of focus, ie, it is blurred, you need to write a blur event, when that event is fired, hide the dropdown menu. – Code_Ninja Jul 3 at 8:14

Convert image to string without losing data in c++

Convert image to string without losing data in c++ I am sending data from my C++ client to C# WCF service where it accepts JSON data. We need to send an image to WCF service by converting it to a JSON string, but while converting image (jpg/jpeg) it has some null characters inside a string ( ) so the string is getting terminated when converting std::string to char* and I am able to send only part of the string to service. Is there way that I can convert the image to string ( const char * ) without having null characters in it so that I can send all the image data (as char* ) without loosing any data? std::string char* const char * char* The available function from C++ client is: httpClient.POST("ServiceName", const char* data, "ContentType") Convert to base64 – Aram Jun 28 at 13:10 You shoul

Testing :id routes

Testing :id routes How can I test routes with :id into it. For example, we have suppose a route like this Router.get('/:id/profile Now, I want to do a test case, the example scenario I saw from someone's else code was that he was passing a string of numbers (probably user ID or something) Being a total tester in beginner who have been asked to test something, how can I find that string which I can send when testing something. For example here describe('Admin users API testing', () => { it('GET /admin/users/:id/activityLog', (done) => { request(URL) .get('/admin/users/5a82b1a61dab4b54fj01f212e/activityLog') .set('accept', '/application/json') We are sending request to it('GET /admin/users/:id/activityLog Which then looks like this .get('/admin/users/5a82b1a61dab4b54fj01f212e/activityLog') inside the above get request we have, something like this 5a82b1a61dab4b54fj01f212e So my question

Bringing a laptop and a VM on another laptop on the same network

Bringing a laptop and a VM on another laptop on the same network I am a newbie to networking. I am currently running an application on a VM (windows based also hosted on a windows based PC (say PC1)). I want my VM to communicate with the Linux based PC (say PC2). I have connected PC1 and PC2 with an ethernet cable and gave tem static IP addresses. Now they can communicate with each other. Ping tested. Now I want the VM hosted on PC1 to communicate with PC2. How can I bring the VM also in the same network ? By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

/var/run/docker.sock: permission denied while running docker within Python CGI script

/var/run/docker.sock: permission denied while running docker within Python CGI script I am trying to run Python CGI script inside which I need to run docker image. I am using Docker version 1.6.2. user is "www-data", which is added in docker group. www-data : www-data sudo docker On machine, with www-data I am able to execute docker commands www-data@mytest:~/html/new$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES I am getting following error while running docker image from Python CGI script: fatal msg="Get http:///var/run/docker.sock/v1.18/images/json: dial unix /var/run/docker.sock: permission denied. Are you trying to connect to a TLS-enabled daemon without TLS?" Is there anything I am missing here? 1 Answer 1 Permission denied on a default install indicates you are trying to access the s

Changing the color of the 'active'

Changing the color of the 'active' The active color is still White even after rgb is changed. .nav li>a:hover, .nav .open>a:hover, .nav li>a:focus, .nav .open>a:focus, .nav li>a:active, .nav .open>a:active { background-color: rgb(255, 0, 0) <nav class="navbar navbar-m2p sidebar" role="navigation"> Toggle navigation Foobar Company </nav> I can not see any li in html code – לבני מלכה Jul 3 at 9:46 li Think you need to learn about basic css selectors - do a tutorial, it will save you a lot of time and questions. But the main problems I see is you have nothing with a class of nav and no li so obviously your css is not styling anything – Pete Jul 3 at 9:51

Extract list data from a column

Extract list data from a column I have a dataframe that looks really similar to this (basically a table of cities and their coordinates on a map. Note that coordinates is a list of X,Y values. foo <- data.frame( city = c("chicago", "new york"), coordinate = I(list(list(10, 15), list(20, 25))), myabbr = c("chi", "ny") ) bar <- subset(foo, select=c("city", "coordinate")) Right now, I can create a new table of only the city and the coordinates. I really want the X and Y values to be a separate column. This is what I tried bar <- subset(foo, select=c("city", "coordinate[1]", "coordinate[2]")) I'm not sure exactly how to do this though. You can try something like cbind(as.character(bar$city), apply(bar, 1, function(i)unlist(i$coordinate))) – Sotos Jul 3 at 9:42

Python fetchall return true and false

Python fetchall return true and false I have a python script that makes a fetchall(): connection = pymssql.connect(host='host', user='user', password='pw', database='database', as_dict=True) cursor = connection.cursor() cursor.execute("EXEC SPname") data=cursor.fetchall() My problem is that the cursor.fetchall() is returning True or Falses (and others columns with others values example above) but in the database the value is a bit 1 or 0 and when exported to CSV it puts the True or False and I want 1 or 0. Sample data returned in SQL: ID Price Price2 Price3 Active Opened Sent Enable 1 12234.09 1111.09 3444.36 1 1 1 0 2 Answers 2 You can use int() int() Ex: print(int(True)) print(int(False)) Output: 1 0 Thank you for your answer and help. The pro

Could anyone explain how the link is combined with the image in this site?

Could anyone explain how the link is combined with the image in this site? Normally, when we want to add some url link to a image, we simply put that image inside a element. However, I just found that in this page: https://uk.burberry.com/mens-trench-coats/ The link of each coat is separated from the image. However, when the mouse is put on the coat image, we can still detect the link. Could anyone explain how does this work? 1 Answer 1 The link on the page you mentioned is position: absolute; and "moved" over the actuall image which is indeed placed in an other element. position: absolute; https://developer.mozilla.org/en-US/docs/Web/CSS/position By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to th

Laravel 5.6 - Using @foreach in a markdown

Laravel 5.6 - Using @foreach in a markdown Hello stackoverflowers, I try to render a @foreach loop in a markdown template. But I don't get it to work. I found this Laravel- use @foreach in markdown mail, but it didn't take me futher. I studied the laraval docs but it seems that I'm unable to find my issue. I try to generate a mail with all information from the supplier-table. Therefore I use the Supplier Class. Maybe someone could open my eyes or could give me a hint in the right direction. Route: Route::get('/mail',function(){ $suppliers = AppModelSupplierSupplier::all(); return new AppMailSupplierCertificates($suppliers); }); Mail-Class: namespace AppMailSupplier; use IlluminateBusQueueable; use IlluminateMailMailable; use IlluminateQueueSerializesModels; use IlluminateContractsQueueShouldQueue; use AppModelSupplierSupplier; class Certificates extends Mailable { use Queueable, SerializesModels; public $supplier; public function __construct(Supplier $supplie

How to prompt/hide a password when opening a CMD?

How to prompt/hide a password when opening a CMD? I have some code inside a batch file that when I run it my passwords do get hidden. However I am trying to build it so that I can place the code inside any batch file and you will then need to enter the correct password. Currently you can type anything and be allowed access. I know my code isn't written so you have to type something specific in, that is why I am asking here. @echo off set "psCommand=powershell -Command "$pword = read-host 'Enter Password' - AsSecureString ; ^ $BSTR=[System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pword); ^ [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)"" for /f "usebackq delims=" %%p in (`%psCommand%`) do set password=%%p echo %password% I wish to keep my code as it is because it currently hides what gets typed, but I need someone to add some sort of password checker. Possible duplicate of Batch File

How do I flat a Nested Json file in Python?

Image
How do I flat a Nested Json file in Python? I have a nested Json file with arrays. I want to flat it so there won't be nested Jsons. For example: Code for Json: https://jsonblob.com/4b255e51-7e9f-11e8-b89c-37203846213e This Json has sub-Json and also array that contains Json. The source is: Output should be: If there are arrays that contains a single Json they can be ignored. But if they have also sub-json they should be treated as above. Basically from my point of view each array is like a separated Json file. I know that flating the Json can be done as: from pandas.io.json import json_normalize json_normalize(sample_object) But this won't work with arrays. Any idea how to make this work? EDIT: This is how arrays should be handled: source: Output: Which means first Json in array stays as is {0}, {1} etc... but the sub-jsons are flatted. There are no columns of attributes_0_value ! Basically convert it to array with a single Json. No nesting (unless there is another array)

Calculated Column based on the number in Text area

Image
Calculated Column based on the number in Text area I hope you can help. What I am trying to achieve is a column that recalculates a column based on the value entered in the Text Area . Let me explain. Text Area In Pic 1 you can see the page called Rename Dashboard, and I also have a page called Percentage Schema see Pic 2 On Page Percentage Schema you will see that Column 1 is the Product Code , Column 2 is the Product name (I have covered with text doc to protect info), Column 3 is the price of the product and Columns 4 out to 12 tell me what 'Schema' this product is on and what discount can be earned by being on this Schema. Percentage Schema Product Code Product name product 'Schema' So if you observe in Pic 2 Product Code 708230 has a 1 in the first row of Column 4 meaning that this product will receive a 20% discount for being on number 1 Schema, If you look at Column 5 you will see the number 2 and if you navigate directly down and across this product will get

Creating star schema from csv files using Python

Creating star schema from csv files using Python I have 6 dimension tables, all in the form of csv files. I have to form a star schema using Python. I'm not sure how to create the fact table using Python. The fact table (theoretically) has at least one column that is common with a dimension table. How can I create the fact table, keeping in mind that quantities from multiple dimension tables should correspond correctly in the fact table? I am not allowed to reveal the code or exact data, but I'll add a small example. File 1 contains the following columns: student_id, student_name. File 2 contains : student_id, department_id, department_name, sem_id. Lastly File 3 contains student_id, subject_code, subject_score. The 3 dimension tables are in the form of csv files. I now need the fact table to contain: student_id, student_name, department_id, subject_code. How can I form the fact table in that form? Thank you for your help. 2 Answers