Posts

Eloquent get by related table count

Eloquent get by related table count I created messenger for laravel. Now I wanna list all threads in which user is participating with a count of messages in each thread. I need the count to where clause because I want to show only these threads, in which are messages. where My current query: $threads = Participant::with('thread.messages') -> where('user_id', Auth::user() -> id) -> get(); $threads = Participant::with('thread.messages') -> where('user_id', Auth::user() -> id) -> get(); Participant: public function user() { return $this -> hasOne(User::class, 'id', 'user_id'); } public function thread() { return $this -> hasOne(Thread::class, 'id', 'thread_id'); } Thread: public function participants() { return $this -> hasMany(Participant::class, 'thread_id', 'id'); } function messages() { return $this -> hasMany(Message::class, 'thread_id', 'id')...

Can't insert None into mysql int field

Can't insert None into mysql int field I need to insert an int or None into a MySql int field (which is nullable). This is my code: cur = db.cursor() contents = [None, 3] for element in contents: print(element) cur.execute('insert into test.new_test (blubb) values (%s)', element) db.commit() When I don't use None, but another int, this works. I just don't understand, why None does not work, I get the error pymysql.err.ProgrammingError: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s)' at line 1"), despite all of the solutions that I found for this saying that %s is able to handle None... Also, is there maybe a way to add the entire list at once (a new row for each entry) without using a for loop? 2 Answers 2 In mysql it should be NULL so you need to ch...

Get minimum of related model date field (django)

Get minimum of related model date field (django) I have the two following classes: class Incident(models.Model): iid = models.IntegerField(primary_key=True) person = models.ForeignKey('Person', on_delete=models.SET_NULL, null=True) class Source(models.Model): sid = models.IntegerField(primary_key=True) incident = models.ForeignKey('Incident', on_delete=models.SET_NULL, null=True) url = models.TextField(validators=[URLValidator()]) datereported = models.DateField(null=True, blank=True) I want to create a field within the Incident that will pull the minimum datereported of related sources. Is this best done in the model, or in the template? Unsure what best practice is, or how to execute in this case. Do you mean the datereported itself, or the corresponding Source object? – Willem Van Onsem Jul 1 at 17:25 ...

how to rename object data Response in React

how to rename object data Response in React So I'm trying to rename an object property for an array of objects. Here is generally what the response looks like response: [{ name: 'Manage User', id: 1, }, { name: 'Manage Region', id: 2, }, { name: 'Manage BTP', id: 3, } ], the function getResponseRename() { return this.response.map((data) => <div> <p>title: {data.key}</p> <span>key: {data.title}</span> <hr/> </div> ); } render(){ return( <div>{this.getResponseRename()}</div> ) } and I would like to change the payload "name" to "title" and "id" to "key". How could I change this and mapping the new response data after rename it?any help would be really appreciate Do you want to...

copy single row from multiple worksheets into new worksheet

Image
copy single row from multiple worksheets into new worksheet I'm not a developer, but was recently hired for a newly created position, meaning I'm trying to create reports and things from scratch that have never been done before. The IT department doesn't have time to teach me and so I'm trying to learn VBA and Access and other advanced data analysis tools, but I don't understand how to write code to the extent I need it yet. I used several things from these forums, but I've been lucky enough to mostly copy and paste to get what I need. I copied this from this forum (second answer): copy the same row from multiple sheets into one sheet in excel This is the code I copied: Sub copyrow() Dim Nrow As Long, Nsheet As Long Dim i As Long Nrow = 7 Nsheet = 6 For i = 1 To Nsheet - 1 Sheets(i).Cells(Nrow, 1).EntireRow.Copy Sheets(Nsheet).Cells(i, 1) Next i End Sub I tested it and it worked, but I didn't realize that Nsheet meant it would go to the 6th sheet and rep...

Get Javascript object array from table data

Get Javascript object array from table data I am likely new at javascript, i want to extract data from table in json object format I have a table look like this <table> <thead> <tr> <th class="active">Bolumn</th> <th class="active">Column</th> <th class="active">Dolumn</th> <th>Molumn</th> </tr> </thead> <tbody> <tr> <td class="active">Bolumn Data</td> <td class="active">Column Data</td> <td class="active">Dolumn Data</td> <td>Molumn Data</td> </tr> <tr> <td class="active">Bolumn Data 1</td> <td class="active">Column Data 1</td> <td class="active">Dolumn Data 1</td> <td>Molumn Data 1</td> </tr> <tr> <td class="active">Bolumn Data 2</td> <td class="active"...

BMI with exception handling python

BMI with exception handling python I need help with this code I am trying to apply, a short time ago I ran a bmi calculator in index and now I am trying to update that code with exception handling. So far the portions don't give me errors they just run strangely together. For example, when it prompts "Enter the user's name or '0' to quit" it doesn't actually end the process it continues on to the exception process. Can someone help me write this more efficiently. here is my code this is updated, the issue I am specifically having now is the program is not terminating when the user enters '0': def bmi_calculator(): end = False print("Welcome to the BMI Calculator!") while end == False: user = input("Enter student's name or '0' to quit: ") if user == "0": print("end of report!") end = True else: print("Lets gather your information,", user) break ...

Do CSS combinators add specificity to a CSS selector?

Image
Do CSS combinators add specificity to a CSS selector? The mdn article about CSS specificity states: Universal selector (*), combinators (+, >, ~, ' ') and negation pseudo-class (:not()) have no effect on specificity. (The selectors declared inside :not() do, however.) However my experience is that combinators do have an effect, see this example: div > p { color: red; } p { color: green; } <div> <p>First Paragraph</p> <p>Second Paragraph</p> </div> So the above quote claims, that CSS combinators have no effect on specificity. If that quote is right, how is it meant then, as my code example shows the opposite? possible duplicate of : stackoverflow.com/questions/2809024/points-in-css-specificity – Temani Afif Jul 1 at 19:11 could be except they never mention ...

Shopify order webhooks

Shopify order webhooks I looked into the different order webhooks and was wondering when they are triggered. This is what I figured out so far: orders/updated orders/create orders/create orders/paid orders/fulfilled orders/cancelled Since orders/updated is also fired whenever the other hooks are fired, it seems as if adding an update webhook would be good enough for keeping a local datastore synced to the shop data. However, I want to confirm that my understanding of those webhooks is correct, i.e. is it true that orders/updated is always fired whenever an order changes in any way. and that the other webhooks are just aimed at more specific use cases? orders/updated orders/updated 1 Answer 1 I'd say for sake of keeping the code easier to understand it would be in your best interest to handle the appropriate webhooks just to keep the code easier to understand. If all you're doing is trackin...

Which part of the code is wrong for artificial neural network in R? [on hold]

Which part of the code is wrong for artificial neural network in R? [on hold] I'm trying to predict a sales demand by using artificial neural network and 10 fold cross validation. So, I coded by using nnet package as follows: library(nnet) library(plyr) k = 10 question$id <- sample(1:k, nrow(question), replace = TRUE) list <- 1:k prediction <- data.frame() testsetCopy <- data.frame() progress.bar <- create_progress_bar("text") progress.bar$init(k) for(i in 1:k){ trainingset <- subset(question, id %in% list[-i]) testset <- subset(question, id %in% c(i)) mymodel <- nnet(Sales1~ResidentA+ResidentB+ResidentD+DOW+Weather+Amt_Rainfall+Air_Quality+Avg_Temp+Humidity, data=trainingset, size=7, decay=0.1) temp <- as.data.frame(predict(mymodel, testset[,-5])) prediction <- rbind(prediction, temp) testsetCopy <- rbind(testsetCopy, as.data.frame(testset[,3])) progress.bar$step() } However, the result showed less than 1 that it seems something wrong. So...

Java8 enum avoid multiple if else

Java8 enum avoid multiple if else In java 8 is there any option to avoid multiple if else check with enum value and to execute particular operation. I dont like to use some thing like below example ? if enum equals A PRINT A else if enum equals B PRINT B else if enum equlas C PRINT C Is it possible you're looking for switch statements? – Silvio Mayolo Jul 1 at 17:37 You do not need to check the equality if the operation is always the same – Yassin Hajaj Jul 1 at 18:06 2 Answers 2 Define enum with abstract method and provide it's implementation with values. enum MyEnum{ A{ @Override...

How does Unity distinguish between Android and iOS

Image
How does Unity distinguish between Android and iOS Let's say we have make a mobile game based on accelerometer. We're using Input.accelerometer class. using UnityEngine; public class ExampleClass : MonoBehaviour { public float speed = 10.0F; void Update() { Vector3 dir = Vector3.zero; dir.x = -Input.acceleration.y; dir.z = Input.acceleration.x; if (dir.sqrMagnitude > 1) dir.Normalize(); dir *= Time.deltaTime; transform.Translate(dir * speed); } } This code works on Andoid and on iOS. Im wondering, how does Unity know if we're running the game on Android or iOS? I have checked UnityEngine.dll file and I did not find any if-else statement between the operating systems. This may be a shot in the dark, but when your running on Windows you are using the UnityEngine.dll... however I don't believe Android or iOS use the dll... I believe they use .so's or .a's why wo...

How can convert my PC to online server?

How can convert my PC to online server? I have made an android app that can connect to MySQL database via online server url. Now, I want to connect the app to MySQL database on my PC instead of the online server. I have searched the internet, and recommendations were to use No-IP software for Dynamic DNS and forward port 3306 in router's configuration page. then, use an online host like 000webhost.com, I have done all of this, but I still don't know how to link my PC to the free domain I acquired on the internet? the input to my android app should be like String ServerURL = "http://mydomain.000webhost.com/get_data.php" ; I have the get_data.php file on my PC, how can I connect it to the online host. Update thank you alexandre for your help. I opened port 80 on my PC inbound/outbound rules, and this is my NAT page in the router config. page, can you tell how should I fill these fields? 1 Answer 1 ...

tumblrwks - receiving 401 on Post

tumblrwks - receiving 401 on Post I am able to post to Tumblr from an iOS app that I created and would like to do the same from a node.js app. My initial test case is have a nodeJS app use the same consumerKey, consumerSecret, accessToken, and accessSecret values that are successful in the iOS app. But, the node.js app, using tumblrwks, fails with a 401 error. Note that I am able to get data using the node.js app, which does not require authentication. I wonder if this is a valid test case, using the same credentials as the iOS app, or do I have to register the nodeJS app separately? The nodeJS app will be used as part of a batch process, not having user interaction, which is why I would like to use the same credentials as the iOS app. My thinking is to accept authorization from the user using the iOS app, save that authorization info to a database, which would be leveraged by the nodeJS Below is the sample code used for posting. Any help would be appreciated. const Tumblr = requir...

What is a concise way to implement nested disposers?

What is a concise way to implement nested disposers? Picture a typical resource returned by a method getResource that has a disposer, that you would use like this: getResource Promise.using( getResource(), resource => doStuffWith(resource)) .then( // "resource" is cleaned up by now ) Now imagine another method wrapResource that took the resource as an argument and returned it decorated in some way (perhaps adding its own initialize/teardown steps) - perhaps with its own disposer. You could use such a method like this: wrapResource Promise.using( getResource(), baseResource => Promise.using( wrapResource(baseResource), resource => doStuffWith(resource))) My question is whether there is a way to write the above in a more succinct way that abstracts away the wrapping of that resource, something you could use like this: Promise.using( getWrappedResource(), resource => doStuffWith(resource)) In other words - how could ...

angular 5 production release css files reference issue

angular 5 production release css files reference issue Similar issues are there but I couldn't find any working solution for this. I cant build my app with production(ng build --prod --base-href /demo/). instead of that I user only ng build(ng build --base-href /demo/) and deployed to my local IIS. Rewrite URL part is also added to web.config. My published URL is "http://localhost/demo/" and still the css reference URL is set to "http://localhost/assets/css/loader-la-ball-clip.css" I added the css references to angular-cli.json too. does anybody know a solution for this ? does this happen due to development build ? "styles": [ "../node_modules/bootstrap/dist/css/bootstrap.min.css", "../node_modules/ngx-bootstrap/datepicker/bs-datepicker.css", "./assets/css/loader-la-ball-clip.css", "./assets/css/bootstrap-datepicker.css", "styles.scss" ...

Slide to delete with similar design to iOS 10+ Notifications slide to delete in UITableViewCell

Image
Slide to delete with similar design to iOS 10+ Notifications slide to delete in UITableViewCell How can I make a tableviewcell's slide to delete look like the slide to delete for iOS notifications (fade in and don't touch edge of the screen). I will only have the delete button so I don't need multiple buttons. I would like it to delete upon a full swipe just like the notifications. Here's a photo of the wanted result with 2 buttons (I only want 1): The current code I have written only sets the editing style to delete. I have tried using UIContextualAction but I believe I can only set the style, background color, and/or image. UIContextualAction func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { return true } func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) { if editingStyle == .delete { print("delete") } } This is what it looks l...