Posts

Showing posts from July 7, 2018

How to check if web service is available without using credentials

How to check if web service is available without using credentials I have a WPF app written in c# and it is supposed to work in offline and online both. I have a class that checks for connectivity to web service using following skeleton code :- var url = "https://somesite.com/mywebservice.svc"; var myRequest = (HttpWebRequest)WebRequest.Create(url); var response = (HttpWebResponse)myRequest.GetResponse(); if (response.StatusCode == HttpStatusCode.OK) { Debug.Write(string.Format("{0} Available", url)); } else { // error } The issue is the web service requires authentication and hence an "unauthorized" exception is always thrown. Although the exception means the service is available but it is logged at network level and causes security alarm as the check is every 10 seconds. Is there a way to check the authenticated service availability without u

How to fetch parents based on their child's records

How to fetch parents based on their child's records I have two models like company.rb class Company < ApplicationRecord has_many :posts end post.rb class Post < ApplicationRecord belongs_to :company scope :notClosed, -> {where(closed: false)} scope :published, -> {where(published: true)} end I want to fetch companies which carries at least one post with matching post scope scope Currently my queries is Company.where(company_type: "Private").all It's return all companies but how to modify this query for my needs. I want to fetch companies which carries at least one post , actually, an INNER JOIN keyword would return the companies with posts associated, you can append a distinct statement to get non-repeated records. Can you explain further what you're trying to do? – Sebastian Palma Jul 2 at 3:55

Angular 6 Http Request Json Headers Doesn't Works

Image
Angular 6 Http Request Json Headers Doesn't Works I'm just trying to make a post using Angular 6 HttpClient, but the problem is that it doesn't send the data if HttpHeaders is in the options params. That just happens with 'Content-Type': 'application/json'. AuthComponentTS: import {Injectable} from '@angular/core'; import {Observable} from 'rxjs'; import {HttpClient, HttpHeaders} from '@angular/common/http'; @Injectable({ providedIn: 'root' }) export class AuthService { httpOptions = {headers: new HttpHeaders({ 'Content-Type': 'application/json' })}; api = 'http://localhost:3000/api/login'; constructor(private http: HttpClient) {} login(form): Observable<any> { const body = JSON.stringify(form); console.log(form); return this.http.post<any>(this.api, body, this.httpOptions); } authenticationHandler(): boolean { const token = sessionStorage.getItem('token'

Disabling zooming on webview

Disabling zooming on webview I've searched around, but I couldn't find how to disable zooming in iOS. I have this in my viewDidLoad() but it doesn't do anything. viewDidLoad() webView.scrollView.isMultipleTouchEnabled = false; Any ideas? 2 Answers 2 You can disable zooming like this: webView.scalesPageToFit = NO; webView.multipleTouchEnabled = NO; I'm trying to disable zooming though, not scrolling – Sam 5 hours ago @Sam Sorry, I misread the question. – hev1 5 hours ago no worries, but isn't this Obj-C? Cause they spew errors saying: Value of type 'WKWebVi

Getting “Transaction not successfully started”

Getting “Transaction not successfully started” I got this WARN everytime I inserted / updated to DB. But my data is still saved, though. Still, I want to get rid of this from my log file. Below is my log file: [WARN] TapestryIOCModule.PerthreadManager Error invoking listener org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl@41c045: Transaction not successfully started org.hibernate.TransactionException: Transaction not successfully started at org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:179) at org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.threadDidCleanup(HibernateSessionManagerImpl.java:65) at org.apache.tapestry5.ioc.internal.services.PerthreadManagerImpl.cleanup(PerthreadManagerImpl.java:128) at org.apache.tapestry5.ioc.internal.RegistryImpl.cleanupThread(RegistryImpl.java:445) at org.apache.tapestry5.ioc.internal.RegistryWrapper.cleanupThread(RegistryWrapper.java:38) at org.apache.tapestry5.TapestryFilter.doFilter(

Extracting data from a complex MongoDB database using PyMongo and converting it to a .csv file

Extracting data from a complex MongoDB database using PyMongo and converting it to a .csv file I have a complex MongoDB database, consisting of documents nested upto 7 levels deep. I need to use PyMongo to extract the data, and then convert the extracted data to a .csv file. What have you tried so far? – Adam Smith Jul 2 at 4:08 Can you use mongoexport? – Astro Jul 2 at 4:11 So far I am able to extract the entire database and store it as a Python object. I am then able to convert this object to a .csv file. However the .csv file has thousands of columns. I need to know how I can extract the data in a clean manner. – pack24 Jul 2 at

access particular set of pixels MTLTexture in melal

access particular set of pixels MTLTexture in melal I created a MTLtexture using UIImage data as follows. var texture = metalView.currentDrawable!.texture let uiImg = createImageFromCurrentDrawable() guard let device = metalView.device else { fatalError("Device not created. Run on a physical device") } let textureLoader = MTKTextureLoader(device:device) let imageData: NSData = UIImagePNGRepresentation(uiImg)! as NSData texture = try! textureLoader.newTexture(data: imageData as Data, options: [MTKTextureLoader.Option.allocateMipmaps : (false as NSNumber)]) what I need to do is change pixels color in MTLTexture.Not all of them.So Is it possible to access particular set of pixels in MTLtexture and write into it in metal? 1 Answer 1 Yes, as a look at the MTLTexture documentation would have shown you. You can use one of the getBytes() methods to copy a region of texture data ou

RedirectMatch not workding with Forward Chaining Proxy in Apache

RedirectMatch not workding with Forward Chaining Proxy in Apache I am trying to configure apache server as a forward proxy chaining to another (internet)proxy while at the same time including RedirectMatch directives to redirect certain urls to the local host instead of chaining to the remote proxy. diagram http://www.plantuml.com/plantuml/png/TP7DIiH03CVlUOhGUt6zBQMKLK4GL9O57s1s6cbXd9GqQzUtDsLBwTHwcKFoc_y7EVJgH2zV0SvynUpub45dWzQtdOkAZy93JvBCieVE-OQA_Mw_ox0iFra69pLsmjUVgjfcxqToeBE9VPCOHR56iqpevvlISHHA5YzHII8fm1G8ysgLey2B1711yKHrA-JrpQblvWzbdl_v8HE9oXZOkz1mhvRrBjBmSNfTcYLD2bm19fuGGA4dVETRXDGshvAUK_3bo92vyTRQtERzIdnSBTd_wyDu0JZOOyV_1G00 The redirect without the forward proxy chaining directives works. The forward proxy chaining works with or without the redirect directive but if I have both the redirect and the chaining configured any url that matches the redirect returns a 404 Here is a copy of the conf ServerRoot "c:/bin/Apache24" Listen 81 ... Listen 8080 <VirtualHost *:8

pandas merge: merge two dataframes on same column but keep different columns

pandas merge: merge two dataframes on same column but keep different columns I have two pandas dataFrames that share one common column name. I would like to merge on the common column name but keep all the different columns from the second dataFrame where there's a match on the common column name. Here's an example of the two dataFrames: DF1: A B C D E F G H value value value value value value value value value value value value value value value value value value value value value value value value etc. DF2: A I J K L value value value value value value value value value value value value value value value I would like the expected result to be: Result: A B C D E F G H I J K L value value value value value value value value value value value value value value value value value value value value value value value va

Javafx How to display image captured from web cam in imageview in another scene

Image
Javafx How to display image captured from web cam in imageview in another scene I have this fxml layout. When I click on take photo it opens a screen for me to take a picture using web cam Dialog layout to take pic from web cam I want the picture captured on the web cam to replace the dummy image on the fxml layout beside take photo button.Here are my files: FXML layout containing dummy image and take photo button <HBox prefHeight="79.0" prefWidth="232.0" spacing="30.0"> <children> <VBox prefHeight="100.0" prefWidth="100.0"> <children> <ImageView fx:id="profilePic" fitHeight="99.0" fitWidth="118.0" nodeOrientation="INHERIT" pickOnBounds="true"> <image> <Image url="@../images/profile_photo.png" /> </image> </ImageView> </chil

tf.gather_nd is really slow when used for many times

tf.gather_nd is really slow when used for many times I would like a loss function in tensorflow which is a complex combination of many elements. For example, this code: import tensorflow as tf import numpy as np import time input_layer = tf.placeholder(tf.float64, shape=[64,4]) output_layer = input_layer + 0.5*tf.tanh(tf.Variable(tf.random_uniform(shape=[64,4], minval=-1,maxval=1,dtype=tf.float64))) # random_combination is 2-d numpy array of the form: # [[32, 34, 23, 56],[23,54,33,21],...] random_combination = np.random.randint(64, size=(210000000, 4)) # a collector to collect the values collector= print('start looping') print(time.asctime(time.localtime(time.time()))) # loop through random_combination and pick the elements of output_layer for i in range(len(random_combination)): [i,j,k,l] = [random_combination[i][0],random_combination[i][1], random_combination[i][2],random_combination[i][3]] # pi

Android ProgressBar size take whole screen

Android ProgressBar size take whole screen I'm trying to implement an Android ProgressBar but its size is taking the whole screen. I've followed a couple of examples but it didn't make any effect. Here is my code <ProgressBar android:id="@+id/progress" android:layout_width="wrap_content" android:layout_height="wrap_content" android:indeterminate="false" android:padding="45dp" android:visibility="gone" /> Post your code so we know what's the problem is – Tam Huynh Jul 2 at 3:09 post a screenshot...and always post your code.... – Abhi Jul 2 at 4:05

Can't bind chart-data from component to view. Angular 6, predix-ui

Can't bind chart-data from component to view. Angular 6, predix-ui pls help. SOS I'm trying to bind chart-data to plot graph, like: [attr.chart-data]='chartData' But in console of browser I have only warning that: Polymer::Attributes: couldn`t decode Array as JSON My Component: export class AppComponent { arr: Array<Object> = ; seriesConfig: {}; ngOnInit(): void { this.arr = [ { x: 1530426560000, y: 179.46 }, { x: 1530426570000, y: 179.58 }, { x: 1530426580000, y: 179.58 }, { x: 1530426590000, y: 179.6 }, { x: 1530426600000, y: 179.52 }, { x: 1530426610000, y: 179.56 }, { x: 1530426620000, y: 179.52 }, { x: 1530426630000, y: 179.52 } ]; this.seriesConfig = { y: { type: "line", name: "series1", x: "x", y: "y" } }; } } My View: <div> <h2 id="title-tag">Timeseries</h2> <px-vis-timeseries id="ts1" prev

Two different pages get clipped with login and signUp page display in android xml layout

Image
Two different pages get clipped with login and signUp page display in android xml layout Login And SignUp Screen How to implement and write xml file like this image? Please Help me. 2 Answers 2 Create layout like this, <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:weightSum="2" tools:context=".MainActivity"> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="1.90" android:orientation="vertical"> <!-- put your Login page content ,email ,passw

How can i block a specific URL while my site fetches each and every video and user pages from youtube using V3 api?

How can i block a specific URL while my site fetches each and every video and user pages from youtube using V3 api? I use php script to fetch video pages and user pages from youtube using api v3, the script includes the blocking of videos feature but does not support blocking user pages, my hosting team is unable to help me out, so iam here at stackoverflow seeking help. Please provide some detail explanation .. and in my opinion you have to read api documentation – Er. Amit Joshi Jul 2 at 4:12 Hey there, i want to block specific pages fetched by youtube api, ( what currently scrpot does, it fetch all urls) – Decent Nil Jul 2 at 4:14 put those url's or id's of

Why 'this' is referring to Window object in below code snippet?

Why 'this' is referring to Window object in below code snippet? Can someone help me understand why the below code prints Inside splitName function = [object Window] Why 'this' is referring to Window object? let emp = { fName: '', lName: '', setName: function(name) { console.log("Inside setName function = " + this) let splitName = function(n) { console.log("Inside splitName function = " + this) let nameArr = n.split(' '); this.fName = nameArr[0]; this.lName = nameArr[1]; } splitName(name); } } emp.setName('ABC DEF'); console.log(window.fName); Because splitName(name); has no calling context – CertainPerformance Jul 2 at 3:39 splitName(name); Also because it is run in non-strict mode, otherwise it wo

Copying to a specific sheet: openpyxl - destination sheet ignored when using copy_worksheet

Copying to a specific sheet: openpyxl - destination sheet ignored when using copy_worksheet Per this answer and these documents I tried to specify a source and target sheet to write to, but when I do, the results are the same as if I hadn't specified a target: source target from openpyxl import load_workbook wb = load_workbook('MyFile.xlsx') ws = 'Sheet1' idx = book.index(ws) new_ws = 'Test' book.create_sheet(new_ws, idx+1) source = book[ws] target = book[new_ws] target = book.copy_worksheet(source) wb.save('Output.xlsx') vs source = book[ws] book.copy_worksheet(source) wb.save('Output.xlsx') Both result in a new worksheet called Sheet1 Copy added to the end of the workbook. How to a copy a sheet into another empty sheet, or specific location within the workbook? Sheet1 Copy 1 Answer 1 I'm still not sure if there's a bug in the ability for copy_

Python-JIRA unable to add_worklog of previous day

Python-JIRA unable to add_worklog of previous day I have pasted my python code for jira to add the work-log but it is not working.Something is not working with "started" argument of the jira.add_worklog API.Kindly help to resolve. Preferable if you provide the suitable example on this. from jira.client import JIRA import time now = time.strftime("%A ""%c") options ={'server': 'http://192.168.100.39:8081/'} jira= JIRA(options, basic_auth=('chaitanya.mehta','qa123*')) jira.add_worklog("SVC-2531", timeSpent="15m", comment= "DSM for 20 June'18", started="2018-06-20T08:21:01.273+0000") print("Worklog successfully done at %s" %now) 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 websit

Getting Mathematical Errors Trying to calculate base price of gas

Getting Mathematical Errors Trying to calculate base price of gas I am trying to solve a problem that requires me to write code to find the base price of a gallon of gas. I am provided with the cost of a gallon of gas, the amount of federal and state tax, and the percent for sales tax. I've tried formatting the equation a couple different ways and the math is always wrong. This is the closest I've gotten (the output is $3.289 which is only .073 cents off, which when I do the calculations by hand happens to be the amount of sales tax so it is as if it is ignoring the end of the equation completely). Could I please get some assistance? I've included the entire problem I was given below. double pumpPrice=3.89, fedTax=.184, stateTax=.417, salesTax=2.25; double basePrice, totalTax, percentTax, profit_bigOil ; basePrice = pumpPrice-fedTax-stateTax-((salesTax*basePrice)/100) ; cout <<"The base price for a gallon of gas is $" <<basePrice << endl; Create