Posts

Showing posts from July 25, 2018

Using Vuex with Nuxt and Vue-Native-Websocket

Image
Clash Royale CLAN TAG#URR8PPP Using Vuex with Nuxt and Vue-Native-Websocket I'm trying to fill my vuex store with data from websocket. I'm using Nuxt. For handling websocket I'm using vue-native-websocket package. Connection to websocket is successful, but commiting to the store doesn't work, it fires an error on every socket event Uncaught TypeError: this.store[n] is not a function Uncaught TypeError: this.store[n] is not a function According to Nuxt and vue-native-websocket docs, I've using them as following: Plugin native-websocket.js: import Vue from 'vue' import VueNativeSock from 'vue-native-websocket' import store from '~/store' Vue.use(VueNativeSock, 'wss://dev.example.com/websocket/ws/connect', { store: store }) nuxt.config.js plugins: [ {src: '~plugins/native-websocket.js', ssr: false} ], As the connection is established, I draw a conclusion that the package is connected right, so it's something about store

Java reduce a collection of string to a map of occurence

Image
Clash Royale CLAN TAG#URR8PPP Java reduce a collection of string to a map of occurence Consider the a list as id1_f, id2_d, id3_f, id1_g , how can I use stream to get a reduced map in format of <String, Integer> of statistics like: id1_f, id2_d, id3_f, id1_g <String, Integer> id1 2 id2 1 id3 1 Note: the key is part before _ . Is reduce function can help here? _ reduce 1 Answer 1 This will get the job done: Map<String, Long> map = Stream.of("id1_f", "id2_d", "id3_f", "id1_g") .collect( Collectors.groupingBy(v -> v.substring(0, v.indexOf("_")), Collectors.counting()) ); 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 polic

How to stop app the server express after 'npm start' (In terminal VSCode)

Image
Clash Royale CLAN TAG#URR8PPP How to stop app the server express after 'npm start' (In terminal VSCode) the console gets locked after starting the express server, as the image shows, how can I kill the service? image of terminal of VSCode Have you tried Ctrl+C? – James 11 mins ago is this, thanks – Gustavo Henrique Lima 11 mins ago Possible duplicate of Start, Stop Node express server – LMulvey 11 mins ago is not a duplicate, i asked about terminal, but its a simple doubt. – Gustavo Henrique Lim

Java Reflection make final method non final

Image
Clash Royale CLAN TAG#URR8PPP Java Reflection make final method non final I know the way to make a Field non-final via Reflection. But is there a way to make a method non-final? Somehow the same approach does not work. Field // make all methods non-final Clazz.javaClass.declaredMethods.forEach { method -> method.isAccessible = true val modifiersField = method.javaClass.getDeclaredField("modifiers") modifiersField.isAccessible = true modifiersField.setInt(method, modifiersField.modifiers and Modifier.FINAL.inv()) } Even if it were possible, what do you think that would help? – Kayaman Jan 10 at 16:06 Does that mean its not possible? – Martin Mlostek Jan 10 at 16:09

Google Cloud Function Environmnet Timing out on every functions

Image
Clash Royale CLAN TAG#URR8PPP Google Cloud Function Environmnet Timing out on every functions Edit: I had to rollback to : npm install firebase-functions@v1.10 --save Because apparently v2.0.0 has some system breaking changes. I'll probably make a separate question and answer it in the hopes that some of firebase team here on SO can give us more insight. I don't know what happen but yesterday out of the blue every single one of my google cloud functions began taking the whole 60 seconds (the default timeout limit of GCF). I even copied the all of the code completely into a sister projects environment and and the code ran smoothly with no timeouts so I believe its all the environment and not the code itself. Is there anything anyone can suggest looking into or tests I could run to investigate the cause of this? I am also open to some restart reboot. I simplified a function down below that is timing out in the first environment but not the second. But Again remember I really

Terraform Module - declaring resource name within provisioner block

Image
Clash Royale CLAN TAG#URR8PPP Terraform Module - declaring resource name within provisioner block I'm relatively new to Terraform - I have a module setup as below, the issue I'm having is with the outputs if the module count is '0' when running a terraform plan. Output PW works fine now that I've used the element(concat workaround but the Output I'm having issues with is DCPWUn, I get the following error: Error: Error refreshing state: 1 error(s) occurred: * module.PrimaryDC.output.DCPWUn: At column 21, line 1: rsadecrypt: argument 1 should be type string, got type list in: ${element(concat("${rsadecrypt(aws_spot_instance_request.PrimaryDC.*.password_data,file("${var.PATH_TO_PRIVATE_KEY}"))}", list("")), 0)} resource "aws_spot_instance_request" "PrimaryDC" { wait_for_fulfillment = true provisioner "local-exec" { command = "aws ec2 create-tags --resources ${self.spot_instance_id} --tags Key=

Get date in current time zone in objective - c?

Image
Clash Royale CLAN TAG#URR8PPP Get date in current time zone in objective - c? NSArray *fromD = [setFreeHour valueForKey:@"fromDate"]; NSString *fromdate = fromD[0]; NSDateFormatter *fromDateFormatter = [[NSDateFormatter alloc]init]; [fromDateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"]; NSDate *fromDate = [fromDateFormatter dateFromString:fromdate]; Results : In fromdate = 2018-07-24 11:41:25 In fromDate = 2018-07-24 06:11:25 +0000 So how can i get both the date (fromdate and fromDate) equal or fromDate in Local Time Zone You only have one date. Where is the 2nd date? – rmaddy 16 hours ago one is fromdate and other is fromDate @rmaddy – Mukie 10 hours ago

visual basic increment on cell update

Image
Clash Royale CLAN TAG#URR8PPP visual basic increment on cell update Currently trying to take each cell update and store in a cell that is basically A55 plus one row each update. So start with A55 then next update A56 then A57 so on forever on each update. Current code is stuck at cell 55 though: Private Sub Worksheet_Calculate() Dim target As Range Set target = Range("U13") Dim Counter As Integer Counter = 55 If Not Intersect(target, Range("U13")) Is Nothing Then Cells(Counter, "A").value = target End If Counter = Counter + 1 End Sub Each time this is run, it will start with Counter=55 and the increment, Counter=Counter+1 will not carry over to the next execution. – Rey Juna 5 hours ago Counter=55 Counter=Counter+1

Call an application using System() from another program and input a file

Image
Clash Royale CLAN TAG#URR8PPP Call an application using System() from another program and input a file I have a main file and a secondary file. The secondary file is compiled into an executable that I cannot edit. The secondary file asks for a file name using user input. In order to run the secondary file from the main file, I am using System("secondary.exe"), which then executes the secondary file an prompts the user for input. Is there a way to bypass that input and hard-code in a file name. I tried looking at command line piping and popen but was unable to find an answer. 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.

Android TTS API sounds robotic

Image
Clash Royale CLAN TAG#URR8PPP Android TTS API sounds robotic I'm learning android development for the first time and my goal is to create a simple Hello World application that takes in some text, and reads them out loud. I've based my code off an example I found and here's my code: class MainFeeds : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main_feeds) card.setOnClickListener{ Toast.makeText(this, "Hello", Toast.LENGTH_LONG).show() TTS(this, "Hello this is leo") } } } class TTS(private val activity: Activity, private val message: String) : TextToSpeech.OnInitListener { private val tts: TextToSpeech = TextToSpeech(activity, this) override fun onInit(i: Int) { if (i == TextToSpeech.SUCCESS) { val localeUS = Locale.US val result: Int

PHP/MySQL Dynamically create prepare query

Image
Clash Royale CLAN TAG#URR8PPP PHP/MySQL Dynamically create prepare query I am trying to pass a list of input field's ID that have been modified so I can create a UPDATE query in MySQL only for the modified data. Here is what I have so far.. In jQuery I have the following code that makes a JSON list of all the id's that have had changed input data. The data is added to a hidden input field. updatedFields = ; $('form :input').change(function(){ attr_name = $(this).attr('id'); updatedFields.push({attr_name}) $("#update_fields").val(JSON.stringify(updatedFields)) }); Once that is POSTed, I have an array similar to Array ( [myform] => Array ( [update_fields] => [{"attr_name":"field1"},{"attr_name":"field2"}] [field1] => field1val [field2] => myfield2val [id] => 5 .....other irrelevant/nonmodified fields....... )

Algorithm for removing entries from an array, by removing “middlest” items?

Image
Clash Royale CLAN TAG#URR8PPP Algorithm for removing entries from an array, by removing “middlest” items? Given a list of items of length n , where a maximum number of wanted items is m , and m < n , and in which the items in the list which are most valuable / useful are those that are furthest from any other item. How can I remove items from the list to reduce the size of the list to m . n m m < n m e.g., for [ a, b, c, d, e ] with an m == 2 , we would get [ a, e] [ a, b, c, d, e ] m == 2 [ a, e] e.g., for [ a, b, c, d, e ] with an m == 3 , we would get [ a, c, e ] [ a, b, c, d, e ] m == 3 [ a, c, e ] [ a, b, c, d, e ] m == 4 [ a, b, c, e ] [ a, c, d, e ] Note: I am generalizing a real problem, which is selecting representative frames from a video. The code will be written in python. By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and co

access table data using .idb and .frm file.

Image
Clash Royale CLAN TAG#URR8PPP access table data using .idb and .frm file. I accessed .idb file from data store of mysql,even if database is password protected. So if we can access Mysql database using .idb and .frm file without password then whats the use of database password?? 1 Answer 1 it is important to consider that if you have physical access to the file system then all bets are off. there will always be some piece of 3rd party software etc that will unscramble some database file. the point of a mysql password is to allow access through the allowed pathways to the MYSQL server. to put that in context, a normal user or administrator of a website that is powered by php and mysql would never see or have access to the physical database files. The password level access set up in PHP and MySQL would only allow the application (php) to access what is required. Securing the database files themselves s

Query in Room Database in Android Studio

Image
Clash Royale CLAN TAG#URR8PPP Query in Room Database in Android Studio I have a list of notes in room database. I want to choose the list of specific notes depending on some characteristic. For this propose I add a second field note_second_id to a PrimaryKey: @PrimaryKey(autoGenerate = true) private long note_id; private long note_second_id; Then I create the next query: @Query("SELECT * FROM " + Constants.TABLE_NAME_NOTE + " WHERE note_second_id = :second_id ") List<Note> getNotes(long second_id); When I want to add a new note I use: long j = activityReference.get().dataBase.getNoteDao().insertNote(note); deck.setNote_id(j); deck.setNote_second_id(note000); where methods .setNote_id(), and setNote_second_id() look like: public void setNote_id(long deck_id) {this.note_id = note_id; } public void setNote_second_id(long notesecondid) { this.note_second_id = notesecondid; } and note000 is a constant: L

Stopping a powershell script with a key combo

Image
Clash Royale CLAN TAG#URR8PPP Stopping a powershell script with a key combo I have been trying to stop a loop in powershell using multiple keys. I wanted something that wouldn't be normally or accidentally pressed, like Fn-F8, or any two key combination. I do not want to use ctrl-c, as the program will run in the background and it will have to do some "cleaning up" upon ending. The code I have below will end by pressing a single key, but that is as much as I could figure out. Thanks in advance. $continue = $true while($continue) { if ([console]::KeyAvailable) { echo "Toggle with F12"; $x = [System.Console]::ReadKey() switch ( $x.key) { F8 { $continue = $false } } } else { # Prints a loop is ended Write-Output "1" } } By

Auto sorting in horizontal html table

Image
Clash Royale CLAN TAG#URR8PPP Auto sorting in horizontal html table I'm trying to create a horizontal table which can be sorted automatically. e.g. |Country 1|Country2| Population | 12134| 232312| GPD | 23| 34| I want to sort by Population or GPD. I used to use tablesorter for table problems but I can't find any thing for this. Any help is greatly appreciated. 1 Answer 1 I used to use list.js http://listjs.com/ has good support for sorting tables. See if it fulfills your needs. thanks. This is what i need, but unfortunately, in the previous version we used <table> too much. changing to <li> would be a real challenge. – dolphin Jul 14 '14 at 15:20 By click

How to do string comparison in VBA if a string has an inequality operator?

Image
Clash Royale CLAN TAG#URR8PPP How to do string comparison in VBA if a string has an inequality operator? I have an Excel sheet that can have the following string in one of its cells: Valid Test for ≥ 30% ABCD? When I capture this value in a variable and output it in the Immediate window, it looks like this: ?strVal Valid Test for = 30% ABCD? I want to check whether the cell contains this value, and currently I'm using: Select Case strVal Case "Valid Test for = 30% ABCD?" doSomething '... other Case statements Case Else doSomethingElse End Select This string match always fails, though, and I get the following results when I investigate in the Immediate window: ?strVal="Valid Test for = 30% ABCD?" False ?asc(mid(strVal,16,1)) 61 ?asc("=") 61 So apparently what's happening here is that the "≥" symbol is being rendered in VBA output as "=" both in appearance and ASCII code, but somehow it's stil