• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 17:06
CET 22:06
KST 06:06
  • 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
[ASL20] Finals Preview: Arrival12TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9
Community News
2025 RSL Offline Finals Dates + Ticket Sales!8BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION1Crank Gathers Season 2: SC II Pro Teams6Merivale 8 Open - LAN - Stellar Fest3Chinese SC2 server to reopen; live all-star event in Hangzhou22
StarCraft 2
General
RotterdaM "Serral is the GOAT, and it's not close" Could we add "Avoid Matchup" Feature for rankgame Smart servos says it affects liberators as well Chinese SC2 server to reopen; live all-star event in Hangzhou The New Patch Killed Mech!
Tourneys
2025 RSL Offline Finals Dates + Ticket Sales! Crank Gathers Season 2: SC II Pro Teams Merivale 8 Open - LAN - Stellar Fest $5,000+ WardiTV 2025 Championship $3,500 WardiTV Korean Royale S4
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 497 Battle Haredened Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment
Brood War
General
[ASL20] Finals Preview: Arrival BSL Season 21 BSL Team A vs Koreans - Sat-Sun 16:00 CET ASL20 Pre-season Tier List ranking! ASL Runner-Up Race Stats
Tourneys
[ASL20] Grand Finals BSL21 Open Qualifiers Week & CONFIRM PARTICIPATION ASL final tickets help [ASL20] Semifinal A
Strategy
Current Meta Soma's 9 hatch build from ASL Game 2 Simple Questions, Simple Answers Roaring Currents ASL final
Other Games
General Games
Stormgate/Frost Giant Megathread Path of Exile General RTS Discussion Thread Nintendo Switch Thread Dawn of War IV
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
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 Things Aren’t Peaceful in Palestine Russo-Ukrainian War Thread YouTube Thread The Chess Thread
Fan Clubs
White-Ra Fan Club The herO Fan Club!
Media & Entertainment
Anime Discussion Thread [Manga] One Piece Korean Music Discussion Series you have seen recently... Movie Discussion!
Sports
Formula 1 Discussion 2024 - 2026 Football Thread MLB/Baseball 2023 TeamLiquid Health and Fitness Initiative For 2023 NBA General 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
The Benefits Of Limited Comm…
TrAiDoS
Sabrina was soooo lame on S…
Peanutsc
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1492 users

The Big Programming Thread - Page 699

Forum Index > General Forum
Post a Reply
Prev 1 697 698 699 700 701 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.
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
Last Edited: 2016-01-06 01:43:55
January 06 2016 01:42 GMT
#13961
On January 06 2016 10:29 aksfjh wrote:
Show nested quote +
On January 06 2016 05:19 Morfildur wrote:
On January 06 2016 03:24 Manit0u wrote:

$response = json_decode(json_encode($this->curl->response), true);


Why?! T_T


It's actually not too uncommon. It's a quick way to turn an object tree into an array. It's not exceptionally fast and it really should be in some properly named function somewhere, but the code in itself isn't bad.

Depends on your definition of "bad." It works, but I know some devs that would skewer you for that.


Holy crap. You guys just enlightened me. When I first saw it I was like "why would you encode stuff that you're about to decode instead of just leaving it as it is". Then you two answered and it dawned on me.

I have to agree that even if it works it's still really bad because it's not obvious/explicit enough to tell a person who hasn't seen it before what's actually going on.

Edit:
I guess that's one of the places where actual comments would help a lot...
Time is precious. Waste it wisely.
Cyx.
Profile Joined November 2010
Canada806 Posts
Last Edited: 2016-01-06 06:33:14
January 06 2016 06:31 GMT
#13962
On January 06 2016 10:42 Manit0u wrote:
Show nested quote +
On January 06 2016 10:29 aksfjh wrote:
On January 06 2016 05:19 Morfildur wrote:
On January 06 2016 03:24 Manit0u wrote:

$response = json_decode(json_encode($this->curl->response), true);


Why?! T_T


It's actually not too uncommon. It's a quick way to turn an object tree into an array. It's not exceptionally fast and it really should be in some properly named function somewhere, but the code in itself isn't bad.

Depends on your definition of "bad." It works, but I know some devs that would skewer you for that.


Holy crap. You guys just enlightened me. When I first saw it I was like "why would you encode stuff that you're about to decode instead of just leaving it as it is". Then you two answered and it dawned on me.

I have to agree that even if it works it's still really bad because it's not obvious/explicit enough to tell a person who hasn't seen it before what's actually going on.

Edit:
I guess that's one of the places where actual comments would help a lot...

Don't know about PHP but I've seen this done in Javascript to implement a deep copy function as well. It's incredibly straightforward, and I honestly really like it. There are a few pitfalls but it works pretty well for a large number of situations. http://stackoverflow.com/questions/122102/what-is-the-most-efficient-way-to-clone-an-object
spinesheath
Profile Blog Joined June 2009
Germany8679 Posts
January 06 2016 07:58 GMT
#13963
On January 06 2016 10:42 Manit0u wrote:
Show nested quote +
On January 06 2016 10:29 aksfjh wrote:
On January 06 2016 05:19 Morfildur wrote:
On January 06 2016 03:24 Manit0u wrote:

$response = json_decode(json_encode($this->curl->response), true);


Why?! T_T


It's actually not too uncommon. It's a quick way to turn an object tree into an array. It's not exceptionally fast and it really should be in some properly named function somewhere, but the code in itself isn't bad.

Depends on your definition of "bad." It works, but I know some devs that would skewer you for that.


Holy crap. You guys just enlightened me. When I first saw it I was like "why would you encode stuff that you're about to decode instead of just leaving it as it is". Then you two answered and it dawned on me.

I have to agree that even if it works it's still really bad because it's not obvious/explicit enough to tell a person who hasn't seen it before what's actually going on.

Edit:
I guess that's one of the places where actual comments would help a lot...

It definitely should be wrapped into a function. That way you can use it without needing to understand. When it's encapsulated properly, it doesn't look so bad (unless there is an obvious equivalent, shorter and more straightforward implementation).
If you have a good reason to disagree with the above, please tell me. Thank you.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
January 06 2016 10:28 GMT
#13964
--- Nuked ---
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
January 06 2016 12:04 GMT
#13965
On January 06 2016 19:28 Nesserev wrote:
Show nested quote +
On January 05 2016 08:55 Manit0u wrote:
Required reading before you ask any more questions:

http://www.sitepoint.com/web-site-basics-beginners/

https://developer.mozilla.org/en-US/docs/Web/Guide/Introduction_to_Web_development

http://coding-geek.com/how-databases-work/

http://code.tutsplus.com/tutorials/mvc-for-noobs--net-10488

https://developer.chrome.com/apps/app_frameworks (it's about JS but general concepts stay the same)

Edit:
Also, if you really want to learn Django properly, please get this book: http://shop.oreilly.com/product/0636920029533.do

It's amazing.


Should've mentioned that the book is available for free online:
http://chimera.labs.oreilly.com/books/1234000000754/index.html


Didn't know that. I only read paper books. I need this tactile feeling and e-books somehow don't work for me (my Kindle lies on the shelf not being used for several years). Also, by buying the book I support the author and I don't mind buying good books
Time is precious. Waste it wisely.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
January 06 2016 17:15 GMT
#13966
--- Nuked ---
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
Last Edited: 2016-01-06 19:07:50
January 06 2016 19:07 GMT
#13967
Has anyone used matlab? I'm currently translating some code from matlab and I find it very hard to understand what is what because data types aren't declared. That, and the language is new to me. I'm used to C style syntax. Any advice?
tofucake
Profile Blog Joined October 2009
Hyrule19149 Posts
January 06 2016 20:23 GMT
#13968
you have 2 options with matlab:
1. be an expert
2. flounder blindly until you get the results you want

I've never met anyone who was "ok" or "decent" at matlab
Liquipediaasante sana squash banana
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
Last Edited: 2016-01-07 02:32:52
January 07 2016 01:28 GMT
#13969
okay, I have a legit question about this TDD book I was recommended.

I am in a section where I am running this test:


def test_home_page_returns_correct_html(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'

response = home_page(request)

self.assertIn('A new list item', response.content.decode())
expected_html = render_to_string(
'home.html',
{'new_item_text': 'A new list item'}
)
print(expected_html)
print(response.content.decode())
self.assertEqual(response.content.decode(), expected_html)


I added the two print statements to see why I was getting a different error than what is in the book.

The error that he gets in the book is:


ERROR: test_home_page_returns_correct_html (lists.tests.HomePageTest) [...] 'new_item_text': request.POST['item_text'], KeyError: 'item_text'



I get a much different error, basically saying that the actual html and the decoded content don't match

and after printing them, the reason is because the actual html has

<input type='hidden' name='csrfmiddlewaretoken' value='dZrKJSMg5KzxomI3LCeFArGXoW991SgX' />

in it. because of the {% csrf_token %}

But we are using POST, which means afaik I *have* to have the csrf token in order to use my view at all. Furthermore, he specifically had me write the csrf token in.

But then that leads me to the question - why isn't he having this problem??
Or more importantly, what can I do to make my expected_html match the actual html when there is a csrf token that, if my understanding is correct, will change every time i run it? lol


edit: it looks like its because im using django 1.9 and he uses 1.8.
found a workaround. couldn't figure out how to do it myself lol
Acrofales
Profile Joined August 2010
Spain18100 Posts
January 07 2016 01:51 GMT
#13970
On January 07 2016 05:23 tofucake wrote:
you have 2 options with matlab:
1. be an expert
2. flounder blindly until you get the results you want

I've never met anyone who was "ok" or "decent" at matlab

I do the latter. I flounder similarly in R. Due to this, I do most of my data analysis in python, which requires far less floundering, and although its libraries are less powerful, it has most of the tools I need.
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
January 07 2016 07:32 GMT
#13971
On January 07 2016 04:07 darkness wrote:
Has anyone used matlab? I'm currently translating some code from matlab and I find it very hard to understand what is what because data types aren't declared. That, and the language is new to me. I'm used to C style syntax. Any advice?

Im pretty sure matlab has just one datatype, matrices.
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
WarSame
Profile Blog Joined February 2010
Canada1950 Posts
January 07 2016 07:51 GMT
#13972
Instead of addition they actually add 2 1x1 matrices. Honestly, I never could handle that language. It's always hard to switch over to another language where you don't even know how to do the most basic functions. It's not fun becoming a beginner again.
Can it be I stayed away too long? Did you miss these rhymes while I was gone?
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
January 07 2016 11:26 GMT
#13973
On January 07 2016 10:28 travis wrote:
okay, I have a legit question about this TDD book I was recommended.

I am in a section where I am running this test:


def test_home_page_returns_correct_html(self):
request = HttpRequest()
request.method = 'POST'
request.POST['item_text'] = 'A new list item'

response = home_page(request)

self.assertIn('A new list item', response.content.decode())
expected_html = render_to_string(
'home.html',
{'new_item_text': 'A new list item'}
)
print(expected_html)
print(response.content.decode())
self.assertEqual(response.content.decode(), expected_html)


I added the two print statements to see why I was getting a different error than what is in the book.

The error that he gets in the book is:

Show nested quote +

ERROR: test_home_page_returns_correct_html (lists.tests.HomePageTest) [...] 'new_item_text': request.POST['item_text'], KeyError: 'item_text'



I get a much different error, basically saying that the actual html and the decoded content don't match

and after printing them, the reason is because the actual html has
Show nested quote +

<input type='hidden' name='csrfmiddlewaretoken' value='dZrKJSMg5KzxomI3LCeFArGXoW991SgX' />

in it. because of the {% csrf_token %}

But we are using POST, which means afaik I *have* to have the csrf token in order to use my view at all. Furthermore, he specifically had me write the csrf token in.

But then that leads me to the question - why isn't he having this problem??
Or more importantly, what can I do to make my expected_html match the actual html when there is a csrf token that, if my understanding is correct, will change every time i run it? lol


edit: it looks like its because im using django 1.9 and he uses 1.8.
found a workaround. couldn't figure out how to do it myself lol


You should be using the latest LTS version of the framework (and that's 1.8 for Django).
Time is precious. Waste it wisely.
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
Last Edited: 2016-01-07 17:35:33
January 07 2016 17:11 GMT
#13974
Edit: Nevermind. Stupid me. There were some values < 0 so floor returned seemingly higher numbers (they were converted to absolute values AFTER flooring).
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
January 07 2016 20:50 GMT
#13975
I have a couple questions about the commonly seen "self" parameter in python

It seems to have the same purpose as "this" in java. except from what I read, self isn't actually a keyword, so it can be anything

so a couple questions I have - is this parameter required in all methods you write in python?
is this parameter basically just saying "from now on this is how this method can refer to itself"
and finally - why? why not just use "this" like in java?
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
January 07 2016 21:22 GMT
#13976
On January 08 2016 05:50 travis wrote:
I have a couple questions about the commonly seen "self" parameter in python

It seems to have the same purpose as "this" in java. except from what I read, self isn't actually a keyword, so it can be anything

so a couple questions I have - is this parameter required in all methods you write in python?
is this parameter basically just saying "from now on this is how this method can refer to itself"
and finally - why? why not just use "this" like in java?


http://stackoverflow.com/questions/2709821/what-is-the-purpose-of-self-in-python
Time is precious. Waste it wisely.
Deleted User 3420
Profile Blog Joined May 2003
24492 Posts
January 07 2016 21:36 GMT
#13977
I already read that. I think I get a grasp of how it works, for the most part. And why, for the most part. I just don't see the advantage of doing it this way instead of just having a keyword. It actually seems like it's making it more complicated instead of less, which is something I haven't seen in python so far.

Maybe this is a question I will need to ask myself in 6 months.
Prillan
Profile Joined August 2011
Sweden350 Posts
January 07 2016 22:01 GMT
#13978
On January 08 2016 06:36 travis wrote:
I already read that. I think I get a grasp of how it works, for the most part. And why, for the most part. I just don't see the advantage of doing it this way instead of just having a keyword. It actually seems like it's making it more complicated instead of less, which is something I haven't seen in python so far.

Maybe this is a question I will need to ask myself in 6 months.

I think that the most important point is that it makes it explicit, so that methods are just normal functions attached to a class. Consider the example by Guido van Rossum (the creator of Python).
class C:
def meth(self, arg):
self.val = arg
return self.val

An equivalent way of writing the above is
# Define an empty class:
class C:
pass

# Define a global function:
def meth(myself, arg):
myself.val = arg
return myself.val

# Poke the method into the class:
C.meth = meth

Source: http://neopythonic.blogspot.se/2008/10/why-explicit-self-has-to-stay.html


Then we have decorators, which modify functions. Because of the explicit self parameter, they work the same on methods.

# Decorator that prints all arguments passed to the wrapped function
def printer(f):
def wrapper(*args, **kwargs):
print(args, kwargs)
return f(*args, **kwargs)
return wrapper


class A:
@printer
def method(self, x):
self.y = x

@printer
def function(x, y):
return x + y


Which results in
>>> a = A()
>>> a.method(1)
(<__main__.A object at 0x769d3dd0>, 1) {}
>>> function(1, 2)
(1, 2) {}
3
TheBB's sidekick, aligulac.com | "Reality is frequently inaccurate." - Douglas Adams
Manit0u
Profile Blog Joined August 2004
Poland17399 Posts
Last Edited: 2016-01-07 22:20:04
January 07 2016 22:02 GMT
#13979
On January 08 2016 06:36 travis wrote:
I already read that. I think I get a grasp of how it works, for the most part. And why, for the most part. I just don't see the advantage of doing it this way instead of just having a keyword. It actually seems like it's making it more complicated instead of less, which is something I haven't seen in python so far.

Maybe this is a question I will need to ask myself in 6 months.


You think this is complicated? PHP has both self and this. And in JavaScript you often see stuff like that:


var self = this;


Try figuring those out

Edit:
Not for the faint of heart: http://alistapart.com/article/getoutbindingsituations
Time is precious. Waste it wisely.
emperorchampion
Profile Blog Joined December 2008
Canada9496 Posts
Last Edited: 2016-01-07 23:00:06
January 07 2016 22:15 GMT
#13980
On January 07 2016 04:07 darkness wrote:
Has anyone used matlab? I'm currently translating some code from matlab and I find it very hard to understand what is what because data types aren't declared. That, and the language is new to me. I'm used to C style syntax. Any advice?


Anything in particular you need to know about? Matlab is pretty frustrating to work with sometimes, but it's easy to get results quickly and everything is built in. It really depends on the scope of your project, but you should probably make functions for most things in separate files even if it's small. I've gotten burned pretty bad in the past with thinking "oh this is just going to be a small program, I don't need any functions..." then you end up adding and adding and adding... >_< It's really annoying that you can't have functions within the main file, but anyhow.


A couple pointers:
- matrices are (row, column), there is no 0 index
- Try to make the most use of the indexing A(:,:) (all rows and columns of A), or A(2:end, 3:end-1), ect.
- Try to replace loops with indexing, much faster and easier, loops should be the last option imo, built in functions or index are the way to go
- You can concatenate matrices B = [A(:,[1,2]), C(:,:)], (assuming similar dimensions of A and C)
- concatenate by row B = [A([1,2],:) ; C]
- "push-back": a = [a, b]
- make use of google to find out functions, there are a ton of them


On January 07 2016 16:32 solidbebe wrote:
Im pretty sure matlab has just one datatype, matrices.


Pretty much, and cells, which are the most annoying thing ever to work with.
TRUEESPORTS || your days as a respected member of team liquid are over
Prev 1 697 698 699 700 701 1032 Next
Please log in or register to reply.
Live Events Refresh
Monday Night Weeklies
17:00
Open Cup
RotterdaM984
TKL 557
IndyStarCraft 280
ZombieGrub274
SteadfastSC267
LiquipediaDiscussion
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
RotterdaM 984
TKL 557
IndyStarCraft 280
ZombieGrub274
SteadfastSC 259
MaxPax 199
UpATreeSC 118
ProTech101
StarCraft: Brood War
Britney 13926
Sea 531
Bonyth 80
NaDa 13
Dota 2
XaKoH 153
capcasts10
Counter-Strike
Foxcn193
PGG 91
Heroes of the Storm
Liquid`Hasu393
Other Games
Grubby2680
FrodaN1993
fl0m1112
Beastyqt736
shahzam460
C9.Mang0130
Organizations
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 19 non-featured ]
StarCraft 2
• kabyraGe 129
• Hupsaiya 58
• StrangeGG 45
• AfreecaTV YouTube
• sooper7s
• intothetv
• Kozan
• Migwel
• IndyKCrew
• LaughNgamezSOOP
StarCraft: Brood War
• blackmanpl 40
• Michael_bg 3
• STPLYoutube
• ZZZeroYoutube
• BSLYoutube
Dota 2
• masondota2987
League of Legends
• TFBlade876
Other Games
• imaqtpie1474
• Shiphtur172
Upcoming Events
BSL 21
3h 55m
Replay Cast
12h 55m
Streamerzone vs Shopify Rebellion
Streamerzone vs Team Vitality
Shopify Rebellion vs Team Vitality
WardiTV Invitational
14h 55m
CrankTV Team League
15h 55m
BASILISK vs TBD
Team Liquid vs Team Falcon
BSL 21
1d 3h
Replay Cast
1d 12h
BASILISK vs TBD
Team Liquid vs Team Falcon
OSC
1d 14h
CrankTV Team League
1d 15h
Replay Cast
2 days
The PondCast
2 days
[ Show More ]
CrankTV Team League
2 days
Replay Cast
3 days
WardiTV Invitational
3 days
CrankTV Team League
3 days
Replay Cast
4 days
BSL Team A[vengers]
4 days
Dewalt vs Shine
UltrA vs ZeLoT
BSL 21
4 days
Sparkling Tuna Cup
5 days
BSL Team A[vengers]
5 days
Cross vs Motive
Sziky vs HiyA
BSL 21
5 days
Wardi Open
6 days
Liquipedia Results

Completed

ASL Season 20
WardiTV TLMC #15
Eternal Conflict S1

Ongoing

BSL 21 Points
CSL 2025 AUTUMN (S18)
BSL 21 Team A
C-Race Season 1
IPSL Winter 2025-26
KCM Race Survival 2025 Season 4
SOOP Univ League 2025
CranK Gathers Season 2: SC II Pro Teams
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
BLAST Bounty Fall 2025

Upcoming

SC4ALL: Brood War
YSL S2
BSL Season 21
SLON Tour Season 2
BSL 21 Non-Korean Championship
RSL Offline Finals
WardiTV 2025
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
META Madness #9
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 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.