• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EST 16:00
CET 22:00
KST 06:00
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Winners2Intel X Team Liquid Seoul event: Showmatches and Meet the Pros10[ASL20] Finals Preview: Arrival13TL.net Map Contest #21: Voting12[ASL20] Ro4 Preview: Descent11
Community News
Starcraft, SC2, HoTS, WC3, returning to Blizzcon!20$5,000+ WardiTV 2025 Championship5[BSL21] RO32 Group Stage3Weekly Cups (Oct 26-Nov 2): Liquid, Clem, Solar win; LAN in Philly2Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win9
StarCraft 2
General
TL.net Map Contest #21: Winners Starcraft, SC2, HoTS, WC3, returning to Blizzcon! RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (Oct 20-26): MaxPax, Clem, Creator win 5.0.15 Patch Balance Hotfix (2025-10-8)
Tourneys
$5,000+ WardiTV 2025 Championship Constellation Cup - Main Event - Stellar Fest Merivale 8 Open - LAN - Stellar Fest Sea Duckling Open (Global, Bronze-Diamond) $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 498 Wheel of Misfortune|Cradle of Death Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace
Brood War
General
BGH Auto Balance -> http://bghmmr.eu/ SnOw's ASL S20 Finals Review [BSL21] RO32 Group Stage Practice Partners (Official) [ASL20] Ask the mapmakers — Drop your questions
Tourneys
[Megathread] Daily Proleagues [BSL21] RO32 Group B - Sunday 21:00 CET [BSL21] RO32 Group A - Saturday 21:00 CET BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION
Strategy
Current Meta How to stay on top of macro? PvZ map balance Soma's 9 hatch build from ASL Game 2
Other Games
General Games
Stormgate/Frost Giant Megathread Nintendo Switch Thread Dawn of War IV ZeroSpace Megathread General RTS Discussion Thread
Dota 2
Official 'what is Dota anymore' discussion
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Russo-Ukrainian War Thread Things Aren’t Peaceful in Palestine YouTube Thread Dating: How's your luck?
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Movie Discussion! [Manga] One Piece Korean Music Discussion Series you have seen recently...
Sports
2024 - 2026 Football Thread NBA General Discussion MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 Formula 1 Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Saturation point
Uldridge
DnB/metal remix FFO Mick Go…
ImbaTosS
Why we need SC3
Hildegard
Career Paths and Skills for …
TrAiDoS
Reality "theory" prov…
perfectspheres
Our Last Hope in th…
KrillinFromwales
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1234 users

The Big Programming Thread - Page 779

Forum Index > General Forum
Post a Reply
Prev 1 777 778 779 780 781 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
JWD[9]
Profile Blog Joined November 2015
364 Posts
October 11 2016 19:20 GMT
#15561
On October 12 2016 03:08 Nesserev wrote:
It seems like its original implementation is:
    Vector_ref(T* a, T* b = 0, T* c = 0, T* d = 0)
{
if (a) push_back(a);
if (b) push_back(b);
if (c) push_back(c);
if (d) push_back(d);
}

This constructor allows you to initiate the vector with between 1 and 4 pointers.
The first parameter cannot have a default parameter, otherwise there would be ambiguity with the other constructor.
The second to last parameters all have a nullptr as their default parameter, so if you don't pass any extra parameters, nothing extra is pushed at the back of the list.


I understand. Thank you Sensei Nesserev.
Sedzz
Profile Blog Joined June 2012
Australia391 Posts
Last Edited: 2016-10-12 09:13:08
October 12 2016 09:12 GMT
#15562
hey guys,

i have a bit of a simple sql insert query issue.

Here is the context;

http://imgur.com/a/QBVGf

Using MySQL & C# with Visual Studio

string insertImageQuery = 
"INSERT INTO image_table (image_name, image, status_id, user_id, tag_id)
VALUES ('" + prov_imgname_tb.Text + "', @IMG, '" + prov_imgstatus_tb.Text + "', '" + prov_uid_tb.Text + "', '" + (this.prov_imgtag_cb.SelectedIndex + 1) + "');";


I want to put focus on the bolded part. Just to get the system working I'm using that line of code as a work-around, and it could stay that way however this could cause issues down the road so I would like to find a proper fix.

The combo box is filled from a method which just grabs all the tag_description entries from the tags_table (two columns in the table, tag_id and tag_description), when inserting a new image into the database, I want the insert to contain the matching tag_id from the selected tag_description in the combo box, but I am unsure how to do this.

I looked into INSERT SELECT and came up with this statement;

INSERT INTO image_table (tag_id)
SELECT tags_table.tag_description
FROM tags_table WHERE image_table.tag_id = tags_table.tag_id


So I'm thinking I need two separate insert statements within the same query but I am unsure if that is possible?

Pretty new to SQL so sorry if this is an easier question.

Cheers!




Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
October 12 2016 09:35 GMT
#15563
On October 12 2016 18:12 Sedzz wrote:
hey guys,

i have a bit of a simple sql insert query issue.

Here is the context;

http://imgur.com/a/QBVGf

Using MySQL & C# with Visual Studio

string insertImageQuery = 
"INSERT INTO image_table (image_name, image, status_id, user_id, tag_id)
VALUES ('" + prov_imgname_tb.Text + "', @IMG, '" + prov_imgstatus_tb.Text + "', '" + prov_uid_tb.Text + "', '" + (this.prov_imgtag_cb.SelectedIndex + 1) + "');";


I want to put focus on the bolded part. Just to get the system working I'm using that line of code as a work-around, and it could stay that way however this could cause issues down the road so I would like to find a proper fix.

The combo box is filled from a method which just grabs all the tag_description entries from the tags_table (two columns in the table, tag_id and tag_description), when inserting a new image into the database, I want the insert to contain the matching tag_id from the selected tag_description in the combo box, but I am unsure how to do this.

I looked into INSERT SELECT and came up with this statement;

INSERT INTO image_table (tag_id)
SELECT tags_table.tag_description
FROM tags_table WHERE image_table.tag_id = tags_table.tag_id


So I'm thinking I need two separate insert statements within the same query but I am unsure if that is possible?

Pretty new to SQL so sorry if this is an easier question.

Cheers!


First things first, never use string concatenation to create queries, use prepared statements. In your current query, a text containing the ' character would cause the statement to fail.

As for the query, you are looking for, I don't completely understand what you actually want to do and what data you actually have available, but it might be that this is what you are looking for:

INSERT INTO image_table (image_name, image, status_id, user_id, tag_id)
SELECT @name, @image, @statusText, @userID, tag_table.tag_id
FROM tag_table
WHERE tag_table.tag_description=@tagDescription

Hhanh00
Profile Joined May 2016
34 Posts
October 12 2016 11:16 GMT
#15564
@seedzz
Always sanitize your SQL inputs and use prepared statements.

If the user inputs

a', 'b', 0, 0, 0); drop table image_table; --


your table is gone.
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
October 12 2016 17:06 GMT
#15565
LINQ is your friend.
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-10-12 18:02:58
October 12 2016 17:14 GMT
#15566
So, we had lecture today, and professor was going over binary trees.

And he said:

"There's so much you to know about trees, I could fill an entire course. And we do, it's called 420. Take 420 if you want to know about trees."


- intentional ? No one laughed but I had to stifle mine.

(cmsc 420 is the course on data structures, apparently)



...if you guys are too nerdy to see why this is funny I will be disappointed
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
October 12 2016 17:48 GMT
#15567
On October 12 2016 18:12 Sedzz wrote:
hey guys,

i have a bit of a simple sql insert query issue.

Here is the context;

http://imgur.com/a/QBVGf

Using MySQL & C# with Visual Studio

string insertImageQuery = 
"INSERT INTO image_table (image_name, image, status_id, user_id, tag_id)
VALUES ('" + prov_imgname_tb.Text + "', @IMG, '" + prov_imgstatus_tb.Text + "', '" + prov_uid_tb.Text + "', '" + (this.prov_imgtag_cb.SelectedIndex + 1) + "');";


I want to put focus on the bolded part. Just to get the system working I'm using that line of code as a work-around, and it could stay that way however this could cause issues down the road so I would like to find a proper fix.

The combo box is filled from a method which just grabs all the tag_description entries from the tags_table (two columns in the table, tag_id and tag_description), when inserting a new image into the database, I want the insert to contain the matching tag_id from the selected tag_description in the combo box, but I am unsure how to do this.

I looked into INSERT SELECT and came up with this statement;

INSERT INTO image_table (tag_id)
SELECT tags_table.tag_description
FROM tags_table WHERE image_table.tag_id = tags_table.tag_id


So I'm thinking I need two separate insert statements within the same query but I am unsure if that is possible?

Pretty new to SQL so sorry if this is an easier question.

Cheers!





If you've already pulled the list of id's and descriptions to fill the combo box, why not just use that list to build the SQL statement? You can use the selected index property of the combo box to know which item in the list is selected.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
October 12 2016 19:04 GMT
#15568
--- Nuked ---
mantequilla
Profile Blog Joined June 2012
Turkey779 Posts
October 12 2016 20:43 GMT
#15569
when I open up twitch chat www.twitch.tv and open network tab of my developer console, I see no requests going and no response containing new chat messages. How does it work? when chat is very fast how does it refresh so fast without making get requests 100 times a second?
Age of Mythology forever!
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
Last Edited: 2016-10-12 21:42:14
October 12 2016 21:34 GMT
#15570
On October 13 2016 05:43 mantequilla wrote:
when I open up twitch chat www.twitch.tv and open network tab of my developer console, I see no requests going and no response containing new chat messages. How does it work? when chat is very fast how does it refresh so fast without making get requests 100 times a second?


That's what WebSockets are for. You make only a single request to the application and you have an open connection over which you can send data back and forth in various formats until the connection is closed.

You can obviously use stuff like socket.io for that, but that's yet another JS framework...

Example (really old one): https://www.sanwebe.com/2013/05/chat-using-websocket-php-socket
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
October 12 2016 22:28 GMT
#15571
On October 13 2016 04:04 Nesserev wrote:
Show nested quote +
On October 13 2016 02:14 travis wrote:
So, we had lecture today, and professor was going over binary trees.

And he said:

"There's so much you to know about trees, I could fill an entire course. And we do, it's called 420. Take 420 if you want to know about trees."


- intentional ? No one laughed but I had to stifle mine.

(cmsc 420 is the course on data structures, apparently)



...if you guys are too nerdy to see why this is funny I will be disappointed

Sorry, I almost didn't recognize that internet meme without all the BLAZE IT references, Snoop Dogg images and MLG airhorns.


programmers r 2 serious 4 me
Sedzz
Profile Blog Joined June 2012
Australia391 Posts
October 13 2016 02:25 GMT
#15572
On October 12 2016 18:35 Morfildur wrote:

First things first, never use string concatenation to create queries, use prepared statements. In your current query, a text containing the ' character would cause the statement to fail.

As for the query, you are looking for, I don't completely understand what you actually want to do and what data you actually have available, but it might be that this is what you are looking for:

INSERT INTO image_table (image_name, image, status_id, user_id, tag_id)
SELECT @name, @image, @statusText, @userID, tag_table.tag_id
FROM tag_table
WHERE tag_table.tag_description=@tagDescription



Cheers. This is a university level unit I'm taking and I think it's either intentionally vague or not very well run because so far there has been no mention of prepared statements nor sanitisation (in-fact, our lecturer encourages the way I've done it) but I think I'm going to incorporate the prepared statements into the code as it's good practice.


Blisse
Profile Blog Joined July 2010
Canada3710 Posts
Last Edited: 2016-10-13 03:26:18
October 13 2016 03:25 GMT
#15573
I giggled at 420. Heh

(Deleted)
There is no one like you in the universe.
meatpudding
Profile Joined March 2011
Australia520 Posts
October 13 2016 03:33 GMT
#15574
I giggled at r/trees.
Be excellent to each other.
Manit0u
Profile Blog Joined August 2004
Poland17420 Posts
October 13 2016 05:16 GMT
#15575
On October 13 2016 11:25 Sedzz wrote:
Show nested quote +
On October 12 2016 18:35 Morfildur wrote:

First things first, never use string concatenation to create queries, use prepared statements. In your current query, a text containing the ' character would cause the statement to fail.

As for the query, you are looking for, I don't completely understand what you actually want to do and what data you actually have available, but it might be that this is what you are looking for:

INSERT INTO image_table (image_name, image, status_id, user_id, tag_id)
SELECT @name, @image, @statusText, @userID, tag_table.tag_id
FROM tag_table
WHERE tag_table.tag_description=@tagDescription



Cheers. This is a university level unit I'm taking and I think it's either intentionally vague or not very well run because so far there has been no mention of prepared statements nor sanitisation (in-fact, our lecturer encourages the way I've done it) but I think I'm going to incorporate the prepared statements into the code as it's good practice.




And please use LINQ for that. It's way clearer what's going on in the code this way.
Time is precious. Waste it wisely.
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
October 14 2016 01:09 GMT
#15576
This is a more math and less programming, but I figured it might be relevant since I'm trying to solve this problem: https://projecteuler.net/problem=213

Suppose I throw two dice. What are the chances that at least one die will be a 1? I know that the calculation would be the chances of rolling a 1 on either die minus the changes of rolling a 1 on both dice: (1/6) + (1/6) - ((1/6) * (1/6))

Suppose I throw three dice (or more). What are the chances that at least one die will be a 1? The logic is the same, add up the probabilities of rolling a 1 on either die and subtract all the potential overlaps, but I'm not sure how to calculate that. Any help?
slmw
Profile Blog Joined October 2010
Finland233 Posts
Last Edited: 2016-10-14 01:25:52
October 14 2016 01:19 GMT
#15577
Probability of [X] is the same as 1 - [NOT X]. In this case [NOT X] is very easy to calculate, so do that instead of figuring all the ways [X] can happen.

If you do want to do it the hard way you need to figure out and add together all the different ways to get to the expected outcome. In the case of 2 dies:

  • First dice is 1, second dice is not 1. 1/6 * 5/6
  • First dice is not 1, second dice is 1. 5/6 * 1/6
  • First dice is 1, second dice is 1. 1/6*1/6


Result: 1/6 * 5/6 + 5/6 * 1/6 + 1/6 * 1/6 = 11/36
enigmaticcam
Profile Blog Joined October 2010
United States280 Posts
Last Edited: 2016-10-14 01:25:58
October 14 2016 01:25 GMT
#15578
On October 14 2016 10:19 slmw wrote:
Probability of [X] is the same as 1 - [NOT X]. In this case [NOT X] is very easy to calculate, so do that instead of figuring all the ways [X] can happen.

Thank you! I knew it wasn't as complicated as I was imagining.
Djagulingu
Profile Blog Joined December 2010
Germany3605 Posts
October 14 2016 13:36 GMT
#15579
On October 14 2016 10:25 enigmaticcam wrote:
Show nested quote +
On October 14 2016 10:19 slmw wrote:
Probability of [X] is the same as 1 - [NOT X]. In this case [NOT X] is very easy to calculate, so do that instead of figuring all the ways [X] can happen.

Thank you! I knew it wasn't as complicated as I was imagining.

What slmw said will help you a lot if you increase the number of dice from 2 to 200.
"windows bash is a steaming heap of shit" tofucake
JWD[9]
Profile Blog Joined November 2015
364 Posts
October 14 2016 20:10 GMT
#15580
Trying to make may way through:
Programming: Principles and Practice Using C++
Second Edition
Bjarne Stroustrup


So at the end of chapter 19, there are talks about implementing a version of the standard library vector. One of the suggested versions has a base class, that handles the resources.


template<typename T, typename A = allocator<T>>
class myvector : private vector_base<T,A>{
public:
using vector_base<T,A>::vector_base;
};


template<typename T, typename A>
struct vector_base{
A alloc; //allocator
long unsigned int sz; //number of elements
T* elem; //start of allocation
long unsigned int space; //amount of allocated space

vector_base(const A& a, long unsigned int n)
:alloc{a}, sz{n}, elem{alloc.allocate(n)}, space{n} {}

~vector_base(){
for(long unsigned int i=0; i < sz; ++i)
alloc.destroy(&elem[i]);
alloc.deallocate(elem,space);
}
};


So my question is mostly about the destructor. The for loop, is it nessecary? It is not in the destructor in the book, but in the reserve function. There it is called after copying the original elements into a new vector:


template<typename T, typename A>
void myvector<T,A>::reserve(long unsigned int newalloc)
{
if( newalloc <= this->space )return; //never decrease allocation
vector_base<T,A>b(this->alloc,newalloc); //allocate new space
uninitialized_copy(this->elem,&this->elem[this->sz],b.elem); //copy old elements
/*for(long unsigned int i=0; i < this->sz; ++i) //
this->alloc.destroy(&this->elem[i]); // */
b.sz = this->sz; //about to swap, preserve number of elements(constructor of b has set b's size to b's capacity)
this->space = b.space; //about to swap, this space still is < newalloc
swap<vector_base<T,A>>(*this,b);
}


I am totally in over my head here, it "felt" right. Now why is it actually wrong, right, good or bad?
Prev 1 777 778 779 780 781 1032 Next
Please log in or register to reply.
Live Events Refresh
LAN Event
18:00
Day 3: Ursa 2v2, FFA
SteadfastSC393
IndyStarCraft 177
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
mouzHeroMarine 499
SteadfastSC 393
White-Ra 211
IndyStarCraft 177
UpATreeSC 142
ProTech125
Railgan 67
ROOTCatZ 43
StarCraft: Brood War
Shuttle 460
Bonyth 69
ivOry 14
Dota 2
Dendi985
Counter-Strike
pashabiceps1182
Foxcn163
Super Smash Bros
Liquid`Ken9
Heroes of the Storm
Liquid`Hasu516
Other Games
Beastyqt728
fl0m665
Mlord452
FrodaN427
shahzam403
KnowMe185
Pyrionflax168
C9.Mang0125
ArmadaUGS115
ToD77
Mew2King74
Trikslyr53
OptimusSC21
Organizations
Counter-Strike
PGL192
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 20 non-featured ]
StarCraft 2
• Adnapsc2 11
• Reevou 9
• Dystopia_ 0
• Kozan
• sooper7s
• AfreecaTV YouTube
• Migwel
• LaughNgamezSOOP
• intothetv
• IndyKCrew
StarCraft: Brood War
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• C_a_k_e 3055
• Ler92
League of Legends
• TFBlade886
Other Games
• imaqtpie1303
• WagamamaTV341
• Scarra290
• Shiphtur221
Upcoming Events
OSC
1h
Replay Cast
2h
OSC
15h
LAN Event
18h
Korean StarCraft League
1d 6h
CranKy Ducklings
1d 13h
LAN Event
1d 18h
IPSL
1d 21h
dxtr13 vs OldBoy
Napoleon vs Doodle
BSL 21
1d 23h
Gosudark vs Kyrie
Gypsy vs Sterling
UltrA vs Radley
Dandy vs Ptak
Replay Cast
2 days
[ Show More ]
Sparkling Tuna Cup
2 days
WardiTV Korean Royale
2 days
LAN Event
2 days
IPSL
2 days
JDConan vs WIZARD
WolFix vs Cross
BSL 21
2 days
spx vs rasowy
HBO vs KameZerg
Cross vs Razz
dxtr13 vs ZZZero
Replay Cast
3 days
Wardi Open
3 days
WardiTV Korean Royale
4 days
Replay Cast
5 days
Kung Fu Cup
5 days
Classic vs Solar
herO vs Cure
Reynor vs GuMiho
ByuN vs ShoWTimE
Tenacious Turtle Tussle
6 days
The PondCast
6 days
RSL Revival
6 days
Solar vs Zoun
MaxPax vs Bunny
Kung Fu Cup
6 days
WardiTV Korean Royale
6 days
Liquipedia Results

Completed

BSL 21 Points
SC4ALL: StarCraft II
Eternal Conflict S1

Ongoing

C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
YSL S2
IEM Chengdu 2025
PGL Masters Bucharest 2025
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025

Upcoming

BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
Acropolis #4
HSC XXVIII
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
META Madness #9
BLAST Bounty Winter 2026: Closed Qualifier
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.