|
Edit 2: This question has been answered, thank you! I'm working on some PHP code and I am trying to use preg_match and substr to check the last two characters of the $listName string to see if they are R followed by a number. I wrote the following code, but it returns false: code:
What confuses me, is that the following code works and returns true, so it seems like my regular expression works, but I don't get why this code works: code:
Edit: There is something about the data being returned in the substr that it is not liking. Aniki fucked around with this message at 19:11 on Jun 6, 2011 |
# ? Jun 6, 2011 18:57 |
|
|
# ? May 15, 2024 17:17 |
Try preg_match('/R[0-9]$/', $listName)
|
|
# ? Jun 6, 2011 19:04 |
|
Zombywuf posted:I thought we were talking about the prior pdf for the position of the cow over the entire set of integers. There is no appropriate scaling factor for your function in that case. Not that it's particularly relevant, but there's a lot of work in bayesian statistics on using so-called improper priors that have infinite mass. The math works out and the statistical methods work well; the only downside is that it's a bitch to assign meaning to a distribution with infinite mass.
|
# ? Jun 6, 2011 19:08 |
|
Aniki posted:Edit: There is something about the data being returned in the substr that it is not liking. Right, because the parameters to substr are backwards. Try substr($listName, -2, 2). e: in the future echo out the return value of substr, not just the string length, to see if it is really returning what you think it is returning. e2: Seriously? e3: Oh I get it, you're using the $ regexp on the entire string instead of using substr. csammis fucked around with this message at 19:13 on Jun 6, 2011 |
# ? Jun 6, 2011 19:10 |
|
nielsm posted:Try preg_match('/R[0-9]$/', $listName) Awesome, thank you!
|
# ? Jun 6, 2011 19:10 |
|
csammis posted:Right, because the parameters to substr are backwards. Try substr($listName, -2, 2). I didn't realize that I had my parameters mixed up, but that would explain why the substr value wouldn't work when I tried running the substr through a switch. The strange thing is that I was echoing out the substr value and it was returning R2. It's possible that I was writing the substr code inconsistently, so in the future I'll store similar values to a variable, so that I can eliminate the possibility of me typing out the parameters differently. I did actually test the updated regular expression on the full string and on the substr and it worked in both instances. I'll still check to make sure that I have the substr code written correctly though.
|
# ? Jun 6, 2011 20:58 |
|
ultrafilter posted:Not that it's particularly relevant, but there's a lot of work in bayesian statistics on using so-called improper priors that have infinite mass. The math works out and the statistical methods work well; the only downside is that it's a bitch to assign meaning to a distribution with infinite mass. Got any references for that, I need to increase my reading backlog by a few MB.
|
# ? Jun 6, 2011 21:06 |
|
Zombywuf posted:Got any references for that, I need to increase my reading backlog by a few MB. There's a little bit in Gelman's book on bayesian computing, and the theory's laid out in Hartigan's book (which you'll have to find in a library--it's pretty badly out of print). Other than that, it's spread out across the objective bayesian literature, and I don't really know where to start there.
|
# ? Jun 6, 2011 21:21 |
|
Is there a good alternative to phpMyAdmin that works with very large mySQL databases? I've always used phpMyAdmin but am currently working on a database with ~300 million records totaling about 13gb of data. phpMyAdmin works only sporadically - I can view the table layouts but it chokes if I try to browse the data or alter the tables. It immediately dumps me back to the main phpMyAdmin page. I don't believe it is a database problem since the console responds perfectly fine and is very quick. Alternatively, are there settings to tweak in phpMyAdmin that I should look into? I've tried googling for help but every problem is related to importing large databases into phpMyAdmin, not the software choking while the database is already loaded.
|
# ? Jun 7, 2011 00:12 |
|
I'm not sure if this is exactly the right place to ask this, but here it goes: Is there any sort of program available to turn some of the more popular threads here into a sort of live chat or live blog style, with automatic updating every time someone posts something new? This is more intended for event threads, where posts multiple posts come in a short span of time. Really I want something that auto-refreshes/keeps the newest posts on the top/no page switching. Thanks!
|
# ? Jun 7, 2011 13:56 |
|
EPCOT posted:Is there any sort of program available to turn some of the more popular threads here into a sort of live chat or live blog style, with automatic updating every time someone posts something new? This is more intended for event threads, where posts multiple posts come in a short span of time. Really I want something that auto-refreshes/keeps the newest posts on the top/no page switching. No such exact software exists because it would have to be tied directly into the forums software, but you can use a polling program like ReloadEvery (Firefox) set to short intervals to catch updates near real-time. Making the posts appear newest first (unless there's a forum option I am unaware of) would need some custom code.
|
# ? Jun 7, 2011 14:16 |
|
A more pertinent question may be: "How tolerant is SA of bots scraping the forums?"
|
# ? Jun 7, 2011 20:28 |
|
baquerd posted:Making the posts appear newest first (unless there's a forum option I am unaware of) would need some custom code. The forum option you're looking for is "the reply screen".
|
# ? Jun 8, 2011 00:56 |
|
I have a folder with 1600 PDF files. I need to figure out a simple way to feed a list of names into something that will search through this folder and copy any files that have a file name that starts with these names. The file names are setup with a Last Name First Name then more info but the first name and last name are the only unique part of the file name for all the files. Is there an easy way to do this in just a batch file or something? I'm no programmer so I don't really have access to any tools.
|
# ? Jun 9, 2011 13:32 |
|
Raymn posted:I have a folder with 1600 PDF files. I need to figure out a simple way to feed a list of names into something that will search through this folder and copy any files that have a file name that starts with these names. The file names are setup with a Last Name First Name then more info but the first name and last name are the only unique part of the file name for all the files. Is there an easy way to do this in just a batch file or something? I'm no programmer so I don't really have access to any tools. What OS are you on? Are they nested or just all in the folder itself? On Unix/Linux/MacOS X you could do something like (in Terminal.app, first type "cd" and drag the starting folder into the window and hit enter): code:
|
# ? Jun 9, 2011 17:50 |
|
Carthag posted:What OS are you on? Are they nested or just all in the folder itself? My PC is windows but I could easily get it run through OSX tho I may have to wait a day or so which I guess makes my preference Windows. Sorry, I should have specified. They are all just in one folder. For your commands, do I need to do anything special with the list document or just have each file be its own line?
|
# ? Jun 9, 2011 18:29 |
|
Raymn posted:My PC is windows but I could easily get it run through OSX tho I may have to wait a day or so which I guess makes my preference Windows. Sorry, I should have specified. Yeah, just each one its own line, like Monroe Marilyn Doe John McCracken Phil or whatever fits the naming scheme. The above basically turns it into "Monroe Marilyn*.pdf" etc and moves whatever matches that into the filtered folder. I know you can do it with a .bat file too, but I haven't used those since around 1994 so I'm a little rusty.
|
# ? Jun 9, 2011 18:45 |
|
Carthag posted:Yeah, just each one its own line, like Not a problem! I'll see what I can do to wrangle up a OSX box today and give it a whirl. Thanks for the help.
|
# ? Jun 9, 2011 19:04 |
|
Carthag posted:What OS are you on? Are they nested or just all in the folder itself? So I tried this and nothing happened I didn't get an error but nothing got copied.
|
# ? Jun 9, 2011 21:54 |
|
Raymn posted:So I tried this and nothing happened I didn't get an error but nothing got copied. Can you post a sample of the directory contents? e.g. On the Mac, after you've typed cd and dragged the folder in and hit enter, type ls | pbcopy (that's a pipe character, shift-\ on US keyboards) then switch to your SA post and hit Paste from the Edit menu. (We don't need all of them, feel free to snip the list down to 10.)
|
# ? Jun 9, 2011 23:32 |
|
Is there a way to modify the data stream on your microphone before it's read by other applications? Imagine I want to create an autotune program that autotunes your voice for every application (skype, ventrilo, etc.). I'd need to A) get the input from the microphone and then B) write new data to that stream. There's plenty of information on doing A but I haven't been able to find anything about doing B. The closest I've seen is people having their own audio device+driver but I'd rather not travel down that path if possible. This is on Windows.
|
# ? Jun 11, 2011 10:10 |
Smugdog Millionaire posted:Is there a way to modify the data stream on your microphone before it's read by other applications? Imagine I want to create an autotune program that autotunes your voice for every application (skype, ventrilo, etc.). I'd need to A) get the input from the microphone and then B) write new data to that stream. There's plenty of information on doing A but I haven't been able to find anything about doing B. If you're okay with working only on Vista and up, I think a Audio Processing Object is what you want, it hooks directly into the audio chain. Alternatively use something like Virtual Audio Cable to feed the microphone stream into an effect application, and have the effect application play back into another virtual audio cable which you can then point your real application to. E: Okay after a bit more reading it seems that APOs can only be shipped as part of a complete audio driver package. nielsm fucked around with this message at 13:29 on Jun 11, 2011 |
|
# ? Jun 11, 2011 13:16 |
|
I have a question regarding using RSA for authentication. Right now, I'm generating a random string of bytes with a public key, sending the encrypted string, decrypting it, and sending the result back. The problem is that there's a small chance the encrypted string could be the same twice, which could result in replay attacks. Is there any way to prevent this in code?
|
# ? Jun 12, 2011 19:02 |
|
dpbjinc posted:I have a question regarding using RSA for authentication. Right now, I'm generating a random string of bytes with a public key, sending the encrypted string, decrypting it, and sending the result back. The problem is that there's a small chance the encrypted string could be the same twice, which could result in replay attacks. Is there any way to prevent this in code? That is a pretty bad way of using RSA for authentication, and replay attacks are not exactly its worst fault. Is there any reason you aren't using a standard protocol like signed Diffie-Hellman?
|
# ? Jun 12, 2011 19:22 |
|
dpbjinc posted:I have a question regarding using RSA for authentication.
|
# ? Jun 12, 2011 21:41 |
|
dpbjinc posted:I have a question regarding using RSA for authentication. Right now, I'm generating a random string of bytes with a public key, sending the encrypted string, decrypting it, and sending the result back. The problem is that there's a small chance the encrypted string could be the same twice, which could result in replay attacks. Is there any way to prevent this in code? I don't quite get how the thing you just described is a form of authentication. Let me see if I got this straight. 1. Alice generates a random string S of bytes, using a secure random number generator. 2. Alice encrypts the string with Bob's public key BobKey.pub, producing the value E(BobKey.pub, S) 3. Alice sends E(BobKey.pub, S) to Bob. 4. Bob decrypts it using the private key only he knows, producing D(BobKey.priv, E(BobKey.pub, S)). 5. Bob sends D(BobKey.priv, E(BobKey.pub, S)) back to Alice. 6. Alice checks that the result equals S, and now... Bob? is authenticated? Is that right? How is this supposed to ensure to Alice that any future messages she sends will be received by Bob?
|
# ? Jun 13, 2011 00:18 |
|
shrughes posted:I don't quite get how the thing you just described is a form of authentication. Let me see if I got this straight. Technically, it proves that Bob has access to an oracle that itself has access to BobKey.priv, by demanding that Bob act as such an oracle for Alice. Which is a very shallow authentication statement, but slightly different than zero information -- in some cases something similar might be used as part of a proof that BobKey.priv exists or is compromised, either of which may be formal statements in some high-level protocol. It's certainly not what any serious cryptographer would claim as a working authentication protocol, but I can sort of see how an amateur might stumble onto it; as written, this protocol is essentially "Bob gives his private key to anyone who asks. Anyone who can credibly claim to have either stolen this key or be capable of talking to Bob or anyone who has stolen his key will be authenticated as Bob". This is why programmers shouldn't be allowed to write their own cryptographic protocols.
|
# ? Jun 13, 2011 03:45 |
|
ShoulderDaemon posted:That is a pretty bad way of using RSA for authentication, and replay attacks are not exactly its worst fault. Is there any reason you aren't using a standard protocol like signed Diffie-Hellman? It looks like my server has GPG, though. I'll try using that instead. Edit: Apparently I have to have a dedicated IP address to use SSL. That's not that expensive. Also, I'm bad at the Internet. ShoulderDaemon posted:This is why programmers shouldn't be allowed to write their own cryptographic protocols. Yeah, I'm pretty bad at designing applications but great at coding them when I'm given a design. I wasn't intending for the system to guard corporate secrets or financial information, though, just to prevent random guys on the Internet from downloading large multimedia files I have on the server. Double Punctuation fucked around with this message at 04:20 on Jun 13, 2011 |
# ? Jun 13, 2011 03:53 |
|
dpbjinc posted:Yeah, I'm pretty bad at designing applications but great at coding them when I'm given a design. I wasn't intending for the system to guard corporate secrets or financial information, though, just to prevent random guys on the Internet from downloading large multimedia files I have on the server. Figure out how to use a self-signed certificate, dammit. Then have people connect and authenticate by providing a password. That's easier than programming your own thing. Of course, this only works if you give people a copy of the certificate, it's meaningless if you just expect them to click "Trust this certificate." Or forgo the SSL and just have them provide a password, if these are just copyrighted movies or something and it's not a big deal if some man-in-the-middle hacker downloads it other than bandwidth costs. dpbjinc posted:Yeah, I'm pretty bad at designing applications but great at coding them when I'm given a design. Suppose I told you that logged in users were recognized because they had a username and a 16-byte hexadecimal cookie string in their cookie. Given an in-memory Dictionary<string, string> of users and their cookie values, can you write a function that looks up the user and makes sure he has the right cookie? Here's the signature: code:
shrughes fucked around with this message at 04:54 on Jun 13, 2011 |
# ? Jun 13, 2011 04:46 |
|
code:
"[some object]" would be changed to the object the threads are locking on. Obviously, the lock isn't needed if it's impossible for the application to write to cookieDict and call this method at the same time.
|
# ? Jun 13, 2011 06:46 |
|
I've been working on Project Euler problems and after seeing all of the recurring themes only ~30 problems in I've decided that I want to create one program to solve them all. I'm having trouble coming up with a good way to organize the code to run each problem. My plan was to create a new class for each problem, with common functions organized into their own classes (fractals, primes, etc). When the user user enters a problem number it would call the function in the appropriate class, but it seems a bit ridiculous to just have 300+ if statements depending on which problem number they enter. I'm doing this in C#. Is there a better way I should organize my code?
|
# ? Jun 14, 2011 04:18 |
Aredna posted:When the user user enters a problem number it would call the function in the appropriate class, but it seems a bit ridiculous to just have 300+ if statements depending on which problem number they enter. I'm doing this in C#. Is there a better way I should organize my code? The Abstract Factory pattern would probably be the standard generalised solution.
|
|
# ? Jun 14, 2011 04:50 |
|
nielsm posted:The Abstract Factory pattern would probably be the standard generalised solution.
|
# ? Jun 14, 2011 05:08 |
Orzo posted:That solves absolutely nothing in this case. Honestly, having a gigantic switch statement in this case is the simplest and cleanest way. True. The choice is between a huge switch or a huge initialiser for a list of factories. The switch is probably less code.
|
|
# ? Jun 14, 2011 06:41 |
|
Just make sure all your problem classes are named something like Problem23, obey some common interface, and have a no-argument constructor. Then you can use reflection, like this:code:
|
# ? Jun 14, 2011 06:46 |
|
What the gently caress is this poo poo, just have a goddamned array of function pointers.
|
# ? Jun 14, 2011 06:48 |
|
Let the linker build the lookup table for you:code:
|
# ? Jun 14, 2011 07:36 |
|
He's using C#, so he'll need to wrap all that with some platform invoke.
|
# ? Jun 14, 2011 08:09 |
|
Honestly, I'd just use a collection of delegates.code:
|
# ? Jun 14, 2011 13:20 |
|
|
# ? May 15, 2024 17:17 |
|
shrughes posted:What the gently caress is this poo poo, just have a goddamned array of function pointers. Depressing isn't it? This is what Java actually believes.
|
# ? Jun 15, 2011 17:24 |