Skip to main content

Posts

Init and use a js module in Laravel Blade

I am trying to do something simple in laravel. I have a simple js module but I am unable to init it with laravel (laravel-mix to compile). To test I want to do something as simple as: <button onclick="console.log(Test.sum);">Print</button> Uncaught TypeError: Cannot read properties of undefined (reading 'sum') test.js var Test = function() { var a = 0; var b = 1; var _sum = function() { return a + b; } return { sum: function() { _sum(); } }; }(); app.js const Test = require('./test'); My question, what is the propper way to init this module to use in my html web? thanks a lot! Solution: test.js var test = function() { var a = 0; var b = 1; var sum = function() { return a + b; } return { sum: function() { return sum(); } }; }(); export { test } app.js import { test } from './test'; window.test = test ; Vi

When does a pg.pool call return?

I have a series of database calls that I need to execute in serial, not in parallel. Despite using the execute_sequentially promise_factory pattern described at: https://pouchdb.com/2015/05/18/we-have-a-problem-with-promises.html The back-end believes the promises to make each DB call are running in serial, as they should be. The database shows that multiple queries are starting before the first one finishes; this is a problem. So I think the DB is telling the back end it can continue before it finishes running the query. But I've struck out looking for documentation to explain that timing. Does the DB wait for the query to finish before it tells the back end that it can continue, or not? More details: Each function call stacks "decks" of "cards" atop the existing pile. If the function runs in serial, everything should be correct. When they run in parallel, multiple cards end up at the same height, and that's an error condition. For example, if I have

Remove elements in elements of alist Python

I have a list that looks like that: [{'ip': 'x.x.x.x', 'error': True, 'reason': 'Reserved IP Address', 'reserved': True, 'version': 'IPv4'}, {'ip': 'x.x.x.x', 'error': True, 'reason': 'Reserved IP Address', 'reserved': True, 'version': 'IPv4'}, {'ip': 'x.x.x.x', 'version': 'IPv4', 'city': 'Munich', 'region': 'Bavaria', 'country': 'DE', 'country_name': 'Germany', 'country_code': 'DE', 'country_code_iso3': 'DEU', 'country_capital': 'Berlin'}, {'ip': 'x.x.x.x', 'version': 'IPv4', 'city': 'Düsseldorf', 'region': 'North Rhine-Westphalia', 'country': 'DE', 'country_name': 'Germany',

Javascript insensitive sort table on click

I'm a totally fresh JS guy so please be understandable. In my app I want to give the user ability to filter data in my table when he/she clicks on the header (sorting on click). What I have is a JS file which sorts everything as except for one column - full_name , it seems like it's sorting case sensitive: Which I thought I was handling by innerHTML.toUpperCase , am I wrong? Snippet with sample html table below: function sortTable(n) { var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0; table = document.getElementById("data_table"); switching = true; dir = "asc"; while (switching) { switching = false; rows = table.rows; for (i = 1; i < (rows.length - 1); i++) { shouldSwitch = false; x = rows[i].getElementsByTagName("TD")[n]; y = rows[i + 1].getElementsByTagName("TD")[n]; if (dir == "asc") { if (x.innerHTML.toUpperCase() > y.innerHTML.toUpperCa

get a list of tuples with the columns that have only two same strings:

I have the following problem: In case I want to get the columns of a dataframe which have all same strings I use the code that follows: Let's create the dataframe first: df_example1 = pd.DataFrame({'A':[1,2,3],'B':[1,2,3]}) . Now let's look for the columns that have exactly the same strings: [(i, j) for i,j in combinations(df_example1, 2) if df_example1[i].equals(df_example1[j])] The code returns the tuple [('A', 'B')] My problem is: In case I want to get a tuple of columns which have ONLY two of the strings the same what code should I use? Let's say that my dataframe is the following: df_example2 = pd.DataFrame({'A':[2,3,4],'B':[1,2,3]}) and it should return the tuple [('A', 'B')]. Thank you in advance :) source https://stackoverflow.com/questions/71145913/get-a-list-of-tuples-with-the-columns-that-have-only-two-same-strings

Using JavaScript to Check Multiple Checkboxes

I have a form, within it is a table with multiple checkboxes and text input boxes. The checkboxes do not have ids, only different attributes. I want to check off multiple boxes when I run the script in the console. I cannot edit the HTML. This is what I've got so far, but I'm not sure how to get it to work, or if it is even possible. Thanks for any help. function chk () { document.querySelector('[name="A"]').checked = true; } <form> <table> <TR> <TD align="left"><INPUT TYPE=CHECKBOX NAME="A">A:</TD> <TD align="right"><input type="text" name="effDateTxtA" value="" class="detailstyle"></TD> </TR> </table> </form> Via Active questions tagged javascript - Stack Overflow https://ift.tt/lUEqm3v

I need to get a random value in a string from JSON

I have the following code where I need to get a random value: const namesJson = { "nombre1": "Raghat", "nombre2": "Uhmla", "nombre3": "Borto" }; const btnName = document.getElementById('btn') btnName.onclick = function names() { var properties = Object.getOwnPropertyNames(namesJson); var index = Math.floor(Math.random() * properties.length); var output = {}; output[properties[index]] = namesJson[properties[index]]; document.getElementById("mensaje").innerHTML = JSON.stringify(output); } <button type="button" id="btn">Get random name</button> <h2>Mensaje:</h2> <div id="mensaje"></div> With this I have {"nombre2": "Uhmla"} I want to get the value like Uhmla , how can I do? Via Active questions tagged javascript - Stack Overflow https://ift.tt/ptlUGjN