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
LuckySevens
Feb 16, 2004

fear not failure, fear only the limitations of our dreams

Newbie question, want to populate a database on a timer every morning, the data being made up off data I've scrapped from yahoo finance. I've written python methods to make calculations and scrap it, now I need a way to store each days scrap on a webserver that will also be hosting django. What is the best way to go about this?

Adbot
ADBOT LOVES YOU

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Make it into a plain old cronjob, or, if you're feeling like a more Pythonic ( :suicide: ) solution, you can look into the sched module, which I can't speak personally on.

bitprophet
Jul 22, 2004
Taco Defender

Dijkstracula posted:

Make it into a plain old cronjob, or, if you're feeling like a more Pythonic ( :suicide: ) solution, you can look into the sched module, which I can't speak personally on.

Honestly, a cronjob is usually the most Pythonic way to run periodic tasks, because real Pythonistas know when the best tool for a job is one not written in Python :) And nothing says the cronjob can't be calling a Python script, of course.

ErIog
Jul 11, 2001

:nsacloud:

bitprophet posted:

Honestly, a cronjob is usually the most Pythonic way to run periodic tasks, because real Pythonistas know when the best tool for a job is one not written in Python :) And nothing says the cronjob can't be calling a Python script, of course.

The cleanest way to do this would be for the cron job to call a Python script. The script imports the models from the Django app, scrapes Yahoo finance, and populates the database using Django's model methods. If you know what cron is, you already know how to use Django, and you've already written the code to scrape then it shouldn't take more than 5 minutes.

NO! I DONT DO ANAL!
Sep 13, 2009

by Tiny Fistpump
I wrote a quick little function in Lisp (ACL2 to be precise) to do compute the factorial of a number. Nothing fancy, just:
code:
(defun ! (x)
  (if (zp x)
    1
    (* x (! (+ -1 x)))
  )
)
And it can't go beyond 1361 on my compiler on my computer before freaking out. I figured that okay, it probably can't handle numbers that big (the number is 3677 digits long), but out of curiosity I multiplied it by 1362:
code:
(* 1362 (! 1361))
and it gave what might possibly be the correct number. I mean, that has the exact same effect as the recursive call in the function, so why would the machine be perfectly happy to perform some action recursively 1361 times but not 1362 times, but still perform that exact same action without complaining if told to do so explicitly?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
What do you mean by freaking out? Naive recursion grows the stack for reasons that are obvious, so you could be hitting your process stack size limit.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

define "freaking out". (e: fb)

NO! I DONT DO ANAL!
Sep 13, 2009

by Tiny Fistpump
Hmm, could be stack overflow... Here, have a gigantically trimmed-down version of the output for (! 1362)

code:
! > if > acl2_*1*_acl2::binary-* > acl2_*1*_acl2::
! > if > acl2_*1*_acl2::binary-* > acl2_*1*_acl2::! > if > acl2_*1*_acl2::binary
-* > acl2_*1*_acl2::! > if > acl2_*1*_acl2::binary-* > acl2_*1*_acl2::! > if > a
cl2_*1*_acl2::binary-* > acl2_*1*_acl2::! > if > acl2_*1*_acl2::binary-* > acl2_
*1*_acl2::! > if > acl2_*1*_acl2::binary-* > acl2_*1*_acl2::! > if > acl2_*1*_ac
l2::binary-* > acl2_*1*_acl2::! > if > acl2_*1*_acl2::binary-* > acl2_*1*_acl2::
! > if > acl2_*1*_acl2::binary-* > system:universal-error-handler > system::brea
k-level-for-acl2 > let* > UNLESS
ACL2 !>
The ^ function has the same cutoff ( (^ 2 1361) works, (^ 2 1362) doesn't) so you're probably right and the cutoff is on stack capacity. Thanks guys!

Fly
Nov 3, 2002

moral compass

NO! I DONT DO ANAL! posted:

I wrote a quick little function in Lisp (ACL2 to be precise) to do compute the factorial of a number. Nothing fancy, just:
code:
(defun ! (x)
  (if (zp x)
    1
    (* x (! (+ -1 x)))
  )
)
If you could make it tail recursive you won't have stack issues.

quote:

http://userweb.cs.utexas.edu/users/moore/publications/gentle-intro-to-acl2-programming.html
Finally, when these two functions are compiled, the recursion in sum-up requires a stack to execute while the recursion in sum-down does not: sum-down is tail recursive. This means that the value of the recursive call is returned as the final answer and there is no need for the execution engine to ``remember'' to come back after the call to ``do something.'' In sum-up the execution engine must ``remember'' to add the two intermediate results together. Tail recursive calls are compiled as simple jumps or ``gotos'' and result in faster executions that require less stack space.

defmacro
Sep 27, 2005
cacio e ping pong

NO! I DONT DO ANAL! posted:

Hmm, could be stack overflow... Here, have a gigantically trimmed-down version of the output for (! 1362)

code:
crazy loving error message
The ^ function has the same cutoff ( (^ 2 1361) works, (^ 2 1362) doesn't) so you're probably right and the cutoff is on stack capacity. Thanks guys!

Is there any reason you're using ACL2 in lieu of a nicer Lisp implementation (mzscheme, SBCL, Clojure, CLisp, etc.) for general programming? ACL2 is for computer-aided proofs, not general purpose programming. Here's the error generated by SBCL:
code:
* (defun ! (x) (if (zerop x) 1 (* x (! (- x 1)))))
* (! 1000000)
Control stack guard page temporarily disabled: proceed with caution

debugger invoked on a SB-KERNEL::CONTROL-STACK-EXHAUSTED in thread #<THREAD "initial thread" RUNNING {1192B6C9}>:
  Control stack exhausted (no more space for function call frames).
This is probably due to heavily nested or infinitely recursive function
calls, or a tail call that SBCL cannot or has not optimized away.
or Clojure
code:
user=> (defn ! [x] (if (zero? x) 1 (* x (! (dec x)))))
#'user/!
user=> (! 100000000)
java.lang.StackOverflowError (NO_SOURCE_FILE:0)
Both of which are very clear and more suited to factorial and above programming.

defmacro fucked around with this message at 03:40 on Mar 25, 2010

mincepiesupper
Apr 9, 2009
Anyone know how to mount an .iso file programmatically (in Windows) so that the files and their contents can be searched? I have many .iso files so would rather not do it a few at a time using Virtual CloneDrive.

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

mincepiesupper posted:

Anyone know how to mount an .iso file programmatically (in Windows) so that the files and their contents can be searched? I have many .iso files so would rather not do it a few at a time using Virtual CloneDrive.

Why does it need to be mounted? I'm pretty sure 7-zip reads ISO files and can be run from the command line.

FunOne
Aug 20, 2000
I am a slimey vat of concentrated stupidity

Fun Shoe
I'm working on a personal project that might end up being a product at some point (and I'd like to retain that option). I've come upon a complicated section and I've found a GWT widget that fills the role EXACTLY, BUT it is licensed as GPLv3.

Now, GWT code is compiled into Javascript, which would imply to me that GPL requires I make the entirety of my GUI code open source, but I wouldn't be modifying the GWT widget at all, just using it for a portion of my UI.

So, which is it, is the compilation activity of GWT killing me and requiring me to make my entire project GPLv3, or can I include the widget without internal modification and call it an 'aggregate' usage of the widget?

Or should I just e-mail the guy writing the code with my question and ask him to modify the license to one less stupid for GWT?

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
If you want to use it, ask him to let you use it under different license terms (asking him to relicense it generally would probably be a non-starter for reasons you can guess). He probably won't if he specified GPLv3, and in that case, don't use it.

Vinterstum
Jul 30, 2003

FunOne posted:

Or should I just e-mail the guy writing the code with my question and ask him to modify the license to one less stupid for GWT?

He doesn't necessarily need to -change- the license, there's nothing preventing him from releasing the software under two different licenses. It's common for companies to do dual-licensing: You get the GPL version for free, but you can also pay a fee to get access to a version under a license that lets you keep your source closed.

Peao
Dec 1, 2004
If you can read this, remind me of why I shouldn't post.
Maybe this isn't the right thread for someone who just wants to rant, but...

Is it me or is Eclipse a steaming pile of poo poo? First the default Eclipse C/C++ install couldn't compile its own Hello World template without tweaking, then I find out the long painful way that printf() doesn't work, and now it's refusing to compile a project I'm working on, pointing to errors that are no longer there. (I deleted the lines, they're not even in the cpp file anymore!) I tried "Build Project" and "Clean Project" and even closing and reopening Eclipse which has worked for me with previous bugs. I've been programming Notepad-style for the last 5 hours, knowing the project won't compile and hoping I can fix things later.

The OSS world really, really needs a quality IDE that can be mentioned in the same breath as Visual Studio if they want to recruit from the new generations of programmers.

Arms_Akimbo
Sep 29, 2006

It's so damn...literal.
I'm trying to export multi-line text from Delphi (TRichEdit) into Excel. The problem is that all the CR/LFs are accompanied by a question mark in a box. If I copy that character and paste it elsewhere, its a CR/LF.

In the string in Delphi it appears as '#$D#$A#$D#$A' (with the single quotes) I tried replacing it with the normal #13+#10, tried ascii replace, tried formatting the cell in Excel as text, drat things keep showing up.

Any suggestions?

E: Figured it out

code:
sQForm := stringreplace(sQForm, #13#10, chr(10), [rfReplaceAll])
Nothing to see here.

Only registered members can see post attachments!

Arms_Akimbo fucked around with this message at 15:42 on Mar 26, 2010

Munkeymon
Aug 14, 2003

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



Peao posted:

The OSS world really, really needs a quality IDE that can be mentioned in the same breath as Visual Studio if they want to recruit from the new generations of programmers.

Give NetBeans a shot http://netbeans.org/features/cpp/index.html

It's significantly less annoying than Eclipse in my experience.

mincepiesupper
Apr 9, 2009

Avenging Dentist posted:

Why does it need to be mounted? I'm pretty sure 7-zip reads ISO files and can be run from the command line.


Thankyou for that suggestion, I tried 7-zip out and it does exactly that.

DrBouvenstein
Feb 28, 2007

I think I'm a doctor, but that doesn't make me a doctor. This fancy avatar does.
A question regarding MATLAB:

I have an assignment to basically produce a "jumble" type of game, where a word (read randomly from a given list of words,) is scrambled up, and the user has to guess it.

Where I am stuck right now is at the actual scrambling function. We were told to make a function that generates a random integer between two values, ok, I got that and it works fine. We are then told to use that function during the scrambling of the word. Here's the notes from the prof.:

Algorithm for scrambling a word:
for i = 1 : length(word) %once for each letter in the word
select a random number between 1 and length(word) (let's call this r)
swap the letter at index i and the letter at index r

This makes sense at first, but then I think to much...what's stopping this loop from picking the same letter to swap multiple times? I mean...let's say we are scrambling the word "hello." We could get:

"lehol"

But isn't it possible to get:

"leeho" instead?

There is nothing stopping that loop, from what I can tell, from getting the same random number more than once.

So how would I go about creating some kind of error check against that? I assume I'll have to store all of the 'r' values into a vector, and then compare the newest one generated with what's in there, and if it matches any of them, reject the number and try again?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

DrBouvenstein posted:

But isn't it possible to get:

"leeho" instead?

There is only one "e" in the string "hello". No matter how many times you swap its position with some other letter, there will still only ever be one "e". What sequence of random numbers do you think will cause this result?

DrBouvenstein
Feb 28, 2007

I think I'm a doctor, but that doesn't make me a doctor. This fancy avatar does.

ShoulderDaemon posted:

There is only one "e" in the string "hello". No matter how many times you swap its position with some other letter, there will still only ever be one "e". What sequence of random numbers do you think will cause this result?

But that's the thing, they aren't actually swapping! At least not using the algorithm given to us. All it's doing is making a new word based on random letters from the existing word, so you can get copies of the same letter.

Here is my actual code:

code:
function scrambled = scramble_word( word )
%scramble_word scrambles a word inputed to the function

high = length(word);
 
scrambled = blanks(high);


for i = 1:high 
    r = myrandint(1, high); 
    scrambled(i) = word(r);
end
And here is the myrandint function:

code:
function r = myrandint( low, high )
%myrandint Returns a random integer in the range specified 


r = round(rand*(high-low)+low);

end
So it's very possible that in the loop, the number 2 is generated more than once by myrandint, so the new word has no guarantee of being composed of only the exact same letters.

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

DrBouvenstein posted:

But that's the thing, they aren't actually swapping! At least not using the algorithm given to us. All it's doing is making a new word based on random letters from the existing word, so you can get copies of the same letter.

DrBouvenstein posted:

Algorithm for scrambling a word:
for i = 1 : length(word) %once for each letter in the word
select a random number between 1 and length(word) (let's call this r)
swap the letter at index i and the letter at index r

Your pseudocode says to swap, not to create a new word. Your code is not doing the same thing as your pseudocode.

DrBouvenstein
Feb 28, 2007

I think I'm a doctor, but that doesn't make me a doctor. This fancy avatar does.

ShoulderDaemon posted:

Your pseudocode says to swap, not to create a new word. Your code is not doing the same thing as your pseudocode.

OK, I see what you're saying. So if I just change my code to:

code:
function scrambled = scramble_word( word )
%scramble_word scrambles a word inputed to the function

high = length(word);
 
scrambled = word;


for i = 1:high 
    r = myrandint(1, high); 
    scrambled(i) = scrambled(r);
end
It should be ok?

ShoulderDaemon
Oct 9, 2003
support goon fund
Taco Defender

DrBouvenstein posted:

OK, I see what you're saying. So if I just change my code to: [snip] It should be ok?

Edit: Wait, misread your new code. You need to swap, not just assign once.

So, scrambled(i) needs to have the value that was in scrambled(r), and scrambled(r) needs to have the value that was in scrambled(i). You'll probably want to introduce a temporary variable for this.

Little Brittle
Nov 1, 2004

Come visit me dawg
I'm not sure where to ask, but I am having trouble generating the correct SSL info in Plesk on a CentOS/Apache server. When I generate the CSR via Plesk and use that to create a 3rd party certificate, it supplies all the wrong data. The certificate says "test.domain.com" by "SomeCompany" and it fails to pass in the browser. I'd like to know where this info is pulled from on the server, because I've never entered it anywhere. I've gone through every field in Plesk and stored the correct data, so this is probably something outside of Plesk. I've been digging through openssl.cnf files via SSH, but none contain the data that is being supplied on the certificate, so I'm not sure which one to edit. Does anyone know where I can enter the SSL configuration for the entire server that Plesk pulls from?

Little Brittle fucked around with this message at 21:30 on Mar 28, 2010

yatagan
Aug 31, 2009

by Ozma

Little Brittle posted:

I'm not sure where to ask, but I am having trouble generating the correct SSL info in Plesk on a CentOS/Apache server. When I generate the CSR via Plesk and use that to create a 3rd party certificate, it supplies all the wrong data. The certificate says "test.domain.com" by "SomeCompany" and it fails to pass in the browser. I'd like to know where this info is pulled from on the server, because I've never entered it anywhere. I've gone through every field in Plesk and stored the correct data, so this is probably something outside of Plesk. I've been digging through openssl.cnf files via SSH, but none contain the data that is being supplied on the certificate, so I'm not sure which one to edit. Does anyone know where I can enter the SSL configuration for the entire server that Plesk pulls from?

This is a software problem, not a programming problem - check SH/SC tech support subforum?

Inverse square
Jan 21, 2008
Ah but you see I was an 06 lurker
This may seem like an odd request, but can anyone point me in the direction of some interesting/old/possibly famous open source C++ code? I'm trying to learn it and I personally find that I get motivated well by giving myself a glimpse of what I'm eventually going to understand (does anyone else do this?). A 3D engine or physics simulator or something would be ideal.

Scaevolus
Apr 16, 2007

Inverse square posted:

This may seem like an odd request, but can anyone point me in the direction of some interesting/old/possibly famous open source C++ code? I'm trying to learn it and I personally find that I get motivated well by giving myself a glimpse of what I'm eventually going to understand (does anyone else do this?). A 3D engine or physics simulator or something would be ideal.
Box2D?

Feral Integral
Jun 6, 2006

YOSPOS

I'm working on this small python script for something school related. This being pretty much the first time I've done anything with python I've run into a problem that I can't seem to work out.

I have a list that I must iterate over backwards so I have something like:

code:
list = [1,2,3]
sum = list[-1] #sum starts at the value of the last item in the list
for i in reversed(list):
   [b]sum-= list[i-1][/b]
...
The goal is to have the sum equal to the last item in the list and have the for loop subtract each previous item from said sum until the beginning of the list is reached. But I get an error and the "bolded" line: "IndexError: list out of range". Not sure what I'm missing.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

What are you actually trying to do? I have no idea why you're doing what you're doing in that way, and the code you supply works on my end:

code:
ntaylor@ntaylor-loonix:~$ cat foo.py 
list = [1,2,3]
sum = list[-1] #sum starts at the value of the last item in the list
for i in reversed(list):
	sum-= list[i-1]
ntaylor@ntaylor-loonix:~$ python foo.py 
ntaylor@ntaylor-loonix:~$ 
You do understand that every time you go through that loop, i is an element of list, not the index to an element, right?

Avenging Dentist
Oct 1, 2005

oh my god is that a circular saw that does not go in my mouth aaaaagh

Dijkstracula posted:

What are you actually trying to do?

Presumably sum = list[-1] - sum(list[:-1])

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Avenging Dentist posted:

Presumably sum = list[-1] - sum(list[:-1])
Right but then why does he say he must iterate backwards over the list or this business about sum equaling the last element or list[-1] or whatever? :pwn:

Vinterstum
Jul 30, 2003

Inverse square posted:

This may seem like an odd request, but can anyone point me in the direction of some interesting/old/possibly famous open source C++ code? I'm trying to learn it and I personally find that I get motivated well by giving myself a glimpse of what I'm eventually going to understand (does anyone else do this?). A 3D engine or physics simulator or something would be ideal.

Famous? Quake I/II/III source code: http://www.idsoftware.com/business/techdownloads/

Vinterstum fucked around with this message at 20:06 on Mar 29, 2010

pseudorandom name
May 6, 2007

Vinterstum posted:

Famous? Quake I/II/III source code: http://www.idsoftware.com/business/techdownloads/

Doom 3 was the first C++ game engine from id Software.

Dijkstracula
Mar 18, 2003

You can't spell 'vector field' without me, Professor!

Also, it should be noted that if you're looking for good, clean C++ to learn good style from, a 3D engine that a) uses all sorts of tricks to squeeze performance out of and b) may have been rushed in order to meet a release deadline might not be the best choice.

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip
Carmack actually gave up some performance to unify light and shadows in the Doom 3 engine in a way he thought was elegant (and probably does fit with most people's naive mental model pretty well). This being said, Carmack's C was never very good looking and I doubt his C++ is much better. The code to the HL2 engine (called 'Source' for reasons that are comedic) got leaked years ago and is still floating around if you look, and is also very bad (unless you're looking for an example of why piecemeal growth and bolting poo poo on can be dangerous).

Inverse square
Jan 21, 2008
Ah but you see I was an 06 lurker

Otto Skorzeny posted:

Carmack actually gave up some performance to unify light and shadows in the Doom 3 engine in a way he thought was elegant (and probably does fit with most people's naive mental model pretty well). This being said, Carmack's C was never very good looking and I doubt his C++ is much better. The code to the HL2 engine (called 'Source' for reasons that are comedic) got leaked years ago and is still floating around if you look, and is also very bad (unless you're looking for an example of why piecemeal growth and bolting poo poo on can be dangerous).
Thanks, and cripes that is so weird to hear. I'm still wet behind the ears; how is it possible that the source engine, something made in 2004 that I personally still think of as current gen, possibly be badly coded?

Also, thanks for the help so far, but how about just any 3D engine? I just wanna know what they look like.

tripwire
Nov 19, 2004

        ghost flow

Inverse square posted:

Thanks, and cripes that is so weird to hear. I'm still wet behind the ears; how is it possible that the source engine, something made in 2004 that I personally still think of as current gen, possibly be badly coded?

Also, thanks for the help so far, but how about just any 3D engine? I just wanna know what they look like.

Souce wasn't purpose built from scratch. If I remember correctly, it's an evolution of half life 1 code, which itself has adapted from Quakeworld source code, which was adapted from Quake source code. Theres probably more links in there that I'm not remembering.

Adbot
ADBOT LOVES YOU

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

Inverse square posted:

Thanks, and cripes that is so weird to hear. I'm still wet behind the ears; how is it possible that the source engine, something made in 2004 that I personally still think of as current gen, possibly be badly coded?

The HL2/Source engine is essentially the HL1/GoldSrc engine modified and with poo poo bolted on. The HL1/GoldSrc engine is a heavily modified version of the Quakeworld engine (which Valve licensed) with poo poo bolted on. Quakeworld is the Quake 1 engine with modified netcode and slightly different physics. So you've got a codebase from 1995 originally written in C, modified piecemeal several times, adapted to C++ and modified more, with 3rd party middleware (Havok physics) grafted in. When the code got leaked, it was found that a good bit of the Havok stuff was copy/pasted from the demo code from Havok's website, and that a fair amount of Carmack's old Quake code was recognizable after all the years.


This all being said, I should say that the code isn't horrible per se, so much as a bad example to learn from.


e: tripwire!!! :orks:

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