Either check if that particular entry (user+group) exists, or get the list of users in a group and check membership against that list.
You can also do it with joins, but it isn't nearly as readable so don't do that unless you have to for performance reasons. (And if you are having performance reasons, you probably should be looking things over anyway...)
Yeah for performance reasons I would have wrote it:
SELECT U.id, U.username
FROM Users U
LEFT JOIN UserGroups UG ON UG.user_id = U.id AND UG.group_id = 4
WHERE UG.user_id is null
But you are right it's not that obvious to what is happening unless you do a lot of SQL.
Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.
The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.
Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.
The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.
And even when you do structured or OOP, the way you write it will probably be different. After doing a bit of functional stuff I find myself using things like map, and when available, list comprehensions and whatnot, far more often and doing recursive stuff comes more naturally every day. I'm also incredibly irritated when I can't find a way to minimize mutations and side effects to only being in a few small areas of code rather than just all over the place, changing shit all willy nilly.
Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.
The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.
Thanks for the link. Actually, the open courseware was my first real look at functional programming and a big part of the reason I signed up for the Coursera course I'm in now which features FP.
@Jimmy King: I knew some bit of Python had functional roots, but there seems to be more overlap that I thought with ML (and presumably others.) It doesn't come naturally to me yet, but I'm starting to understand what you mean.
I think that the internet has been for years on the path to creating what is essentially an electronic Necronomicon: A collection of blasphemous unrealities so perverse that to even glimpse at its contents, if but for a moment, is to irrevocably forfeit a portion of your sanity.
Xbox - PearlBlueS0ul, Steam
If you ever need to talk to someone, feel free to message me. Yes, that includes you.
Yeah, and then there's functools and itertools for python which adds even more functional stuff and I just recently say fn.py, which adds in some really cool stuff like lazy evaluated streams.
Took my first stab at functional programming this weekend. It feels so weird wrapping your head around things like using 1 + myself instead of i++ in a loop for a counter. It's not bad, it just feels like trying to learn a physical skill that your body has absolutely no muscle memory for.
The most time consuming part was trying to decipher the SML error messages. They were amazingly unhelpful.
Thanks for the link. Actually, the open courseware was my first real look at functional programming and a big part of the reason I signed up for the Coursera course I'm in now which features FP.
@Jimmy King: I knew some bit of Python had functional roots, but there seems to be more overlap that I thought with ML (and presumably others.) It doesn't come naturally to me yet, but I'm starting to understand what you mean.
FP is definitely one of the things that every programmer should understand. You'll write better code, no matter what you do, if you understanding FP principles.
(Coincidentally, it's good to know that you're enjoying Dan's class on coursera. That course is one of the reasons why I'm doing programming language research today. I recommend everyone check it out!)
@TwitchTV, @Youtube: master-level zerg ladder/customs, commentary, and random miscellany.
Stupid corporate anti-virus firewall blocking my incoming broadcast packets
Spent an entire day asking whyyyyyy
Double checking that I was binding to the right interface
Testing other packet types - unicast, multicast
And it was the firewall blocking incoming broadcast packets to the socket
Turns out, though, that if you use the same socket to send any data out, it allows broadcast packets to be received on that socket for about 3-5s
So now, I am adding a "Firewall Workaround" option, where all it does it pick a random port, and periodically sends out a dud packet
Just had to vent.
The joys of getting around network firewalls. I had something similar in one of my projects where sometimes multicast traffic wouldn't get through... for a system where nodes discovered each other through multicast! Fun!
was the book we used and I found it pretty helpful.
Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.
So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?
Sites without a media="print" stylesheet. That's a paddlin'.
4.5 pages of junk before reaching the actual content I want printed. I end up just doing a cut'n'paste and then printing it.
Have a look at Readability if you're using firefox. I have a friend who loves it. I've seen it and it is pretty damn amazing at taking a website full of shit and making it readable.
So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?
The reason you're seeing a bunch of different ways to do this, is that a combo box is a client side object. ASP.NET MVC isn't WebForms, it's not going to wire it all up for you. Every application is going to have it's own way it wants to display HTML 'select' elements and how it wants them populated.
The easiest, most straightforward, way is to simply stick some Razor in your view that iterates the list and outputs the appropriate 'option' tags inside of a select. You'll then want to wire up that client side object to either post back, or send an AJAX request, when the value changes.
I believe there are MVC helper methods for this, but there isn't going to be "one standard". Much like in RoR or Django, a "combo box" lives outside the boundary of what the framework is meant to handle. They are client side objects, that happen to need data from the server.
Sites without a media="print" stylesheet. That's a paddlin'.
4.5 pages of junk before reaching the actual content I want printed. I end up just doing a cut'n'paste and then printing it.
Have a look at Readability if you're using firefox. I have a friend who loves it. I've seen it and it is pretty damn amazing at taking a website full of shit and making it readable.
Safari has an excellent reader mode. I wonder why media sites weren't screaming louder about how awful and piratey it was.
So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.
So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.
That seems like something one should have anticipated.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
GnomeTankWhat the what?Portland, OregonRegistered Userregular
Man, WPF...let me profess my love for thee.
I've been working like a madman on my game engine lately, and part of that is the editing environment. Knowing WPF as well as I do, it's mind blowing the level of Awesome (tm) I can get out of this UI, using just the built in WPF controls (aside from AvalonEdit and AvalonDock, which are free open source) and good templating.
WPF really should be held up as one of Microsoft's greatest successes...because once you understand it, it's mind-fucking-blowingly great to work with. The fact that it so nicely dovetails with MVVM is another nice touch.
So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.
That seems like something one should have anticipated.
It sure does. This entire platform is terrible. Did you know that if you happen to request a page on our site that isn't in our akamai cache it takes between 10,000 and 11,000 database queries to build the page for most pages? I don't know why this thing even works.
I once discovered (in code I was partially responsible for) a problem that would occasionally happen where the ASP.NET process wouldn't release a lock on a temp file, resulting in sticking around.
This seems all well and good, right? Just run a process to clean it up every so often!
But then something occurred to me and I realized that panic was the appropriate response. You see, the temp files were for our online file repository. They were used to stage downloads in a load balanced scenario. And the temp file names weren't unique across customers...
0
Options
admanbunionize your workplaceSeattle, WARegistered Userregular
Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.
So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?
GnomeTank's answer is accurate. My preferred method is to create a SelectList with the (list, id, value) constructor and send that out to the view, then the view code is really simple.
Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.
So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?
GnomeTank's answer is accurate. My preferred method is to create a SelectList with the (list, id, value) constructor and send that out to the view, then the view code is really simple.
Yeah, this is the method I eventually figured out on my own.
I'm just kinda teaching myself as I go, so I'm trying to build a site that allows you to create and run a tournament, a-la http://binarybeast.com/ or http://challonge.com/ , but just for one sport, and with special rules just for that sport.
So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.
That seems like something one should have anticipated.
It sure does. This entire platform is terrible. Did you know that if you happen to request a page on our site that isn't in our akamai cache it takes between 10,000 and 11,000 database queries to build the page for most pages? I don't know why this thing even works.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
0
Options
GnomeTankWhat the what?Portland, OregonRegistered Userregular
Yeah, that was my response to. 11,000 database queries? Jesus fucking christ. Did you guys use an ORM and just never optimize it or something?
Yeah, that was my response to. 11,000 database queries? Jesus fucking christ. Did you guys use an ORM and just never optimize it or something?
Yes. As far as I can tell. Most of it was written before I ever worked here. I worked here for 1 1/2 years and never saw the code for this system until a few weeks ago. I was told about the ridiculous number of queries by the guy who managed to get it down from over 11,000 to between 10,000 and 11,000 shortly before they laid everyone off.
There's no taking advantage of django's queryset caching, select_related(), etc. Just fuckloads of pulling a queryset inside of a method, converting it to a list (or return None if the queryset was empty!), and then iterate over it, doing more queries where the queryset just dies inside of methods.
Yeah, that was my response to. 11,000 database queries? Jesus fucking christ. Did you guys use an ORM and just never optimize it or something?
Yes. As far as I can tell. Most of it was written before I ever worked here. I worked here for 1 1/2 years and never saw the code for this system until a few weeks ago. I was told about the ridiculous number of queries by the guy who managed to get it down from over 11,000 to between 10,000 and 11,000 shortly before they laid everyone off.
There's no taking advantage of django's queryset caching, select_related(), etc. Just fuckloads of pulling a queryset inside of a method, converting it to a list (or return None if the queryset was empty!), and then iterate over it, doing more queries where the queryset just dies inside of methods.
11,000 individual queries? What the fucking fuck could you possibly query from 11,000 different locations? Jesus Christ.
At least get that down to a sane number, oh you need things from catalog A? Okay, Catalog B, okay.
Sounds like someone's trying to amalgamate different catalogs into one, and at that case, you're better off batching and using a new database as a central layer, you know, for performance. Who cares if it's a day off.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
What, you guys haven't ever seen code in the wild that is "select a list of ids" and then deserializes those into objects one by one, each with five queries to get related data? :rotate:
I suspect it's because of a shitload of foreign keys. Django provides a select_related() method on the ORM that you can use to tell it to join the foreign keys you're actually going to use, but that's never used here, so every attribute access where the object's attribute is a foreign key results in another query. When there are models which are subclasses of other models, it takes one query per model in the chain of subclassing as well.
GnomeTankWhat the what?Portland, OregonRegistered Userregular
edited January 2013
Rails does the same with using the :include clause. Helps you tune the final queries for how your object graph is loaded. It defaults to lazy loaded, query per object, if you don't tell it otherwise. Simple, but pretty bad for a production site. Eager loading using joins is almost always better for query performance.
What, you guys haven't ever seen code in the wild that is "select a list of ids" and then deserializes those into objects one by one, each with five queries to get related data? :rotate:
A very real thing, and fuck that shit hard.
I wish I could say I was innocent of this, but sadly I'm not. Granted it was 200 records at the greatest, but the performance hit on 200 records was intense. I can't imagine 11,000. That's in-fucking-sane.
I realized my mistake after 5 minutes on the test bed.
not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
0
Options
GnomeTankWhat the what?Portland, OregonRegistered Userregular
Lucky for me, all my current ORM work is using nHibernate against SQLite in a desktop app. I couldn't care less what' it's load graph looks like, because it still takes milliseconds!
Yep, I saw those when reading over ActiveRecord documentation.
I suspect the original developers of most of this stuff really had no idea what the ORM was doing behind the scenes and had never really read any of the documentation. I tried to give them the benefit of the doubt and was going to suggest that maybe much of the code was written before select_related() existed since I know early on the Django ORM wasn't all that great. It's existed at least since 1.0 though and I doubt they were building on an earlier version of Django.
GnomeTankWhat the what?Portland, OregonRegistered Userregular
edited January 2013
One of the first things I tell new Rails devs to do is turn on ActiveRecord debug logging, so you can see the queries it creates. I've spotted specific performance problems coming a mile away, just from looking at the SQL generated for a particular object load.
Stupid corporate anti-virus firewall blocking my incoming broadcast packets
Spent an entire day asking whyyyyyy
Double checking that I was binding to the right interface
Testing other packet types - unicast, multicast
And it was the firewall blocking incoming broadcast packets to the socket
Turns out, though, that if you use the same socket to send any data out, it allows broadcast packets to be received on that socket for about 3-5s
So now, I am adding a "Firewall Workaround" option, where all it does it pick a random port, and periodically sends out a dud packet
Just had to vent.
The joys of getting around network firewalls. I had something similar in one of my projects where sometimes multicast traffic wouldn't get through... for a system where nodes discovered each other through multicast! Fun!
I ran into a problem a while back where all of a sudden all my web requests sent programatically were getting a 403. Seems IT had the brilliant idea to block all versions of JAVA but ONE and not tell anyone. I spent HOURS debugging my shit. And guess what? ITS HAPPENING AGAIN!!! What version of JAVA is it this time? No one seems to know. Fantastic!
Posts
Yeah for performance reasons I would have wrote it:
But you are right it's not that obvious to what is happening unless you do a lot of SQL.
Nintendo ID: Incindium
PSN: IncindiumX
@an_alt check out MIT's open courseware http://ocw.mit.edu/courses/electrical-engineering-and-computer-science/6-00sc-introduction-to-computer-science-and-programming-spring-2011/index.htm their intro course is entirely functional programming. Once you grok it you may never want to program structured or OOP again.
Joe's Stream.
Also, interview #2 with the RoR shop is being scheduled. Yay!
Thanks for the link. Actually, the open courseware was my first real look at functional programming and a big part of the reason I signed up for the Coursera course I'm in now which features FP.
@Jimmy King: I knew some bit of Python had functional roots, but there seems to be more overlap that I thought with ML (and presumably others.) It doesn't come naturally to me yet, but I'm starting to understand what you mean.
If you ever need to talk to someone, feel free to message me. Yes, that includes you.
https://github.com/kachayev/fn.py
Stupid corporate anti-virus firewall blocking my incoming broadcast packets
Spent an entire day asking whyyyyyy
Double checking that I was binding to the right interface
Testing other packet types - unicast, multicast
And it was the firewall blocking incoming broadcast packets to the socket
Turns out, though, that if you use the same socket to send any data out, it allows broadcast packets to be received on that socket for about 3-5s
So now, I am adding a "Firewall Workaround" option, where all it does it pick a random port, and periodically sends out a dud packet
Just had to vent.
FP is definitely one of the things that every programmer should understand. You'll write better code, no matter what you do, if you understanding FP principles.
(Coincidentally, it's good to know that you're enjoying Dan's class on coursera. That course is one of the reasons why I'm doing programming language research today. I recommend everyone check it out!)
The joys of getting around network firewalls. I had something similar in one of my projects where sometimes multicast traffic wouldn't get through... for a system where nodes discovered each other through multicast! Fun!
How advanced is it? I had a compiler module last year that wasn't too bad.
https://www.google.co.uk/search?q=compilers+principles+techniques+and+tools&rlz=1C1CHKZ_en-gbGB510GB510&aq=0&oq=compilers+principles+tech&aqs=chrome.0.0j57j0l2.4936&sourceid=chrome&ie=UTF-8#q=compilers+principles+techniques+and+tools&hl=en&tbo=u&rlz=1C1CHKZ_en-gbGB510GB510&source=univ&tbm=shop&sa=X&ei=HYj-UKOFNqqO0AW2mIGADQ&ved=0CDwQrQQ&bav=on.2,or.r_gc.r_pw.r_qf.&bvm=bv.41248874,d.d2k&fp=b08baca294896502&biw=1920&bih=955
was the book we used and I found it pretty helpful.
Also, can somebody who knows ASP.NET MVC explain something to me? I want to populate a DropDownList using a database table, and I can't work out how to do it. All of the examples I find online use different methods to each other, and none of them seem very intuitive to me.
So, lets say I have a table full of players, each of whom have a name, and a gender, and I have teams, which are either one or two players. If I'm trying to put a dropdown list in the view for creating a new team using the list of existing players, how do I do it?
4.5 pages of junk before reaching the actual content I want printed. I end up just doing a cut'n'paste and then printing it.
The reason you're seeing a bunch of different ways to do this, is that a combo box is a client side object. ASP.NET MVC isn't WebForms, it's not going to wire it all up for you. Every application is going to have it's own way it wants to display HTML 'select' elements and how it wants them populated.
The easiest, most straightforward, way is to simply stick some Razor in your view that iterates the list and outputs the appropriate 'option' tags inside of a select. You'll then want to wire up that client side object to either post back, or send an AJAX request, when the value changes.
I believe there are MVC helper methods for this, but there isn't going to be "one standard". Much like in RoR or Django, a "combo box" lives outside the boundary of what the framework is meant to handle. They are client side objects, that happen to need data from the server.
Safari has an excellent reader mode. I wonder why media sites weren't screaming louder about how awful and piratey it was.
So we've got this process that involves downloading an image from another server on our network and importing it into our main CMS. It's looking like that process may not actually check the response from the remote httpd and just assumes it's good. We may have 16,000 (out of 28,000) "jpg" files which are actually html for a 404 error for just one of our websites.
That seems like something one should have anticipated.
I've been working like a madman on my game engine lately, and part of that is the editing environment. Knowing WPF as well as I do, it's mind blowing the level of Awesome (tm) I can get out of this UI, using just the built in WPF controls (aside from AvalonEdit and AvalonDock, which are free open source) and good templating.
WPF really should be held up as one of Microsoft's greatest successes...because once you understand it, it's mind-fucking-blowingly great to work with. The fact that it so nicely dovetails with MVVM is another nice touch.
This seems all well and good, right? Just run a process to clean it up every so often!
But then something occurred to me and I realized that panic was the appropriate response. You see, the temp files were for our online file repository. They were used to stage downloads in a load balanced scenario. And the temp file names weren't unique across customers...
GnomeTank's answer is accurate. My preferred method is to create a SelectList with the (list, id, value) constructor and send that out to the view, then the view code is really simple.
Yeah, this is the method I eventually figured out on my own.
I'm just kinda teaching myself as I go, so I'm trying to build a site that allows you to create and run a tournament, a-la http://binarybeast.com/ or http://challonge.com/ , but just for one sport, and with special rules just for that sport.
There's no taking advantage of django's queryset caching, select_related(), etc. Just fuckloads of pulling a queryset inside of a method, converting it to a list (or return None if the queryset was empty!), and then iterate over it, doing more queries where the queryset just dies inside of methods.
Sometimes it doesn't.
At least get that down to a sane number, oh you need things from catalog A? Okay, Catalog B, okay.
Sounds like someone's trying to amalgamate different catalogs into one, and at that case, you're better off batching and using a new database as a central layer, you know, for performance. Who cares if it's a day off.
A very real thing, and fuck that shit hard.
I wish I could say I was innocent of this, but sadly I'm not. Granted it was 200 records at the greatest, but the performance hit on 200 records was intense. I can't imagine 11,000. That's in-fucking-sane.
I realized my mistake after 5 minutes on the test bed.
I suspect the original developers of most of this stuff really had no idea what the ORM was doing behind the scenes and had never really read any of the documentation. I tried to give them the benefit of the doubt and was going to suggest that maybe much of the code was written before select_related() existed since I know early on the Django ORM wasn't all that great. It's existed at least since 1.0 though and I doubt they were building on an earlier version of Django.
Suddenly ST2 can't run Ruby with Cmd-B. But only if I start ST2 from the terminal. If I start it from Spotlight or whatever, it works.
A while back I had the exact opposite thing happen - I had to run it from the terminal or it wouldn't build ruby stuff.
Probably some weird environment shit going on again.
I ran into a problem a while back where all of a sudden all my web requests sent programatically were getting a 403. Seems IT had the brilliant idea to block all versions of JAVA but ONE and not tell anyone. I spent HOURS debugging my shit. And guess what? ITS HAPPENING AGAIN!!! What version of JAVA is it this time? No one seems to know. Fantastic!