Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
tef
May 30, 2004

-> some l-system crap ->

Orzo posted:

Yes, I read the opening post I just thought someone might have a more precise suggestion for someone who knows C# inside and out. I guess I'm looking for an approach that assumes the reader knows how programming works but at the same time starts from step 1 on the C++ language.

Tbh beyond the basics knowing c# will be more of a hindrance when your preconceptions work.


Try accelerated c++

Adbot
ADBOT LOVES YOU

The King of Swag
Nov 10, 2005

To escape the closure,
is to become the God of Swag.
I have another Win32 keyboard input question; for those that remember, I was having some trouble with LAlt and RAlt being correctly detected and I was quickly helped with that. Now I've rewritten my left and right key detection routine so that left and right keys are properly handled when pressed/released while the other key is down (i.e. holding right control down and then tapping left control will correctly register keydown and keyup events for left control). This isn't hard at all, but the snag I've run into is with shift. If both shift keys are held down and then one is released, only one keyup event is sent as expected, but GetKeyState and GetAsyncKeyState will return that neither shift key is held down, so another keyup event is never sent and during the first keyup event (when the first shift key is released), you cant tell what shift it was, because both return as up, and the right shift isn't an extended key like control and alt. At this point, I'm thinking this bug makes it impossible to handle both shift keys down together like the other left and right-hand keys.

Has anyone dealt with this; am I truly out of luck here? I spent a lot of time tracking the error to the Win32 API, and even more time trying to find a possible solution, but I just can't see a way without some way to properly poll what key is down or what shift was just released.

Ixian
Oct 9, 2001

Many machines on Ix....new machines
Pillbug
Javascript question:

I am trying to replace part of a url string so I can output it as a variable to be used by a simple redirect script for mobile users. Example:

url is https://www.mysite.com/foo.html?id=randomstring&anotherrandomstring

I need it changed to: https://www.mysite.com/mobile.html?id=randomstring&anotherrandomstring

Everything else in the url stays the same, including the id's on the end - those being dependant on the logged in user reading the page. Basically I want to swap in the word "mobile", then do a little js routine that grabs that new url and sends iphone, android, etc users on their merry way. Any guidance?

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

code:
var a = document.createElement("a");
a.href = window.location; // or whatever url
var mobiled = a.protocol + '//' + a.hostname + 
  a.pathname.replace(/\/[^\/]+\.html/i, '/mobile.html') + a.search + a.hash;

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

That'll work, but you're probably better off doing 301/302 server redirects for SEO reasons. (e.g. with apache url rewrites or the ASP/php/etc. equivalent)

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

Scaramouche posted:

That'll work, but you're probably better off doing 301/302 server redirects for SEO reasons. (e.g. with apache url rewrites or the ASP/php/etc. equivalent)

Agreed, but he asked for JavaScript. :-)

Baldbeard
Mar 26, 2011

I've been working on learning Action script and I've been running into a few roadblocks. I'm hoping some of you guys can point me in the right direction for a book or some specific tutorials.

I'm trying to make my code OO. So far, I feel like I have the basics of working with classes -- but I'm having a hell of a time organizing my code before I start working. I usually end up just coding in a straight line until things get so messy I give up.

The best way I can articulate my main question is to give an example. Right now I'm working on an inventory system for a classic RPG style game. I have no idea how to split it up into classes or where to put the functionality. Should the 'Item' class hold the code for drag/drop and interactive functions? Should the interactive stuff be its own class? Should I make an 'inventory manager' class that handles an array of items?

I can make it all work -- but I'm clueless as to how to organize it all efficiently. I'm rip roarin' and ready to code, but I don't want to get too used to coding dirty. If anyone could point me in the right direction I would be grateful.

Lonely Wolf
Jan 20, 2003

Will hawk false idols for heaps and heaps of dough.

Baldbeard posted:

I'm having a hell of a time organizing my code before I start working. I usually end up just coding in a straight line until things get so messy I give up.

Don't organize before you start working, organize as you work. Do one thing look at how it interacts with everything else you have, reorganize. You'll end up changing a lot of things a lot of times but as you do it you'll start making less changes as you get used to how things fit together and evolve a sense of design. This advice is additive to whatever anyone else says. Learn by doing.

TasteMyHouse
Dec 21, 2006

Lonely Wolf posted:

Don't organize before you start working, organize as you work. Do one thing look at how it interacts with everything else you have, reorganize. You'll end up changing a lot of things a lot of times but as you do it you'll start making less changes as you get used to how things fit together and evolve a sense of design. This advice is additive to whatever anyone else says. Learn by doing.

I'd just like to add that you'll probably make some terrible choice and paint yourself into a corner and have to do major refactoring multiple times. This is normal, and don't feel bad about it.

It would be worse if you didn't realize you were making mistakes and stuck with it.

Baldbeard
Mar 26, 2011

Thanks for the encouragement, I will keep chugging along. I'm probably just frustrated because when it comes to coding, I've noticed that there is a great wealth of 'just getting started basics' and 'advanced' resources, with a desert plateau somewhere in the middle.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Alright, I'm not sure where this goes, so I'll just put it here and hopefully it'll get seen.

Some emails were sent containing page.php?key=<number> and, for some reason, a bunch of users are having trouble with the ? getting auto-mangled into %3f when they click on the links in their email clients. I'm trying to come up with a quick server-side fix for this using RewriteRule, but none of these are matching:

code:
RewriteRule ^page.php%3fkey=(.*) /page.php?key=$1
RewriteRule ^page.php%3Fkey=(.*) /page.php?key=$1
RewriteRule ^page.php\%3fkey=(.*) /page.php?key=$1
RewriteRule ^page.php\%3Fkey=(.*) /page.php?key=$1
RewriteRule ^page.php\?key=(.*) /page.php?key=$1
And the File Does Not Exist message is getting written to the error log.

covener
Jan 10, 2004

You know, for kids!

Munkeymon posted:

Alright, I'm not sure where this goes, so I'll just put it here and hopefully it'll get seen.

Some emails were sent containing page.php?key=<number> and, for some reason, a bunch of users are having trouble with the ? getting auto-mangled into %3f when they click on the links in their email clients. I'm trying to come up with a quick server-side fix for this using RewriteRule, but none of these are matching:

code:
RewriteRule ^page.php%3fkey=(.*) /page.php?key=$1
RewriteRule ^page.php%3Fkey=(.*) /page.php?key=$1
RewriteRule ^page.php\%3fkey=(.*) /page.php?key=$1
RewriteRule ^page.php\%3Fkey=(.*) /page.php?key=$1
RewriteRule ^page.php\?key=(.*) /page.php?key=$1
And the File Does Not Exist message is getting written to the error log.

I confirm that the last one ought to match, unless you're confused about what you're getting over the wire. If these rules are in <virtualhost> context,and not htaccess/Directory, the anchor is wrong since what you're matching against will always start with a slash (you can just add it the slash)

raminasi
Jan 25, 2005

a last drink with no ice

Baldbeard posted:

Thanks for the encouragement, I will keep chugging along. I'm probably just frustrated because when it comes to coding, I've noticed that there is a great wealth of 'just getting started basics' and 'advanced' resources, with a desert plateau somewhere in the middle.

The middle is occupied by "rewriting your own terrible code a bajillion times." There isn't any way around it.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



covener posted:

I confirm that the last one ought to match, unless you're confused about what you're getting over the wire. If these rules are in <virtualhost> context,and not htaccess/Directory, the anchor is wrong since what you're matching against will always start with a slash (you can just add it the slash)

It's not in <virualhost>. I think the problem may be that my test machine is Windows so ? just isn't a valid character in a path because when I do this:
code:
RewriteCond %{QUERY_STRING} (.*)
RewriteRule .* thisExists.htm?%1

RewriteCond %{QUERY_STRING} ^$
RewriteRule .* soDoesThis.html
I still get a server error. Gonna see if I can find a better test environment.

Scaramouche
Mar 26, 2001

SPACE FACE! SPACE FACE!

pokeyman posted:

Agreed, but he asked for JavaScript. :-)

Of course, and your solution was right. It's just that javascript might not be... the best solution for a redirect problem.

covener
Jan 10, 2004

You know, for kids!

Munkeymon posted:

It's not in <virualhost>. I think the problem may be that my test machine is Windows so ? just isn't a valid character in a path because when I do this:
code:
RewriteCond %{QUERY_STRING} (.*)
RewriteRule .* thisExists.htm?%1

RewriteCond %{QUERY_STRING} ^$
RewriteRule .* soDoesThis.html
I still get a server error. Gonna see if I can find a better test environment.

I'm not entirely clear on the applicability of this to the original problem, in this context the bare ? would terminate the URL-path and start the substituted query string.

Perhaps the common thread is that you have some windows specific thing blowing up long before htaccess rewritess can even be processed due to the invalid URI->FS mapping.

In that case, you should move your rewrites out of htaccess/Directory and into VirtualHost context -- they run earlier there in the Apache API. Fix the anchor and tack on a PT flag as well.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



covener posted:

I'm not entirely clear on the applicability of this to the original problem, in this context the bare ? would terminate the URL-path and start the substituted query string.

Perhaps the common thread is that you have some windows specific thing blowing up long before htaccess rewritess can even be processed due to the invalid URI->FS mapping.

I was trying to figure out whether it thought there was a query string or not by setting up a situation where I could only get two responses and which one I got depended on the presence of a non-empty QS. It turns out that in my local setup at least, there's a comedy third option which is to fail with an error without hitting a rewrite rule (or I'm misunderstanding something which is quite possible).

quote:

In that case, you should move your rewrites out of htaccess/Directory and into VirtualHost context -- they run earlier there in the Apache API. Fix the anchor and tack on a PT flag as well.

I tried moving the rules into my <Directory settings for my local webroot and it didn't change anything. We don't use virtual hosts by decree from on high, so I'm not even going to try setting one up for a test.

Thermopyle
Jul 1, 2003

...the stupid are cocksure while the intelligent are full of doubt. —Bertrand Russell

Baldbeard posted:

Thanks for the encouragement, I will keep chugging along.

I find that I often realize I need a refactor, but I keep struggling with what I've got until I reach a breaking point. Then I do the refactor and it feels so good!

covener
Jan 10, 2004

You know, for kids!

Munkeymon posted:

We don't use virtual hosts by decree from on high, so I'm not even going to try setting one up for a test.

The equivalent to VH context in that case would simply be at the bottom of your apache configuration, not inside any other context -- which acts as like a catch-all vhost. This would get your rules running earlier.

Gothmog1065
May 14, 2009
Alright, I'm on the road to learning the basics of python, and picking it up fairly decently. Should I get a more advanced book for python, or should I look at learning another language?

e: More information: I have no specific need for any one language. I'm just learning stuff to learn right now. Would it be better to have a basic knowledge of all languages or have a firm grasp of one?

Gothmog1065 fucked around with this message at 19:03 on May 4, 2011

nielsm
Jun 1, 2009



Learning another language is never bad, although the choice of which one can be important :)

I'd suggest to keep using Python to write still more programs. Try to hold off on buying another book, instead see if how much you can pick up from reading library documentation on things you haven't worked with yet. It's a good skill to be able to figure out how to use a library from just its reference documentation.

As for a second language I'd suggest something C-like. Either pure C, C++ or C#. Java if you're feeling extra masochistic. Two reasons, first is to try a different kind of syntax (on some points more strict and others less strict than Python) and second to use a more strongly typed language.

Maybe also try dabbling with an SQL database and learn some basic relational database theory and the SQL query language. Python comes with the SQLite library that allows you to work with an SQL database without installing a database server.
Yes I just wrote Structured Query Language query language.

Lysidas
Jul 26, 2002

John Diefenbaker is a madman who thinks he's John Diefenbaker.
Pillbug

nielsm posted:

C, C++ or C#. Java
...
more strongly typed language

None of these languages are more strongly typed than Python. C in particular is weakly typed. Perhaps you mean a static type system?

nielsm
Jun 1, 2009



Lysidas posted:

None of these languages are more strongly typed than Python. C in particular is weakly typed. Perhaps you mean a static type system?

You're probably right. Statically checked types is my point of suggesting those languages at least.

tef
May 30, 2004

-> some l-system crap ->
Learn erlang! it is munctional

Deviant
Sep 26, 2003

i've forgotten all of your names.


This isn't working:

code:
cd~
export SOURCE=~
echo $SOURCE
export TARGET=~
echo $TARGET
export USER=xxxxxx
echo $USER
export PERMISSIONS=777
echo $PERMISSIONS
sudo ls $SOURCE > chmod.sh
/bin/echo '%s/^/sudo chmod $PERMISSIONS $SOURCE\//g\nwq!' | ex - chmod.sh
sudo ls $SOURCE > chown.sh
/bin/echo '%s/^/sudo chown $USER $SOURCE\//g\nwq!' | ex - chown.sh
sudo ls $SOURCE > move.sh
/bin/echo '%s/^/sudo mv $SOURCE\//g\nwq!' | ex - move.sh
sed 's/$/ $TARGET\//' move.sh > 2move.sh
mv 2move.sh move.sh
chmod 744 chmod.sh chown.sh move.sh
It won't parse any of the $variables for the echo and sed statements.

code:
$ cat chown.sh
sudo chown $USER $SOURCE/chmod.sh
sudo chown $USER $SOURCE/chown.sh
sudo chown $USER $SOURCE/test.sh
sudo chown $USER $SOURCE/testshort.sh
$
Any idea why? This is on a Solaris 10 system, ksh shell

Deviant fucked around with this message at 20:26 on May 5, 2011

baquerd
Jul 2, 2007

by FactsAreUseless

Deviant posted:

Any idea why? This is on a Solaris 10 system, ksh shell

Single quoted strings do not resolve variables inside of them by default. Try double quotes.

Deviant
Sep 26, 2003

i've forgotten all of your names.


baquerd posted:

Single quoted strings do not resolve variables inside of them by default. Try double quotes.

That was my first thought. Been there, done that. No dice. :(


code:
SOURCE=~
TARGET=~
USER=xxxxxx
PERMISSIONS=777
echo $SOURCE
echo $TARGET
echo $USER
echo $PERMISSIONS
sudo ls $SOURCE > chmod.sh
/bin/echo "%s/^/sudo chmod $PERMISSIONS $SOURCE\//g\nwq!" | ex - chmod.sh
sudo ls $SOURCE > chown.sh
/bin/echo "%s/^/sudo chown $USER $SOURCE\//g\nwq!" | ex - chown.sh
sudo ls $SOURCE > move.sh
/bin/echo "%s/^/sudo mv $SOURCE\//g\nwq!" | ex - move.sh
sed "s/$/ $TARGET\//" move.sh > 2move.sh
mv 2move.sh move.sh
chmod 744 chmod.sh chown.sh move.sh
code:
/support/mm755904
/support/mm755904
xxxxxx
777
Password for mm755904 on cpmero05:
Extra characters at end of "substitute" command
Extra characters at end of "substitute" command
Extra characters at end of "substitute" command
sed: command garbled: s/$/ /support/mm755904\//

qntm
Jun 17, 2009

Deviant posted:

code:
sed "s/$/ $TARGET\//" move.sh > 2move.sh
code:
sed: command garbled: s/$/ /support/mm755904\//

I don't know anything about sed but I am reasonably sure that a regular expression substitution like that won't work unless you escape the slashes in $TARGET somehow.

code:
sed "s/$/ \/support\/mm755904\//" move.sh > 2move.sh
Alternatively, does sed let you use a different delimiter? This would obviate a need for escaping.

code:
sed "s#$# /support/mm755904/#" move.sh > 2move.sh

MrDog
Apr 21, 2009
Does anyone know much about Processing? The reason being is, I'm stuck with a probably trivial problem, regarding sine waves (I think).

If you imagine having a series of circles (in an ArrayList) that move from offscreen towards the centre of the screen in a straight line, this is pretty simple enough for me to code, if (x > width/2) { x--; }, same for y, and so on... It's having those circle objects 'snake' their way around, that's confusing me.

I suppose similar to this, in a way, http://www.openprocessing.org/visuals/?visualID=6545 though not necessarily that complex, a simple S shape approach is what I'm looking for here, hence the sine wave?

Any pointers would be appreciated, thanks...hoping to turn these circles into enemy objects at some point..

Modern Pragmatist
Aug 20, 2008

MrDog posted:

Does anyone know much about Processing? The reason being is, I'm stuck with a probably trivial problem, regarding sine waves (I think).

If you imagine having a series of circles (in an ArrayList) that move from offscreen towards the centre of the screen in a straight line, this is pretty simple enough for me to code, if (x > width/2) { x--; }, same for y, and so on... It's having those circle objects 'snake' their way around, that's confusing me.

I suppose similar to this, in a way, http://www.openprocessing.org/visuals/?visualID=6545 though not necessarily that complex, a simple S shape approach is what I'm looking for here, hence the sine wave?

Any pointers would be appreciated, thanks...hoping to turn these circles into enemy objects at some point..

I'm not entirely sure what you are asking, but I think that I understand enough to be able to point you at parametric equations. Basic idea being that X and Y coordinates are functions of (at least) one other parameter (t). As t changes, X and Y evolve. So basically your different points in the snake will have different starting t's but the size of delta-t will be the same. So all circles will follow after one another.

Using parametric equations you can make a ton of different patterns. Alternately, you could vary the equations for X(t) and Y(t) over time to get a seemingly random movement.

Hope this helps somewhat?

peak debt
Mar 11, 2001
b& :(
Nap Ghost
This is kind of a silly question but it's been vexing me (CJ for job, coder for hobby) for years.

Let's say you have an array, and you want to output that array in a comma separated list. Any trivial way of doing this, let's say
code:
for (i=0; i<a.length; i++)) { s += a[i] + ", " }
has you end up with a trailing comma that isn't legal in most formats.

What's the best way to avoid that. Like what do they teach you in university to do in such a case.

spiritual bypass
Feb 19, 2008

Grimey Drawer
if(i < a.length-1){
put a comma
}

flyboi
Oct 13, 2005

agg stop posting
College Slice
So I've grown to the point with my clients in terms of relations that they're asking for pretty hectic dba type work. Note: this is 99% MySQL as that is what I've focused on in terms of database analysis. I'm able to identify queries that cause locking issues, basic schema overhaul and tweaking variables to assist with databases but I need a better grasp of how MySQL as a whole works and better-tweaking database schema. Like I can use explain on a query and have a rough idea on what to do in regards to indexing but I want to know how it works under the hood as I've seen in the past that while you might optimize one query that added index might affect others so that they run slower.


Anyone have some good books to suggest that I can read over to better-understand this stuff? I've read a lot of o'reilly books like high performance mysql . As an aside I had identified some queries a client was causing issues with and he ended up hiring Percona to look over his server and they said the same things. So that was a nice ego booster but I really would like to be able to tell clients "Hey, do this as MySQL sucks at this." My major points of focus are InnoDB and MyISAM.

ninjeff
Jan 19, 2004

peak debt posted:

This is kind of a silly question but it's been vexing me (CJ for job, coder for hobby) for years.

Let's say you have an array, and you want to output that array in a comma separated list. Any trivial way of doing this, let's say
code:
for (i=0; i<a.length; i++)) { s += a[i] + ", " }
has you end up with a trailing comma that isn't legal in most formats.

What's the best way to avoid that. Like what do they teach you in university to do in such a case.

http://msdn.microsoft.com/en-us/library/57a79xd0.aspx or nearest equivalent.

tef
May 30, 2004

-> some l-system crap ->

peak debt posted:

This is kind of a silly question but it's been vexing me (CJ for job, coder for hobby) for years.

What's the best way to avoid that. Like what do they teach you in university to do in such a case.

Write the obvious code that does it and worry less about one-liners

i.e, in pseudocode

if (len > 0) {
print a[0]
for (n in 1 ... len-1) { print ", ",a[n] }
}

Jarl
Nov 8, 2007

So what if I'm not for the ever offended?

peak debt posted:

What's the best way to avoid that. Like what do they teach you in university to do in such a case.

I just have to tell you that you wont be taught such trivial things if you study computer science at the university. Programming is merely a heavily employed tool and not the focus of study.

_aaron
Jul 24, 2007
The underscore is silent.
I'm looking at getting a Master's degree, but I'd like to do it part-time, and online if possible. I see that the University of Illinois offers an online "Master of Computer Science" (http://courses.illinois.edu/cis/2011/fall/programs/graduate/computer_science.html). This is a non-thesis program, which differentiates it from the standard "Master of Science, Computer Science." What disadvantages would such a program entail? If I wanted a PhD in the future, would this be problematic? Would employers view MCS differently than MSCS? Is this really not a big deal at all?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


_aaron posted:

I'm looking at getting a Master's degree, but I'd like to do it part-time, and online if possible. I see that the University of Illinois offers an online "Master of Computer Science" (http://courses.illinois.edu/cis/2011/fall/programs/graduate/computer_science.html). This is a non-thesis program, which differentiates it from the standard "Master of Science, Computer Science." What disadvantages would such a program entail? If I wanted a PhD in the future, would this be problematic? Would employers view MCS differently than MSCS? Is this really not a big deal at all?

Some employers might care, but others won't. If you really want to do a PhD, there are a number of reasons why a traditional master's degree is a much better choice.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

ultrafilter posted:

If you really want to do a PhD, there are a number of reasons why a traditional master's degree is a much better choice.

I'm not the one who was asking, and I believe you, but what are some of those reasons?

Adbot
ADBOT LOVES YOU

baquerd
Jul 2, 2007

by FactsAreUseless

pokeyman posted:

I'm not the one who was asking, and I believe you, but what are some of those reasons?

Most PhD's don't get a masters then just "decide" to go get the doctorate unless they want to stick around for 4-6 more years working on it. PhD's that get it done are PhD students their first year in graduate school, even if their program includes a Masters as well. Your entire academic career will shift dramatically if you try to get in to the PhD club and you will want to be focusing on that out of the gate.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply