Posts

Uncaught Error: Objects are not valid as a React child when trying to render html in react

Image
Clash Royale CLAN TAG #URR8PPP Uncaught Error: Objects are not valid as a React child when trying to render html in react Here's a simple version my app constructor(props) super(props); let images = JSON.parse(localStorage.getItem('images')) images = images? images : this.match = props.match // the images part of this state should be handled by the app component but for now i'll use localStorage console.log('constructor', images); this.state = count: 0, increment: 9, images: images if (this.state.images.length === 0) this.getImages(this.state); build_gallery_items = (images) => return images.map((src, id) => return ( <div className="item col s4" key=src> <a data-fancybox="gallery" href=src data-caption=`<a href='$src' download>Download</a>`> <img className="image-item" src=src alt="Stuff about this" /> </a> </div> ); ); getImages = (state) ...

How to hide error message in vue js after validation is true?

Image
Clash Royale CLAN TAG #URR8PPP How to hide error message in vue js after validation is true? Actually my problem I am checking when a particular value is valid through v-on:input. If, the value is invalid I get the response as "invalid data" and i display the same. But, when the value becomes valid, the "invalid data" is not hiding. How to I able to do so. My code is methods: checkLimit: function () var vm = this; data = ; if (this.no != '') data['no'] = this.no; $.ajax( url: "doc/checkNumber", method: "POST", data: data, dataType: "JSON", success: function (e) if (e.status == true) else console.log(e.msg); vm.error = e.msg; , ); , So if status is false, I am showing as <input type="text" class="form-control" v-model="orno" required="" v-on:input="checkLimit" maxlength="3"><p>error</p> . But when Status is true the erro...

Cannot exchange AccessToken from Google API inside Docker container

Image
Clash Royale CLAN TAG #URR8PPP Cannot exchange AccessToken from Google API inside Docker container I have a web app written in Go, use oauth2 (package golang.org/x/oauth2 ) to sign user in by Google (follow this tutorial https://developers.google.com/identity/sign-in/web/server-side-flow). golang.org/x/oauth2 When I test app on local, it works fine but when I deploy app and run inside a Docker container (base on golang:alpine), it has an error: Post https://accounts.google.com/o/oauth2/token: x509: certificate signed by unknown authority Post https://accounts.google.com/o/oauth2/token: x509: certificate signed by unknown authority Here is my code to exchange the accessToken: ctx = context.Background() config := &oauth2.Config ClientID: config.GoogleClientId, ClientSecret: config.GoogleClientSecret, RedirectURL: config.GoogleLoginRedirectUrl, Endpoint: google.Endpoint, Scopes: string"email", "profile", accessToken, err := config.Exchange(ctx, req.Code) i...

Moving average with changing window

Image
Clash Royale CLAN TAG #URR8PPP Moving average with changing window I would like to calculate the moving average of a variable in R with a changing window size. To be more specific: The moving average should be calculated over three years, but the data (time-series) is available in higher frequency and the window size can vary for each three-year window. Assume the following dataset: library(data.table) set.seed(1) # reproduceable data dataset <- data.table(ID=c(rep("A",2208),rep("B",2208)), x = c(rnorm(2208*2)), time=c(seq(as.Date("1988/03/15"), as.Date("2000/04/16"), "day"),seq(as.Date("1988/03/15"), as.Date("2000/04/16"), "day"))) The three-year moving average of the variable x should be calculated for both of the IDs (person A and B). Can this be done with zoo and datatable preferably? But any solution is fine. zoo datatable Please note I know how to do this with a fixed window size, the proble...

Session_start keeps reloading page

Image
Clash Royale CLAN TAG #URR8PPP Session_start keeps reloading page I have a script to connect to my db in MYSQL and I use PDO to connect. So When I use session_start it keeps reloading my page but when comment it //session_start(); it works perfectly. what do I do wrong? //session_start(); <?php ob_start(); //session_start(); //$_SESSION['already_submitted'] = false; $timezone = date_default_timezone_set("Europe/London"); $DB_host = "localhost"; $DB_user = "root"; $DB_pass = ""; $DB_name = "db_name"; // Set the credentials for the database and make a new PDO connection, // if the connection fails display the error. try $DB_con = new PDO("mysql:host=$DB_host;dbname=$DB_name",$DB_user,$DB_pass); $DB_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); catch(PDOException $e) echo $e->getMessage(); include_once 'class.crud.php'; $crud = new crud($DB_con); ?> <?php class crud private $d...

Javascript : Construct array from an array with duplicate elements by property [duplicate]

Image
Clash Royale CLAN TAG #URR8PPP Javascript : Construct array from an array with duplicate elements by property [duplicate] This question already has an answer here: I have an array of objects that I would like to convert to a new array with different structure by removing duplicate elements based on an attribute of the array. For example, this array would be filtered by date property: var arrayWithDuplicates = [ "date":"02/08/2018", "startTime": "09:00", "endTime": "12:00" , "date":"02/08/2018", "startTime": "14:00", "endTime": "17:00" ]; ==> would become : var newArray = [ { "date":"02/08/2018", "times": [ "startTime": "09:00", "endTime": "12:00" , "startTime": "14:00", "endTime": "17:00" ] ]; So, how can i do this using js(ES5) ...

Codewars Challenge - Count of positives / sum of negatives

Image
Clash Royale CLAN TAG #URR8PPP Codewars Challenge - Count of positives / sum of negatives My code works but it's not being accepted in order to pass the challenge. Any help on what I'm doing wrong would be appreciated. Challenge Description: Given an array of integers. Return an array, where the first element is the count of positives numbers and the second element is sum of negative numbers. If the input array is empty or null, return an empty array: C#/Java: new int / new int[0]; C++: std::vector<int>(); JavaScript/CoffeeScript/PHP/Haskell: ; Rust: Vec::<i32>::new(); ATTENTION! The passed array should NOT be changed. Read more here.* For example: input [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -11, -12, -13, -14, -15] return [10, -65]. My Code: function countPositivesSumNegatives(input) if (input.length < 1) return ; var newArray = [0, 0]; for (var i = 0; i < input.length; i++) if (input[i] > 0) newArray[0] += 1; else newArray[1] += input[i]; re...

Is there a method to generate a UUID with go language

Image
Clash Royale CLAN TAG #URR8PPP Is there a method to generate a UUID with go language I have code that looks like this: u := make(byte, 16) _, err := rand.Read(u) if err != nil return u[8] = (u[8] | 0x80) & 0xBF // what does this do? u[6] = (u[6] | 0x40) & 0x4F // what does this do? return hex.EncodeToString(u) It returns a string with a length of 32, but I don't think it is a valid UUID. If it is a real UUID, why is it a UUID, and what is the purpose of the code that modifies the value of u[8] and u[6] . u[8] u[6] Is there a better way of generating UUIDs? 12 Answers 12 u[8] = (u[8] | 0x80) & 0xBF // what's the purpose ? u[6] = (u[6] | 0x40) & 0x4F // what's the purpose ? These lines clamp the values of byte 6 and 8 to a specific range. rand.Read returns random bytes in the range 0-255 , which are not all valid values for a UUID. As far as I can tell, this should be done for all the values in the slice though. rand.Read 0-255 If you are on linux...

Adds new method to Array.prototype in javascript [duplicate]

Image
Clash Royale CLAN TAG #URR8PPP Adds new method to Array.prototype in javascript [duplicate] This question already has an answer here: I am new to Javascript language, recently I started looking into js prototype and got confused by some odd output in below code: Array.prototype.print = function() console.log(this) [1, 2, 3, 4].print(); Could anyone tell me why it returns Cannot read property 'print' of undefined' If I declare var array = [1, 2, 3, 4] then call print function by array.print() , it works fine, so I got confused how is that different? var array = [1, 2, 3, 4] array.print() Array.prototype.print = function() console.log(this) var array = [1, 2, 3, 4] array.print() This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. Are you running both blocks of code at the same time? It works for me when I run each block separately, which suggests a race condition. Make ...

Set equal height of specific elements using CSS only?

Image
Clash Royale CLAN TAG #URR8PPP Set equal height of specific elements using CSS only? I have 2 columns of data, in each column I have a paragraph and an image. I am wondering if there is a CSS-only method of making the paragraphs have the same height so that the images line up. I know I could loop through with JavaScript to find the tallest paragraph and set the height of the other to that, but I'm hoping to find a CSS solution if possible. Additionally, I cannot modify the DOM structure. .container display:flex; .col padding:0 15px; <div class="container"> <div class="col"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi fringilla ultrices nulla ac tempus.</p> <img src="http://placehold.it/250x100" /> </div> <div class="col"> <p>Nam mauris mi, eleifend et rutrum at, dignissim nec elit. Aliquam lacinia tincidunt leo, et pellentesque nibh ultricies ut. Etiam elit p...

How to dynamically output python dictionary to html in django?

Image
Clash Royale CLAN TAG #URR8PPP How to dynamically output python dictionary to html in django? This is the data I get from socket dynamically and I would like to show it in a table like keys and values in html with django. Received: 'power': 'ON', 'mode': 'AUTOMATIC', 'execution': 'ACTIVE', 'Xact': '235.70', 'Yact': '1468.86', 'Zact': '1.27', 'Xcom': '0.00', 'Ycom': '0.00', 'Zcom': '0.00', 'path_feedrate': '0.00', 'line': '1136849', 'Block': '1136849', 'program': '37262 S1 - .75 JET_imported_CNC.ORDn' 'comms': 'NORMAL', '': 'n2018-08-08T17:11:51.0384', 'Sspeed': '60000.00n' 'line': '1136860', 'Block': '1136860n' 'Xact': '236.17', 'Xcom': '909.70', 'path_feedrate'...

function returning data but not showing

Image
Clash Royale CLAN TAG #URR8PPP function returning data but not showing I have this component const SummaryBar = props => const MainObject = props; const localGetUserFromID = userID => getEmailFromId(userID).then(results => return results.data.Title; //Comment: This one returning friendly name ); ; return (<span>Hello localGetUserFromID(MainObject.AuthorId)</span>) but when I render it somehow the its only showing Hello and not the output I am getting from my localGetUserFromID function. Am I doing wrong? Note the AuthorId is being pass to an API and the MainObject came from the App Level, FYI when I try to debug it using dev tools the function is retuning the text I am look for. You have an async function, meaning the data isn't available as return value of your promise call, but only available when it has completed. You should rather go for a stateful component, get the data in componentwillmount, and update the local state, and render that sta...

XZing and Xamarin Forms

Image
Clash Royale CLAN TAG #URR8PPP XZing and Xamarin Forms I'm trying to use ZXing to render a simple barcode on screen in Xamarin. I've added the ZXing package to my solution and have the following code: BarcodeWriterPixelData writer = new BarcodeWriterPixelData Format = BarcodeFormat.CODE_39 , Options = new ZXing.Common.EncodingOptions Height = 80, Width = 30, Margin = 0 ; var data = writer.Write("18898798790"); IDBarCode.Source = ImageSource.FromStream(() => new MemoryStream(data.Pixels)); However my code runs without rendering anything on screen. I've been looking for some sort of sample I can use without any sucess. Have you downloaded and ran the sample on their github? try that first! – Axemasta Aug 8 at 20:39 2 Answers 2 Don't forget to initialize the ZXing library in your platform projects, else it will show up empty. You can do this by adding: // On iOS in your AppDelegate.cs in the FinishedLaunching method ZXing.Net.Mobile.F...