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
Jabor
Jul 16, 2010

#1 Loser at SpaceChem

Boris Galerkin posted:

That ' mark completely messes up my syntax highlighting. Everything changes color, possibly because it's waiting for a closing ' mark. I'm using the Solarized theme if this makes any difference.

Is there a setting or something I can adjust to fix this? Right now what I do is just delete the offending ' mark, but it's a little bit annoying because I have to remember to add it back before I commit or else other people complain about it when I push it upstream.

Set fortran_dialect so the syntax highlighter knows you're using Fortran77.

Adbot
ADBOT LOVES YOU

ToxicFrog
Apr 26, 2008


The Collector posted:

I started learning sql a while back by using this site http://sqlzoo.net/ (among other things). I had to stop for a bit, and I'm starting to pick it up again. Are there any similar/better sites out there or is this my best bet?

apologies if this is the wrong thread :ohdear:

It is, in fact, the wrong thread (although there's probably some people in here who can help you regardless). You probably want the SQL Megathread. :)

Das MicroKorg
Sep 18, 2005

Vintage Analog Synthesizer
I hope this is the right thread for this: I'm building a small website and I'd like to display 6 random images from a list of images on every page reload. Of those 6 displayed images, there shouldn't be any duplicates though. Does anybody have a JavaScript code for that? All I can find online is code for one random image and I've never done a JS programming myself.


EDIT: V V V Thanks a lot guys :)

Das MicroKorg fucked around with this message at 14:08 on Jul 28, 2012

ToxicFrog
Apr 26, 2008


FLX posted:

I hope this is the right thread for this: I'm building a small website and I'd like to display 6 random images from a list of images on every page reload. Of those 6 displayed images, there shouldn't be any duplicates though. Does anybody have a JavaScript code for that? All I can find online is code for one random image and I've never doen a JS programming myself.

I don't have a full code example handy, but it may be helpful to know you can use images.splice(n,1) to remove the n'th element from the list (in-place). So, you can select an element at random, display it, and remove it from the list so it won't be selected again. Repeat until you've displayed as many images as you want.

You could also shuffle the entire list* and then just take the first six images from it.

* there is no builtin function for this in JS, so you'd have to write one. Don't do it by using sort() with a random comparison function, as some sites will recommend.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?
^^^
drat, beaten! Anyway, see below for my suggestion of a shuffling algorithm. It's trivial to implement in any language and the wikipedia article includes both pseudocode and a couple of language specific examples.

FLX posted:

I hope this is the right thread for this: I'm building a small website and I'd like to display 6 random images from a list of images on every page reload. Of those 6 displayed images, there shouldn't be any duplicates though. Does anybody have a JavaScript code for that? All I can find online is code for one random image and I've never doen a JS programming myself.

If you don't want duplicates then, as you've recognised, you can't just generate 6 random choices. One way to approach it is to rephrase the problem as taking the first 6 images from a randomly ordered set. This could be achieved by performing a Fisher-Yates shuffle on your list of images and then selecting the first 6 results from the resulting shuffled list. If you don't want to be performing the shuffle every time you reload the page (for example, if you have a very large list of images) you could store the shuffled list some manner and keep an offset into it which is incremented by 6 whenever the page is loaded. When offset + 6 > listSize, you reshuffle the list, store it again and set the offset back to zero.

rolleyes fucked around with this message at 14:03 on Jul 28, 2012

karms
Jan 22, 2006

by Nyc_Tattoo
Yam Slacker

rolleyes posted:

If you don't want duplicates then, as you've recognised, you can't just generate 6 random choices. One way to approach it is to rephrase the problem as taking the first 6 images from a randomly ordered set. This could be achieved by performing a Fisher-Yates shuffle on your list of images and then selecting the first 6 results from the resulting shuffled list.

Do this.

rolleyes posted:

If you don't want to be performing the shuffle every time you reload the page (for example, if you have a very large list of images) you could store the shuffled list some manner and keep an offset into it which is incremented by 6 whenever the page is loaded. When offset + 6 > listSize, you reshuffle the list, store it again and set the offset back to zero.

Don't do this. Shuffling a list is laughably easy work for a browser.

rolleyes
Nov 16, 2006

Sometimes you have to roll the hard... two?

KARMA! posted:

Don't do this. Shuffling a list is laughably easy work for a browser.

I more meant from a data transmission standpoint rather than it being processor intensive. If you've got a large image list you could be transferring tens of kb every time the page loads, whereas if you database your shuffled list and keep selecting the next 6 results you've probably cut it down to less than 1kb.

I doubt his website is going to be dealing with enough visitors for that to be a concern, but it's a valid bandwidth saving technique for high-traffic situations.

Rigged Death Trap
Feb 13, 2012

BEEP BEEP BEEP BEEP

I'm starting a computer science course later this year and I was wondering, since I am wet behind the ears on programming, what stuff I could read up on to begin with?

A list of other general stuff related to the course would be swell.

shrughes
Oct 11, 2008

(call/cc call/cc)

Rigged Death Trap posted:

I'm starting a computer science course later this year and I was wondering, since I am wet behind the ears on programming, what stuff I could read up on to begin with?

Less reading, more coding.

Make Python programs.

Thermopyle
Jul 1, 2003

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

shrughes posted:

Less reading, more coding.

Make Python programs.

Seconded.

leper khan
Dec 28, 2010
Honest to god thinks Half Life 2 is a bad game. But at least he likes Monster Hunter.

Rigged Death Trap posted:

I'm starting a computer science course later this year and I was wondering, since I am wet behind the ears on programming, what stuff I could read up on to begin with?

A list of other general stuff related to the course would be swell.
^^what those guys said for getting better with programming.

If you want a leg up on your course, it probably wouldn't hurt to read up on a few sorting algorithms. Try quick sort and bogo sort and please skip bubble sort.

vvv If you want real-time, free is mutually exclusive to good. Actually free+good basically doesn't exist for market data at all..

leper khan fucked around with this message at 20:58 on Jul 29, 2012

mmm11105
Apr 27, 2010
Anyone know of a good (free) API for stock data (quotes, prices, high/low), or even better one that would also let me get chart data, or enough historical data to make my own charts.

MrMoo
Sep 14, 2000

I presume you actually mean service, as even both the Bloomberg and Reuters API's are actually free now.

You can get delayed data free: free meaning without Exchange costs. The pricing is only network and management costs.

I do actually know how much MSN and & co. are spending per month for their data, it is not insignificant.

mmm11105
Apr 27, 2010

MrMoo posted:

I presume you actually mean service, as even both the Bloomberg and Reuters API's are actually free now.

You can get delayed data free: free meaning without Exchange costs. The pricing is only network and management costs.

I do actually know how much MSN and & co. are spending per month for their data, it is not insignificant.

Basically, I need a simple way to grab the basic info for some stocks. (Last Trade Price, Bid, Ask, Open, Close, etc.), as well as hopefully some historical data or a chart service. Also needs to support foreign markets (in particular Toronto Stock Exchange)

Doctor w-rw-rw-
Jun 24, 2008

Rigged Death Trap posted:

I'm starting a computer science course later this year and I was wondering, since I am wet behind the ears on programming, what stuff I could read up on to begin with?

A list of other general stuff related to the course would be swell.

Python the Hard Way. Get comfortable with it. Followed by SICP if you want to challenge yourself in the long term.

Nighttheii
Nov 21, 2007
hi
A Computer Science course I'll be taking in the fall is using Ada '95. This might sound stupid, but, I'm not sure where to find a (Compiler? IDE?) to write and run programs in this language.

The links on my school's website are all dead, similar to the websites I've tried on Google. What should I do?

ultrafilter
Aug 23, 2007

It's okay if you have any questions.


Nighttheii posted:

A Computer Science course I'll be taking in the fall is using Ada '95. This might sound stupid, but, I'm not sure where to find a (Compiler? IDE?) to write and run programs in this language.

The links on my school's website are all dead, similar to the websites I've tried on Google. What should I do?

That's an interesting choice of language. Anyway, this looks like a good place to start.

Nighttheii
Nov 21, 2007
hi

ultrafilter posted:

That's an interesting choice of language. Anyway, this looks like a good place to start.

I thought all the links on this site were dead, but the one mirror link for NYU works. I guess I need to click more thoroughly. Thanks!

ToxicFrog
Apr 26, 2008


Also, if you're on linux, debian (and probably other distros as well) has an ada compiler in the repositories.

Might also want to tell the prof/TA/IT/whoever that the course website is busted.

Vanadium
Jan 8, 2005

Does this help?

http://en.wikibooks.org/wiki/Ada_Programming/Installing

Nighttheii
Nov 21, 2007
hi

It does, Thank you!

Vanadium
Jan 8, 2005

This also sounds kinda interesting~

http://blog.spacesocket.com/2012/07/23/learning-ada/

Feral Integral
Jun 6, 2006

YOSPOS

Was reading about the pop (mail) library python has here and came across this line in the example:

code:
numMessages = len(M.list()[1])
I don't know what [1] next to the M.list() function means, anyone know?

Ahh duh a list is the return value. sorry, been a while. Thanks!
VVV

Feral Integral fucked around with this message at 04:55 on Aug 2, 2012

vikingstrike
Sep 23, 2007

whats happening, captain
It's referencing the second item in M.list().

ToxicFrog
Apr 26, 2008


Feral Integral posted:

Was reading about the pop (mail) library python has here and came across this line in the example:

code:
numMessages = len(M.list()[1])
I don't know what [1] next to the M.list() function means, anyone know?

M.list(), per the manual, returns a 3-tuple. The [1] is an index into the tuple, accessing the second element in it (tuples, like all indexed data structures in python, are 0-indexed).

etcetera08
Sep 11, 2008

Nighttheii posted:

A Computer Science course I'll be taking in the fall is using Ada '95. This might sound stupid, but, I'm not sure where to find a (Compiler? IDE?) to write and run programs in this language.

The links on my school's website are all dead, similar to the websites I've tried on Google. What should I do?

:hfive: Ada-for-school buddy. It was recommended that we use AdaGIDE as an IDE on Windows (after installing GNAT) but I ended up just ssh'ing into our campus's Ubuntu machine and doing everything that way so I didn't really worry about local configuration. Might be easier if you have that option?

mrbotus
Apr 7, 2009

Patron of the Pants
More Eclipse related than actually related, but...

Well, I hit a key on my keyboard, and now instead of the typical stick-thin marker that's used to mark the place in the document where I'm typing, it's become a big, thick block. It highlights one character, but only affects the characters to the left or right (when I delete something, or add a character).

I can't figure out how to undo it, and it's very annoying and disorienting. tia

fletcher
Jun 27, 2003

ken park is my favorite movie

Cybernetic Crumb
Sounds like you are in insert mode. Just tap the insert key on your keyboard to get out of it. There should be an indicator in the bottom right of eclipse that says whether you are in insert or overwrite mode.

stubblyhead
Sep 13, 2007

That is treason, Johnny!

Fun Shoe
When you use POST as a html form submission method, what does the submitted document look like? Say your html page is like

code:
<html>
<body>
<form  action="farts.php" method="post" target="hole">
     <input type=text name=beans>
     <input type="Submit" value="Toot"></br>
</form>
</body>
</html>
what actually gets posted to farts.php ?

I SAID LISTEN
Jan 10, 2007
I don't *do* up.
I guess it's more a question about programming structure, but I'm tinkering around in Python with a roguelike module (libtcod) mainly to learn the language. As my code's getting bigger I'm wondering whether it is important to start moving things to their own modules, and what exactly the benefits of this are. Moreover, is there a clean way to do this? A lot of things (e.g. in handling keyboard input) refer to specific objects that, I suspect, will break a bit if I move them to their own module.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

stubblyhead posted:

When you use POST as a html form submission method, what does the submitted document look like? Say your html page is like

code:
<html>
<body>
<form  action="farts.php" method="post" target="hole">
     <input type=text name=beans>
     <input type="Submit" value="Toot"></br>
</form>
</body>
</html>
what actually gets posted to farts.php ?

Someone will doubtless answer in more detail and/or fix inaccuracies in this, but something like the following:

this assumes that the full URL to farts.php is your.subdomain.yoursite.com/path/to/farts.php, and that you entered "Some text about beans" in the text input, and submitted the form by clicking the submit button.

code:
POST /path/to/farts.php HTTP/1.1
Host: your.subdomain.yoursite.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 33

beans=Some%20text%20about%20beans
The first line specifies that the request is an HTTP 1.1 POST request and specifies the resource that is to receive the request. The next three lines are headers that tell the receiving resource some information about the request or the request body. The first one (Host) is used in routing the request in the case where multiple sites have the same IP address (e.g. in case of a shared web host) - it allows the web server to know which site the request is actually for. After the double newline is the actual request body. In this case it is URL-encoded form field data.

I am not sure whether a variable is sent for the submit button, because you didn't give it a name. I'm pretty sure that if you do give it a name, then it sends a variable for the submit button, and its value is the "value" attribute on the button (so in this case, "Toot")

Bear in mind that anyone can craft any HTTP request they like (or even craft a malformed request) and send it to your script, so don't rely on requests looking the way they are supposed to look, and also there might be all sorts of different headers like a user-agent header, "accept" headers, etc. etc.

Hammerite fucked around with this message at 23:31 on Aug 2, 2012

stubblyhead
Sep 13, 2007

That is treason, Johnny!

Fun Shoe

Hammerite posted:

Bear in mind that anyone can craft any HTTP request they like (or even craft a malformed request) and send it to your script, so don't rely on requests looking the way they are supposed to look, and also there might be all sorts of different headers like a user-agent header, "accept" headers, etc. etc.

Heh, I'm actually the person trying to create this http request, I just don't know how to form the post document. Why they used post instead of get I'm not sure, cause it's just pulling some data from somewhere and displaying it.

edit: and that actually worked perfectly. I was basically doing the same thing in my first quick test, but I was posting to the html page instead of the script. :downs:

stubblyhead fucked around with this message at 23:49 on Aug 2, 2012

Zombywuf
Mar 29, 2008

stubblyhead posted:

Heh, I'm actually the person trying to create this http request, I just don't know how to form the post document. Why they used post instead of get I'm not sure, cause it's just pulling some data from somewhere and displaying it.

edit: and that actually worked perfectly. I was basically doing the same thing in my first quick test, but I was posting to the html page instead of the script. :downs:

In general you probably want to find a library that will make the request in whatever language you are using. There are a few extra things that need to be handled that a library will probably do for you, it will also make your code simpler.

Lamont Cranston
Sep 1, 2006

how do i shot foam
So I've been working on a small encryption project/proof-of-concept and I've hit a snag. Please bear in mind that my previous experience with crypto is extremely limited, so if it looks like I'm doing something dumb here you're probably right.

Essentially, I have a ruby script and a nodejs script that do a Diffie-Hellman key exchange. The ruby script sends its public key, and the node script calculates the private key, then MD5 digests the key and uses it to encrypt a piece of text using AES-128-CBC (I've also tried this with SHA256/AES256 with the same results). Node then concatenates the IV and ciphertext, and sends them back in the response. Ruby then decrypts/prints the message.

This all works great when I use a 16 character string like '1234567890abcdef' for the IV:
code:
var str = '1234567890abcdef';
var iv = new Buffer(iv);
I send it across concatenated to the front of the ciphertext, separate them on the ruby side, and everything decrypts just fine. But when I generate a random 16 bytes:

code:
var iv = crypto.randomBytes(16);
The decryption comes out wrong. The first 16 characters of the decrypted text are garbled and corrupt, but the rest of the text is fine. For example:
code:
in : Lorem ipsum dolor sit amet, consectetur adipiscing elit posuere.
out: Morem4j-sZmz?&#1412;?r sit amet, consectetur adipiscing elit posuere.
in : 4c 6f 72 65 6d 20 69 70 73 75 6d 20 64 6f 6c 6f 72 20 73 69 74 20 61 6d 65 74 2c 20 63 6f 6e 73 65 [...]
out: 4c 6f 28 12 29 c3 58 a2 92 0a 3d e9 8f a2 1e d2 72 20 73 69 74 20 61 6d 65 74 2c 20 63 6f 6e 73 65 [...]
I am removing the IV from the ciphertext before I decrypt it, so it's not that. I can see that the IV that ruby is using is the same 16 bytes as the ones I randomly generate on the node end. Both libraries are using OpenSSL behind the scenes as far as I can tell, and they're both running on the same machine so they should be using the same OpenSSL. So if anyone knows what I might be doing wrong here or just has any general advice I'd love to hear it. I'm also happy to clarify anything I glossed over here.

shrughes
Oct 11, 2008

(call/cc call/cc)
You have some issues in your code and you probably have some issues in your encryption too, my bet is you aren't actually encrypting more than the first block.

Edit: Your problem is that you aren't authenticating your message, and there's a man in the middle on your machine twiddling its bits.

Lamont Cranston
Sep 1, 2006

how do i shot foam

shrughes posted:

You have some issues in your code and you probably have some issues in your encryption too, my bet is you aren't actually encrypting more than the first block.

Edit: Your problem is that you aren't authenticating your message, and there's a man in the middle on your machine twiddling its bits.

I'm fully ready to admit that my knowledge here is lacking and I'm more or less learning as I go. Obviously none of this is going anywhere near production. That being said, the output of the encryption and what I get back on the other side from the HTTP response are byte-for-byte identical. Also, if only the first block were being encrypted, I would tend to think the encrypted output would be the same after 16 bytes from run to run, correct?

shrughes
Oct 11, 2008

(call/cc call/cc)
You probably can't be helped unless you show the code.

cannibustacap
Jul 7, 2003

Brrrruuuuuiinnssss
Redhat shell script question! Right now, I conduct audits on a linux machine by doing the following steps

  1. Check to make sure the /var/log/audit/audit.log files are not split apart.
    If they are, concatenate them into a single audit.log file
  2. Within a folder /isso/ run a script called ./rotate_logs.sh
    That script grabs audit.log (as well as a few other logs) and restarts the audit service. It then moves the logs into a folder called /isso/logs_rotated
  3. Copy another script called auditprocess.sh into /isso/logs_rotated
  4. Go into /isso/logs_rotated and run ./auditprocess.sh

Now, I follow all these steps because I can't figure out how to write an umbrella .SH file that will do these steps for me.

I notice that if I am not precisely in the right folder and run the scripts, for example if I am not precicely in /isso/logs_rotated when I run auditprocess.sh, it will blow up. Even if I am in the root \ folder and I manually run ./isso/logs_rotated/auditprocess.sh it still blows up.

So, I am pretty newb to shell scripting, but I am failing to google these issues properly.

Any tips on how I can take those 4 steps and make them into a single shell script that can be run anywhere?

This is what I do by hand now
  1. sudo bash
    (get root privileges)
  2. cd /var/log/audit
    (check the audit.log.* files if there are any. cat them to one single audit.log if so)
  3. cd /isso/
  4. ./rotate_logs.sh
  5. cp auditprocess.sh logs_rotated/
  6. cd logs_rotated/
  7. ./auditprocess.sh

I have to do that to many machines. I can do it fast, but I think its about time I learn how to really use Shell.

Lamont Cranston
Sep 1, 2006

how do i shot foam

shrughes posted:

You probably can't be helped unless you show the code.

Happy to:
Ruby: http://hastebin.com/cunihinuma.rb
java script: http://hastebin.com/penolufube.js

Adbot
ADBOT LOVES YOU

shrughes
Oct 11, 2008

(call/cc call/cc)

Oh, it's corrupt differently each time! Here are some outputs I got, except for the first line which is for reference.

code:
Lorem ipsum dolor sit amet, consectetur adipiscing elit posuere.
LzUe6Qips!m dolor sit amet, consectetur adipiscing elit posuere.
%&#65533;;>&#65533;T&#65533;&#65533;&#65533;&#65533;	@&#65533;j4&#65533;r sit amet, consectetur adipiscing elit posuere.
Lordm&#65533;&#65533;&#65533;&#65533;&#587;_&#65533;&#65533;r sit amet, consectetur adipiscing elit posuere.
!oFm} ;n`dolr sit amet, consectetur adipiscing elit posuere.
!;Jem)?p2v"dol|r sit amet, consectetur adipiscing elit posuere.
6m `Zsum [tr sit amet, consectetur adipiscing elit posuere.
The corruption seems to be on the Ruby side -- NodeJS can decrypt the buffer just fine.

What if I set the iv to this:

code:
            var iv = new Buffer([0,1,2,3,4,5,128,7,8,9,0,1,2,3,4,127]);
It seems you get corruption on the Ruby side when the IV has characters 128 or higher. And it corresponds exactly to the position of the character.

Let's look at how CBC works:
http://en.wikipedia.org/wiki/Block_cipher_modes_of_operation#Cipher-block_chaining_.28CBC.29

You can see that the IV is supposed to get XORed with the output of the block cipher to create the plaintext. However, it works correctly for future blocks because the IV only affects the output of the first block, on the Ruby side. (It affected the values of the ciphertext blocks on the JS side.)

So I'm guessing the Ruby OpenSSL library is loving things up, maybe it depends on what Ruby version you're using.

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