Posts

Showing posts from September 15, 2018

Video is not rendered in accord videoSourcePlayer control

Image
Clash Royale CLAN TAG #URR8PPP Video is not rendered in accord videoSourcePlayer control I have an accord videoSourcePlayer control in my form.Why is it that it is not rendering the video that I select? Please see my code below: // Open video file using DirectShow private void openVideoFileusingDirectShowToolStripMenuItem_Click(object sender, EventArgs e) if (openFileDialog.ShowDialog() == DialogResult.OK) // create video source FileVideoSource = new FileVideoSource(openFileDialog.FileName); // open it sourceInitialiization = true; OpenVideoSource(FileVideoSource); // Open video source private void OpenVideoSource(IVideoSource source) // set busy cursor this.Cursor = Cursors.WaitCursor; // close previous video source CloseVideoSource(); // start new video source videoSourcePlayer.VideoSource = new AsyncVideoSource(source); videoSourcePlayer.Start(); // reset statistics statIndex = statReady = 0; // start timers timer.Start(); alarmTimer.Start(); //alarmTimer...

Bind JSON http response to Angular 6 components

Image
Clash Royale CLAN TAG #URR8PPP Bind JSON http response to Angular 6 components I'm getting below JSON response from my HttpClient GET method shortDescription: "3", promotionName: "2", highResolutionImage: "4", lowResolutionImage: "5", promotionOrChallengeCode: "aaa" Promotion.ts export interface IPromotion PromotionOrChallengeCode:string; PromotionName:string; ShortDescription:string; HighResolutionImage:string; LowResolutionImage:string; In my Component class promotion:IPromotion; onSubmit() : void this.httpClient.get('http://localhost:8080/api/search/'+this.pcode ) .subscribe((response:IPromotion) => console.log(response); this.promotion = response; console.log(this.promotion.PromotionOrChallengeCode); ); In the Browser console, I'm able to view the JSON response (Output of first console statement). And the output of second console statement is displayed as "Undefined" Let me know h...

Get list of files using Boto from Private S3: 403 Forbidden

Image
Clash Royale CLAN TAG #URR8PPP Get list of files using Boto from Private S3: 403 Forbidden I would like to get a list of files that exist in a private S3. Generally, I do the following: from boto.s3.connection import S3Connection from boto.s3.key import Key aws_access_key_id = "XXX" aws_secret_access_key = "YYY" conn = S3Connection(aws_access_key_id, aws_secret_access_key) bucket = conn.get_bucket('bucket-name') these_files = ["s3://bucket-name/" + f.name for f in list(bucket.list("", ""))] However, if I were to read the file in pandas I get 403 Forbidden Error . I found the solution here to get a file such as: 403 Forbidden Error bucket = conn.get_bucket('bucket', validate=False) k = bucket.get_key('file.csv') df = pd.read_csv(k) The problem with this solution is that it requires the user to know the file name in advance. I could avoid this by creating a custom function: def readS3_files(f): filename = f.s...

How to reduce repeatedly and dynamically generated html

Image
Clash Royale CLAN TAG #URR8PPP How to reduce repeatedly and dynamically generated html I am in the middle of revising a website and it has a significant problem with rendering time. I looked into what is causing the problem and it turns out that table-generating mechanism that I am using takes way too much time. As needed data gets queried from DB, the table is dynamically generated in repeated format. (as shown below in the code) Table size increases as scrolling down to bottom. Instead of generating additional table every time additional queries are done, is there any way to get by and reduce the rendering time? Here is a snippet of HTML structure generated. (there are more than 10000 rows in the same format but with different contents) Thank you very much for your help in advance! <tr class="doc_field_vendor_item"> <td width="150px" align="center" class="item"> <div id="invno1127">16011304</div> </...

Increase the width of two columns in PDF in c#

Image
Clash Royale CLAN TAG #URR8PPP Increase the width of two columns in PDF in c# I am downloading a PDF using Itextsharp .I need to increase the width of two columns in pdf.I have tried using celcols.width ,however its not working.Now all the columns have same width.Any help will be really appreciated.Thanks in Advance`. protected void Button6_Click(object sender, EventArgs e) try string fromdate = "", todate = ""; string compgrp = "All"; var pdfDoc = new Document(PageSize.A3, 10f, 10f, 10f, 0f); System.IO.MemoryStream mStream = new System.IO.MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, mStream); PdfPageEventHelper pageEventHelper = new PdfPageEventHelper(); writer.PageEvent = pageEventHelper; HeaderFooter header = new HeaderFooter(new Phrase("Schedule report" + DateTime.Now.ToString("dd/MMM/yyyy hh:mm tt") + ""), false); header.BackgroundColor = new iTextSharp.text.Color(System.Drawing.ColorTra...

Multiprocessing throws Attribute Error, why?

Image
Clash Royale CLAN TAG #URR8PPP Multiprocessing throws Attribute Error, why? For some reason that I do not see, this code is throwing an error: AttributeError: __exit__ AttributeError: __exit__ The code is simple: import re, string, math, numpy, time, os.path, itertools, matplotlib, subprocess, shutil, sys, scipy.spatial.distance, multiprocessing, threading, ctypes from functools import partial from multiprocessing.sharedctypes import Value, Array from multiprocessing import Process, Lock def main(): with multiprocessing.Pool(8) as myPool: print("1") if __name__ == '__main__': main() The various import lines are for other things I've been using with other code I'm working on multithreading. This however is the simple 'sample' code that I'm trying to analyze to learn the ropes. I assume it's having some sort of trouble opening the with block, but I don't understand why. Does Python 2.7 not implement multiprocessing this way? It's a...

How to redirect with a model after making a post request in Angular/.NET MVC?

Image
Clash Royale CLAN TAG #URR8PPP How to redirect with a model after making a post request in Angular/.NET MVC? I am using .NET MVC and AngularJS. After making a post request to place an order, I need to return the order that was created to a different view. I have two views. Purchase Success and Purchase Fail. Here is the post request in Angular: $http.post('/Home/PlaceOrder/', placeOrderViewModel) .then(function (response) if (response != null) window.location = '/Home/PurchaseSuccess'; else window.location = '/Home/PurchaseFail'; , function () alert('error'); ); Here is the method on my MVC controller. public ActionResult PlaceOrder(PlaceOrderViewModel viewModel) It accepts a view model from the Angular post request, and does some work. Then I have it returning either the purchase success or purchase fail view with the order model attached to a successful order. return View("~/Views/Home/PurchaseSuccess.cshtml", order); return Vie...

Common elements comparison between 2 lists

Image
Clash Royale CLAN TAG #URR8PPP Common elements comparison between 2 lists def common_elements(list1, list2): """ Return a list containing the elements which are in both list1 and list2 >>> common_elements([1,2,3,4,5,6], [3,5,7,9]) [3, 5] >>> common_elements(['this','this','n','that'],['this','not','that','that']) ['this', 'that'] """ for element in list1: if element in list2: return list(element) Got that so far, but can't seem to get it to work! Any ideas? Hi, could you add some details on how you plan to use the code? If this is to complete an assignment, it may be better to choose a solution which encapsulates the "Pythonic" way. However, if efficiency is your concern, then the "Pythonic" way is unlikely to be the most efficient solution. Advising us on these details will help solutions aim to solve your problem. – M...

How to pass a vector to the dots (…) argument of a function

Image
Clash Royale CLAN TAG #URR8PPP How to pass a vector to the dots (…) argument of a function Several R functions have and arguement ... that allows you to pass an arbitrary number of arguments. A example of this is the paste function, to which you can provide an arbitrary number of arguements. But sometimes, you don't know ahead of time how many arguements you want to pass. ... paste For example, say I want to produce a plot in ggplot, where I want to color points by the combination of two columns: df <- data.frame(x=rnorm(100), y=rnorm(100), cat1=sample(c(TRUE, FALSE), 100), cat2=sample(c(TRUE, FALSE), 100), cat3=sample(c(TRUE, FALSE), 100)) ggplot(df) + aes(x=x, y=y, col=paste(cat1,cat2) + geom_point() But now consider that I want to the list of columns to be colour by to be determined at run-time. I would like to write a function that did something like: library(rlang) color_plot <- function(df, color_by) color_by = lapply(color_by, sym) ggplot(df) + aes(x=x, ...

How to implement dirty state in VueJs

Image
Clash Royale CLAN TAG #URR8PPP How to implement dirty state in VueJs I am new to VueJs and I am working on a form that I want to enable the Save button only when a change occurs at the model. Save My initial though is to compute a dirty function comparing initial model with current. compute Note: This code is not tested, it's here just for an example. var app = new Vue( el: '#app', data: a:0, b:'', c:c1:null, c2:0, c3:'test', initialData: null, mounted(): initialData = JSON.parse(JSON.stringify(data));, computed: isDirty: function () return JSON.stringify(data) === JSON.stringify(initialData) ); Is there a better way of doing this or is there any improvement you could suggest on the above mentioned code? 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.

How would I make a list of tuples of size three into key-value pairs?

Image
Clash Royale CLAN TAG #URR8PPP How would I make a list of tuples of size three into key-value pairs? Objective: 1st number: Key to the second number 2nd number: Value to the first number but key to the third number 3rd number: Value to the second number def make_dictionary_list(old_list): return key: values for key, *values in old_list Input: [(4157, 1, 1), (4157, 1, 10), (4157, 2, 1), (4157, 2, 10), (4157, 3, 1), (4157, 3, 10), (4157, 4, 1), (4157, 4, 10), (4182, 1, 1)] [(4157, 1, 1), (4157, 1, 10), (4157, 2, 1), (4157, 2, 10), (4157, 3, 1), (4157, 3, 10), (4157, 4, 1), (4157, 4, 10), (4182, 1, 1)] Output: 4157: [4, 10], 4182: [1, 1] 4157: [4, 10], 4182: [1, 1] The output is not what I want. As stated above, I'd like the 1st number being key to the 2nd number and 2nd number being the key to the 3rd number. How would I go about doing that? Thanks! you have duplicate keys. – Garr Godfrey 5 mins ago 1 Answer 1 You unravel your list: data = [(4157, 1, 1), (415...

Unresolved resource dependencies [DefaultSchedule] in the Resources block of the template

Image
Clash Royale CLAN TAG #URR8PPP Unresolved resource dependencies [DefaultSchedule] in the Resources block of the template I am working with the cloudformation script to create AWS Data Pipeline. I have created the script according to the documentation but I am facing 1 error i.e. Template validation error: Template format error: Unresolved resource dependencies [DefaultSchedule] in the Resources block of the template Here is the resources part of my script: Resources: DataPipelineForS3Backup: Type: AWS::DataPipeline::Pipeline Properties: Name: Ref: S3BackupDataPipeline Description: Ref: S3BackupDataPipeline Activate: 'true' ParameterObjects: - Id: myAwsCliCommand Attributes: - Key: description StringValue: Dp command to run - Key: type StringValue: String ParameterValues: - Id: myAwsCliCommand StringValue: Ref: AwsCliCommand PipelineObjects: - Id: DefaultSchedule Name: Every 1 day Fields: - Key: type StringValue: Schedule - Key: period StringValue: 1...

ggplot2: Plotting multiple vectors sequentially

Image
Clash Royale CLAN TAG #URR8PPP ggplot2: Plotting multiple vectors sequentially Suppose I have two vectors, say vec1 <- c(1,2,1,3) vec2 <- c(3,3,2,4) I want to plot both vectors in series, in different colors, on GGPlot. For example, to plot a single vector in series, I could simply do: qplot(seq_along(vec1),vec1)) But I want to plot both in series, so we can pairwise compare the entries visually. The graph would look something like: Thanks! I would suggest looking at the ggplot documentation, essentially you just need a plot canvas with multiple stored vectors or if you convert the vectors in to a df you can just pass the df in. – Mike Tung Aug 8 at 17:36 1 Answer 1 We need to make a data frame from vec1 and vec2 . Since ggplot2 prefers data in long format, we convert df to df_long using gather from the tidyr package (after creating id column using mutate function from the dplyr package). After that it's fairly easy to do the plotting. vec1 ...

Kafka : Check if 2 topics have been caught up

Image
Clash Royale CLAN TAG #URR8PPP Kafka : Check if 2 topics have been caught up I have 2 topics in kafka which I am double writing to. Their offsets are at different commit points to begin with. My consumer starts consuming from the second topic late, but eventually will catch up with the first topic. How can I optimally find out if both of them are caught up ? I am planning to look at a fixed window of previous messages consumed from both the topics and check if the messages consumed are similar in nature. Any ideas of how I can find if they are similar ? Any other ideas of how I can be sure that they have been caught up ? Also, my topic has multiple partitions. The check should include if all partitions have been caught up. List the consumer groups given your application group id – cricket_007 Jul 13 at 3:25 are you writing exactly same amount of messages toboth topics? if so, sum of offsets (topic1) = sum of offsets (topic2) can give you very close results. ...

Macro for template definitions

Image
Clash Royale CLAN TAG #URR8PPP Macro for template definitions I have a problem with alias template, because I have a code which must be compatible with VS 2012, which does not support alias template. Let's say I have an alias template like: template<typename A, typename B> using foo = bar<A,B>; Then it would be very convenient to be able to do something like: #ifdef NO_ALIAS_TEMPLATE_AVAILABLE #define foo<x,y> bar<x,y> #else template<typename A, typename B> using foo = bar<A,B>; #endif However the best I can do is #define foo(x,y) bar<x,y> And I don't want to replace all template specializations in all my code by round brackets, for code readability. Is there any way to have a macro with delimiters <> for its argument? Or is there no simple solution to my problem? If not, how to implement a strict equivalence to alias template? <> 2 Answers 2 No, the preprocessor cannot use <> to delimit mac...

Import column from excel file with path into array

Image
Clash Royale CLAN TAG #URR8PPP Import column from excel file with path into array Is there a faster way to import a column from a specific excel file as an array with VBA? The code that I'm currently using has to open the excel file. Is there a way to do this in the background ? Is there a way to read values row by row from the first column? Thanks My code below: Sub LoadExcelArray() Dim Vendor As Variant Dim wb As Workbook Dim sFile As String sFile = "D:Desktoptest.xlsx" Application.ScreenUpdating = False Set wb = Application.Workbooks.Open(sFile) Vendor = wb.Sheets(1).Range("A1:A95").Value2 wb.Close False Application.ScreenUpdating = True MsgBox Vendor(30, 1) End Sub 1 Answer 1 What you're already using is the best way in my opinion. But if you're looking for other options: The xlsx file is actually a zip file. You could open it as a zip file and extract the contents. This can be done without starting Excel. So it should be faster. https://m...