Posts

Showing posts from July 6, 2018

Adding new element(s) to Spinner Adapter

Adding new element(s) to Spinner Adapter I'm new to Kotlin language and I'm going to load Spinner data from the website. For this reason, I used Fuel Library as my httpGet , httpPost and ... helper library and simply the Spinner Control for showing that data to the user. Below is my tried code: Kotlin Spinner httpGet httpPost Spinner var listOfLesson:List<String> = listOf() override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.ostad_page) val adapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, listOfLesson) "home/GetAllLessons".httpGet().responseString { request, response, result -> when (result) { is Result.Success -> { val lessonsArray: List<tblLesson> = Gson().fromJson(result.value, Array<tblLesson>::class.java).toList() var index:Int = 0 for (lesson: tblLesso...

c# UserControl constructor don't throws exceptions as expected

c# UserControl constructor don't throws exceptions as expected This is my WinForm solution entry point in Program.cs: try { Application.Run(new MainForm()); } catch (Exception e) { Log.error(e.ToString()); ErrorHandlerForm abend = new ErrorHandlerForm(e); abend.ShowDialog(); } It works fine, every exception thrown in my solution is gracefully handled! But today I found an issue: My program don't catch exceptions that occurs in UserControls construstors! It simply crash to windows with the ugly system prompt (or it shows the error in the VisualStudio if i am in debug mode). I don't understand this behaviour and I have no idea how to fix it, I want to catch those exception in my catch block. what error do you get in Visual studio when in debug mode ? – Prany Jul 1 at 17:13 ...

code breaker program in python is not working properly [closed]

code breaker program in python is not working properly [closed] enter code here import random digits = list(range(10)) random.shuffle(digits) print(digits) my_list = [str(item) for item in digits [:3]] print (my_list) digits = (''.join (my_list)) print (digits) guesses = 0 while guesses <=3: if(guesses == 3): break guess = input('What is your guess ? :- ' ) tmp = '' for i in guess: if i.isdigit(): tmp += i guess = tmp[:3] print(guess) count = 0 for i in range(3): for j in range(3): if digits[i] == guess[j] : #if i == j: count = count + 1 exit() if count == 3 : print('found:',end = ' ') print('YOU WON') exit() break elif ((count>0) and (count <3)) : print('near:',end = ' ') else: print('nope' , end = ' ') guesses +=1 This question appears to be off-topic. The users who voted to close gave this specific reason: ...

the rules behind treeshaking with an npm module and webpack

the rules behind treeshaking with an npm module and webpack If I have an npm package that exports all its components from 1 index.js file: export * from './components/A'; export * from './components/B'; Then if I have another package that consumes this package: import {A} from 'my-package'; Will the contents of components/B be bundled even though it is never used in the consuming package? components/B Is there a way around this? 1 Answer 1 Doing this: export * from './components/A'; export * from './components/B'; Is the same as doing: export class A () ... export class B () ... If you just import {A}... you are telling webpack that what you only cares about is A. import {A}... By using named imports, webpack is capable of only bundling the content of A and not bundling B in the final output. TL;TR: Always use named exports/imports if you want to have an opt...

Entity Framework like ORM for Cosmos DB

Entity Framework like ORM for Cosmos DB I am looking for any ORM for Cosmos DB. Most of the client which have been mentioned in samples create a new connection to table when they need i.e. there is no connection pooling policy. It seems creating new connection always as is given in samples is non scalable. Please correct me if I am wrong. And does anyone have any good ORM solution which comes with connection pooling 2 Answers 2 Cosmonaut is exactly what you're looking for. It is a simple and minimalistic object mapper, which creates a collection-to-object relationship. You can use your POCO objects and do all the CRUD operations. It supports collection sharing in order to reduce the cost of having multiple objects in one collection as well. Read more about Cosmonaut here. Disclaimer, I am the creator of Cosmonaut. Great to know that you're the creator of Cosmonaut...

How to call dynamic url in Guzzle with GET request

How to call dynamic url in Guzzle with GET request I'm using Laravel and Guzzle and i want to call java spring rest api and get result from dynamic url : http://localhost:8080/api/clients/clientAvailability/{id} .With static url (http://localhost:8080/api/clients/clientAvailability/9976 everything works great but for dynamic i don't know how to solve it. Rest api which i want to call Controller (function for call rest api) $url='http://localhost:8080/api/clients/clientAvailability/9976'; try{ $client = new Client(); $response = $client->request('GET', $url); $body = $response->getBody(); $status = 'true'; $message = 'Data found!'; return view('chart.clientProfile', ['clients' => $body]); // is thrown for 400 level errors }catch(ClientException $ce){ $status = 'false'; $message = $ce->getMessage(); $data = ; //In the event of a networking error (connect...

I want to populate value in Dataframe based on matching values in other Dataframe

I want to populate value in Dataframe based on matching values in other Dataframe I am editing the question. I dont want to use groupby to use group values. I would appreciate if someone could help with just the query to transform data in the following way: I have one dataframe given as follows: df1: col1 col2 ------------ VG 12 G 11 A 10 P 06 VP 0 I want the new dataframe such as: df2: VG G A P VP --------------------- 12 11 10 06 0 I tried achieving this using if condition and I got following error: Code: if df1.Score=='VG': df2['VG']=df1.loc[df1['col1'] == 'VG', 'col2'] The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all() 3 Answers 3 agg and transform would work :) agg transform df.groupby('col1').agg(list).col2.transform(pd.Series).T.fillna(0) ...

Mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO)

Mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) I'm using xampp. I also downloaded MySQL Database. Then I have created a database with Mysql Database, with Then I start Xampp Apache and Mysql. When I try to connect to localhost:8080/phpmyadmin, I receive this kind of error: Messaggio di MySQL: Documentazione Impossibile connettersi: impostazioni non valide. mysqli_real_connect(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) phpMyAdmin ha provato a connettersi al server MySQL, e il server ha rifiutato la connessione. Si dovrebbe controllare il nome dell'host, l'username e la password nel file di configurazione ed assicurarsi che corrispondano alle informazioni fornite dall'amministratore del server MySQL. So I think that I should modify the file: config.inc.php but the problems are: config.inc.php Can you help me to solve this problem? I need t...

Comparable arrays in Kotlin

Comparable arrays in Kotlin Coming from a Swift world I'm trying to figure out how to use comparable functions like min() or max() on an array of objects. In Swift I would use the comparable protocol - min() max() class Car: Comparable { let year: Int static func < (lhs: Car, rhs: Car) -> Bool { return lhs.year < rhs.year } static func == (lhs: Car, rhs: Car) -> Bool { return lhs.year == rhs.year } } But how would you do the same in Kotlin? I've tried this but I'm not sure if it's the right approach, or how I would implement the iterable function - data class Car(val year: Int): Comparable<Car>, Iterable<Car> { override fun compareTo(other: Car) = when { this.year < other.year -> -1 this.year > other.year -> 1 else -> 0 } override fun iterator(): Iterator<Car> { TODO("not implemented") } } So your end g...

Am I going down the right path? - Programming Beginner [closed]

Am I going down the right path? - Programming Beginner [closed] Okay so, I am basically a beginner to Java and only recently started to code in Java for a school project of which I have to complete by the end of 2019 or so. Although I have dug right into the development of the game, as I started to code the menu for my game all I knew about Java was how encapsulation, inheritance and constructors work. As a result it was very hard for me to code my menu, I went through multiple youtube videos only to find one that explained it simply for beginners like me eventually leading me to finishing the menu for my game. If I was to code the menu for my game again I feel as if I could not code it. Is this how I should start off coding? (If you have any useful starting websites please let me know, and the course name if you know a helpful one in particular) Is it expected for beginners to code a game from scratch? Is it ideal for me to code the entirety of my game using tutorials? What would be t...

SQL Query to show instock always but do 2 lots of ordering

SQL Query to show instock always but do 2 lots of ordering Not sure how this would work but I can give a brief description. I have database I want to sort but kind of sort twice in same statement. I have products, some in stock and some out of stock, I want to always show in stock before any out of stock regardless of sorting order. So it will sort A-Z of all in stock items first and the same query has to then show A-Z of out of stock. Sorting in price order would show Low-High of in stock and then do the same for out of stock again in same query. Basically, I want to be sure they can always see all the in stock items first at all times. 1 Answer 1 You can use multiple terms in the order by clause: order by SELECT * FROM products ORDER BY in_stock DESC, name ASC By clicking "Post Your Answer", you acknowledge that you have read our updated...

jQuery - how to get the final link after redirects to load() the content from URL?

jQuery - how to get the final link after redirects to load() the content from URL? I want to use jQuery's load() function to load content from an element on another page getting link from the current page. This is currently my code: load() $(document).ready(function() { var $target = $('#post').find('h2 a').attr('href'); $(".content").load($target + ".breadcrumb"); }); But this doesn't load content from the linked page, because the link isn't direct. There is a link that redirects to the final page. So jQuery loads a redirect from that link and takes me to the final page, instead of loading it on the current one. How can I take the final URL and then assign it to the variable, then load the content from the final link without redirect? E.g attr of a href is "example.com/reports/29025/?action=find" . "example.com/reports/29025/?action=find" When you click on this link you are redirected to e.g: "ex...

Web scrapping of masked URL using VBA

Image
Web scrapping of masked URL using VBA I want to scrape some stock data from a website https://dps.psx.com.pk/ using VBA in Excel, but the problem is the URL of this website does not change. When I click on market summary as highlighted in the below image that will return the whole market summary, I just need to scrape data in Excel using VBA as highlighted in the following image: Did you look at the requests being made when you search for "EFOODS"? – antfuentes87 Jul 1 at 16:30 This is basic web scraping. You need to inspect the source code elements and like @antfuentes87 says , follow the requests. It sounds more like you need to purchase a third party tool to help you. It's also called "scrape" and "scraping" – dbmitch Jul 1 at 16:44 ...

Maven Class path error multiple SLF4J bindings

Maven Class path error multiple SLF4J bindings I have been getting this error while trying to do a MAVEN INSTALL. I tried exclusions, but not sure the where to include in pom file. Let me how and what exclusion tags should i include in my pom file. I am also attaching my pom file snippet where to include the exclusions`SLF4J: Class path contains multiple SLF4J bindings. SLF4J: Found binding in [jar:file:/C:/Users/147188/.m2/repository/ch/qos/logback/logback-classic/1.2.3/logback-classic-1.2.3.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: Found binding in [jar:file:/C:/Users/147188/.m2/repository/org/apache/logging/log4j/log4j-slf4j-impl/2.10.0/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class] SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder] POM file: <!-- Start of required part to make log4j work --> <dependency> ...

Can't properly compile and run program - No Class Def Found Error

Can't properly compile and run program - No Class Def Found Error Source code I'd like to properly compile and run the program, but the solutions I've tried aren't working. javac src/main/java/ReceitoDromo.java Output Note: ReceitoDromo.java uses unchecked or unsafe operations Note: Recompile with -Xlint:unchecked Exception java src.main.java.ReceitoDromo Error: Could not find or load main class src.main.java.ReceitoDromo open the command line, go to the folders where your ReceitoDromo.class file is, and invoke java ReceitoDromo . What is your output? – Daniele Jul 1 at 17:49 ReceitoDromo.class java ReceitoDromo 1 Answer 1 There might be some syntax error in code. Mostly it happens when you use collections without type specifiers. eg- yo...

Getting Bootstrap broker ip:9092 disconnected error from kafka spout

Getting Bootstrap broker ip:9092 disconnected error from kafka spout Versions: "org.apache.storm" % "storm-kafka-client" % "1.2.1" "org.apache.storm" % "storm-core" % "1.2.1" % "compile" Kafka: 0.10.1.0 I am getting following error/warnings, running in localCluster, from my kafka spout: 2018-06-28 00:00:34,930 AppInfoParser [INFO] Kafka version : 0.10.1.0 2018-06-28 00:00:34,930 AppInfoParser [INFO] Kafka commitId : 3402a74efb23d1d4 2018-06-28 00:00:34,931 WARN NetworkClient [Thread-40-KafkaSpout-executor[12 12]] Bootstrap broker ip1:9092 disconnected 2018-06-28 00:00:35,092 WARN NetworkClient [Thread-40-KafkaSpout-executor[12 12]] Bootstrap broker ip2:9092 disconnected 2018-06-28 00:00:35,251 WARN NetworkClient [Thread-40-KafkaSpout-executor[12 12]] Bootstrap broker ip3:9092 disconnected 2018-06-28 00:00:35,524 WARN NetworkClient [Thread-40-KafkaSpout-executor[12 12]] Bootstrap broker ip4:9092 disconnected 2018-06-2...

ReactJS - Axios doesn't return data

Image
ReactJS - Axios doesn't return data I have this code to get data with Axios. Unfortunately, this code is not working because the console.log(response); is not logging any data in the console. What is wrong here? Is there something missing? console.log(response); const ROOT_URL = "https://jsonplaceholder.typicode.com"; const getFindAll = (data) => { return { type: constants.FETCH_FIND_ALL, payload: data } } export const fetchFindAll = () => { return (dispatch) => { axios({ method: 'put', url: `${ROOT_URL}/posts/1` }) .then(response => { console.log(response); dispatch(getFindAll(response.data.Body.Message)); }) .catch(error => { //TODO: handle the error when implemented }) } } I'm calling the fetchFindAll() inside FileTree component: fetchFindAll() FileTree export class FileTree extends React.Component { constructor(props) { super(props); this.state = ...

Does Azure Service Fabric do the same thing as Docker?

Does Azure Service Fabric do the same thing as Docker? My thinking is that people use Docker to be sure that local environment is the same as production and that I they can stop thinking about where are their apps running physically and balancing mechanisms should just allocate apps in best places for that moment. I'm 100% web based and I'm going to move to cloud together with our databases, and what cannot be moved will be seamlessly bridged so the corporate stuff and the cloud will become one subnetwork. And so I'm wondering, maybe Service Fabric already does the same thing that Docker does plus it gives as address translation service (fabric:// that acts a bit like DNS for the processes in fabric space) plus (important for some) encourages on demand worker allocation - huge scalability perk. 2 Answers 2 It's confusing since Docker (the company) is trying to stake claims in everyth...

Trouble with deserializing Avro data in Scala

Trouble with deserializing Avro data in Scala I am building an Apache Flink application in Scala which reads streaming data from a Kafka bus and then performs summarizing operations on it. The data from Kafka is in Avro format and needs a special Deserialization class. I found this scala class AvroDeserializationScehema (http://codegists.com/snippet/scala/avrodeserializationschemascala_saveveltri_scala): package org.myorg.quickstart import org.apache.avro.io.BinaryDecoder import org.apache.avro.io.DatumReader import org.apache.avro.io.DecoderFactory import org.apache.avro.reflect.ReflectDatumReader import org.apache.avro.specific.{SpecificDatumReader, SpecificRecordBase} import org.apache.flink.api.common.typeinfo.TypeInformation import org.apache.flink.api.java.typeutils.TypeExtractor import org.apache.flink.api.common.serialization._ import java.io.IOException class AvroDeserializationSchema[T](val avroType: Class[T]) extends DeserializationSchema[T] { private var reader: DatumRead...