|
JawnV6 posted:Hate conditional logic? Smuggle the decisionmaking through flow control instead! All of my source files start with a macro to inline branch-if-equals
|
# ? Nov 19, 2015 19:59 |
|
|
# ? May 31, 2024 12:05 |
|
JawnV6 posted:Hate conditional logic? Smuggle the decisionmaking through flow control instead! Yeah, unless specifically asked for a recursive, general-for-all-N solution I don't think I would ever produce the recursive formulation of this problem. It's vastly simpler to just write out the conditionals. There's a bunch of nontrivial cases in the small sets, and it's much harder to verify that it really does work in the constrained number of experiments allowed.
|
# ? Nov 19, 2015 20:02 |
|
This is cool, and the principle seems totally reasonable to me, just not the effort spent in formalizing it in non-general cases. (Which you agree with.) But my Haskell isn't good enough - can this determine the direction of the mid-weighted coin in the given number of experiments? That's part of the original problem. (Obviously it's just one more experiment, so the big-O complexity doesn't change.) LeftistMuslimObama posted:It involves a bunch of return statements instead. I didn't say no conditional logic, just fewer if statements. I also didn't think about it too hard so I'm probably missing a corner case in there. how do you figure out which return statement executes
|
# ? Nov 19, 2015 20:20 |
|
Full disclosure, I'm probably just a little overobsessed with writing recursive answers to everything because it tickles my nerdzones. I spend all day staring at languages where recursion is basically impossible so it's my default first thing to try when handed trivial problems outside the context of work. I don't think we use that particular question in our interviews, and now that I've actually given it more than 5 seconds thought I agree that specific problem is maybe not great. I was more reacting to the general notion that trivial problems mean the interview is bad. I think they can have value in guiding the interview.
|
# ? Nov 19, 2015 20:23 |
|
I'm real confused about this "thicket" of conditional logic.code:
|
# ? Nov 19, 2015 20:24 |
|
GrumpyDoctor posted:But my Haskell isn't good enough - can this determine the direction of the mid-weighted coin in the given number of experiments? That's part of the original problem. (Obviously it's just one more experiment, so the big-O complexity doesn't change.) My algorithm doesn't attempt to determine that information. It's sort of conflated; on some paths it will have performed the right experiment to learn that information, but in other paths it won't and would need an additional experiment. Edit: To be more specific, you would probably elect to extract that information post-facto; once you know the identity of the mis-weighted coin, you look through past experiments to find any experiment which involved that coin. That experiment will tell you the direction of the weight difference. It's possible with 6 coins to get an answer without ever actually weighing the mis-weighted coin (e.g. sets [1,2] and [3,4] are equal, coins 1 and 5 are equal, mis-weighted coin must be 6 which has never been weighed) but I think without examining that too closely that you will always have a "left over" experiment available that you can use. I'm not really interested in rewriting my algorithm to verify that, though. ShoulderDaemon fucked around with this message at 20:41 on Nov 19, 2015 |
# ? Nov 19, 2015 20:36 |
|
sarehu posted:I'm real confused about this "thicket" of conditional logic. Clear, intuitive, and complete code, shrughes-style.
|
# ? Nov 19, 2015 20:53 |
|
sarehu posted:I'm real confused about this "thicket" of conditional logic. Too terse. Let me clean it up a little: code:
|
# ? Nov 19, 2015 20:57 |
|
I guess we didn't really need any conditions.code:
code:
code:
sarehu fucked around with this message at 00:20 on Nov 20, 2015 |
# ? Nov 19, 2015 22:43 |
|
Now instead of only satisfying the problem requirements if the fake coin is in one of the last two positions, it never satisfies them. Hooray for consistency!
|
# ? Nov 19, 2015 23:41 |
|
Man, if one of my coworkers used code like that in real life I would punch them so hard. I mean, code golf is a thing, sure, I just wouldn't want to see it used in an interview.
|
# ? Nov 20, 2015 00:04 |
|
GrumpyDoctor posted:Clear, intuitive, and complete code, shrughes-style. First you pick the pair, of (0,1), (2,3), or (4,5) that has the bad coin, in two comparisons. Then you use one more to see if the even number is the bad one. How is that bad?
|
# ? Nov 20, 2015 00:22 |
|
sarehu posted:First you pick the pair, of (0,1), (2,3), or (4,5) that has the bad coin, in two comparisons. Then you use one more to see if the even number is the bad one.
|
# ? Nov 20, 2015 00:35 |
|
6 coins in 3 weighings is easy-mode anyway. If you want to have to actually think about it, try 12 coins. (In theory, you have enough information for 13, but you'd need something extra in order to extract maximum information out of the very first weighing.)
|
# ? Nov 20, 2015 01:12 |
|
I've just started processing, and I'm trying to write software which will sort the data output from the serial of an Arduino. Currently the arduino's output looks like this:code:
code:
code:
edit: I've also checked if any commands are deleting the outputs before they can be drawn in the program, but this doesn't seem to be the case. edit 2: here's the full code just in case i'm missing crucial information: http://pastebin.com/eiCBPgG2 Rockybar fucked around with this message at 02:20 on Nov 20, 2015 |
# ? Nov 20, 2015 02:15 |
|
Sex Bumbo posted:"no I'm not answering this dumb question" I've done that (sort of). I got a string processing interview question with the instructions to write a function to solve it like I would for real production code. I said I'd use a couple regular expression substitutions, but I don't remember what the syntax is for the regex library in this language, and in real life I'd google it. Interviewer said that's fine what are the substitutions you'd do? Got the job.
|
# ? Nov 20, 2015 03:10 |
|
Rockybar posted:I've just started processing, and I'm trying to write software which will sort the data output from the serial of an Arduino. Currently the arduino's output looks like this: Any reason you can't just read the additional expected input immediately? code:
|
# ? Nov 20, 2015 03:34 |
|
Volmarias posted:Any reason you can't just read the additional expected input immediately? I could but the issue is once I've cleared up my code a bit I don't think it would work, because it will reach a point where they might be 10 Heart rate outputs before a compass one i.e.e [HR, 70, 60, 65, 54, 70, COMPASS, 98, HR, 20, 52...]. And I'd also like to add new modes quite easily. And I'm still not sure why my code isn't working correctly, is it an issue reading the val output? edit: I really feel it has to be something to do with the if (val.equals("COMPASS")), is it because of the new line? Rockybar fucked around with this message at 11:37 on Nov 20, 2015 |
# ? Nov 20, 2015 11:18 |
|
Rockybar posted:I could but the issue is once I've cleared up my code a bit I don't think it would work, because it will reach a point where they might be 10 Heart rate outputs before a compass one i.e.e [HR, 70, 60, 65, 54, 70, COMPASS, 98, HR, 20, 52...]. And I'd also like to add new modes quite easily. And I'm still not sure why my code isn't working correctly, is it an issue reading the val output? OK, that wasn't clear because your sample input had each type only emitting a value once. Assuming that you cannot for some reason change the arduino firmware to work that way, since that would likely simplify both the code on the arduino and the java client, you probably do have to do something like what you had. The documentation for readStringUntil isn't very clear. But, looking at the source, that calls readBytesUntil, whose doc states "Reads from the port into a buffer of bytes up to and including a particular character." That means that you need to compare against "HR\n" and "Compass\n". When in doubt, use the debugger to see what input you're actually getting.
|
# ? Nov 20, 2015 16:06 |
|
Volmarias posted:OK, that wasn't clear because your sample input had each type only emitting a value once. Assuming that you cannot for some reason change the arduino firmware to work that way, since that would likely simplify both the code on the arduino and the java client, you probably do have to do something like what you had. Sorry should have been clearer about that. This is really baffling me because with the if (val != null) {} statement, which I can confirm is working, not even a statement like code:
code:
code:
|
# ? Nov 20, 2015 19:07 |
|
Rockybar posted:
Dunno if this is just a typo or not, but your backslash is a frontslash here.
|
# ? Nov 20, 2015 19:11 |
|
TooMuchAbstraction posted:Dunno if this is just a typo or not, but your backslash is a frontslash here. Cheers, changed it but didn't seem to fix it.
|
# ? Nov 20, 2015 20:00 |
|
Have you considered looking at what input you're getting? Processing's IDE should have a debugger. At worst, put it into your text(...) calls to see what you're getting.
|
# ? Nov 20, 2015 21:19 |
|
Volmarias posted:Have you considered looking at what input you're getting? Processing's IDE should have a debugger. At worst, put it into your text(...) calls to see what you're getting. I've tried that, just doing text(val, 100,100); in the normal loop, without modifying it, and it comes through fine, flashing up the value every refresh, as one would expect on the serial monitor, just shows COMPASS, or HR, or some reading on its own. edit: about to go to sleep but in the morning I think I will try something like declaring a string = COMPASS, and then testing that against my if statements, to see if the equator is even working Rockybar fucked around with this message at 01:31 on Nov 21, 2015 |
# ? Nov 21, 2015 01:25 |
|
Not sure if this is the right place, but, here goes (tl;dr I want to run automated reports but have no clue where to begin): I work in widget sales, and the first part of each morning I have to update our widget progress to the team, via excel spreadsheets that are emailed. The basic process is: Open Excel template Open query in <some crappy, proprietary database view> Copy results to clipboard, paste into an Excel tab. Repeat for 15-20 queries. I wrote a python script where I can do this automatically, so I come into work, double click and then go make a coffee or whatever. The database access we get is so lame, the python code is pretty much keystrokes to get to the saved queries in folders, switch to excel, advance tabs, etc; I can't really get to it in any useful way other than having this db viewer program and excel. But the next step I want to take is to be able to just run this at 5am or whatever, but I'm not really sure from where. Ideas are to leave my work laptop at work, always on, and have some timed execution. Or from home and vpn in.. but shouldn't there be some way I can run a version of this crappy db viewer and excel in the cloud, vpn into my work network, and then access the results in the morning? If someone could point me in the direction of an answer, it would be greatly appreciated -- my specific widget business is not really a tech savvy one, so there's not much support available for the kinds of things I am trying to do here.
|
# ? Nov 23, 2015 08:39 |
|
Turkeybone posted:Not sure if this is the right place, but, here goes (tl;dr I want to run automated reports but have no clue where to begin): To run your script automatically, you want the Windows Task Scheduler http://blogs.esri.com/esri/arcgis/2013/07/30/scheduling-a-scrip/ You can even configure the job to wake up the machine at 5 to run - it's just a check box you can click. Not sure about automating your VPN access. The setup for a dedicated machine to run it depends a lot on your IT department and how paranoid they are, but the easy/simple way would be an old machine sitting in a corner in the office. You could also set up an AWS instance to do it if you wanted, but I don't have an article to link to about that.
|
# ? Nov 23, 2015 15:38 |
|
Perfect, thanks -- yeah I am a little remiss in asking my IT department about it (they were really.. weird.. when I asked them about GPS coords for our customer base (widget delivery is also part of our world)), so I'll try leaving my work laptop here a few nights to get it going, then look into some AWS (it's a small enough widget operation that I could probably do the majority of it for free).
|
# ? Nov 23, 2015 16:09 |
|
I'd recommend against using AWS to connect to your internal database systems. Either you'll have to set up VPN from there, run plaintext data over the internet, or otherwise poke holes in your network. I can't imagine IT being particularly happy if they find out. Our organization has our own cloud infrastructure that we can use for stuff like this, but since you probably don't have that, you could also run the process in a virtual machine - this won't help with the scheduling (at least on its own - maybe you could get IT to host it on an existing sever), obviously, but this way you could run it without the script interfering with your work or vice versa.
|
# ? Nov 23, 2015 17:30 |
|
So that's the thing, I wouldn't connect directly as in able to make changes -- I only can view using my cruddy viewer. So I guess I am thinking (maybe incorrectly so) that I need a machine with excel and my database viewer, and the choices are either my work laptop, my home desktop (via vpn), an IT server, or an Amazon AWS thing (again with vpn). edit: looks like there is a means to automate turning on/off vpn connections as well, so that's progress: http://serverfault.com/questions/163772/how-to-automate-turning-on-off-windows-vpn-connection Turkeybone fucked around with this message at 17:47 on Nov 23, 2015 |
# ? Nov 23, 2015 17:43 |
I have been editing some javascript code that's very efficient but hard to understand. Basically it takes a nested json and with recursion it transforms it into a matrix of objects and arrays to make it easier to transform into an html table. I work mostly in angular and other javascript libraries but this feels lower level, computer scienciesh I guess? How can I get to the level where that kind of code is natural to me? What should I read?
|
|
# ? Nov 23, 2015 19:27 |
|
gmq posted:I have been editing some javascript code that's very efficient but hard to understand. Basically it takes a nested json and with recursion it transforms it into a matrix of objects and arrays to make it easier to transform into an html table. There's no book to read that will make such things natural to you, you just need to work with code at that level for awhile.
|
# ? Nov 23, 2015 19:33 |
|
gmq posted:I have been editing some javascript code that's very efficient but hard to understand. Basically it takes a nested json and with recursion it transforms it into a matrix of objects and arrays to make it easier to transform into an html table. Start with a naive solution that you can get to work, then account for edge cases, then find places you can optimize.
|
# ? Nov 24, 2015 12:51 |
|
mysql/php/encryption advice needed! I'm using mcrypt_encrypt to store base64 values in a db's table. I'm setting up a scheme where I have encrypted values on one database's table, and on another server's database I have a table their IV's. Every row of the encrypted values have a corresponding IV. When this is finalized, I'm going to store the IV's in a vault. Is this a good scheme? For testing purposes I'm using one database with the encrypted values and IV's to start off with. In their simplest form, this is what both tables look like. I'll call them A and B. Table A: ID | encrypted value Table B: ID | IV ID on table A is associated with ID on table B. Say if the encrypted values on table A were states, and I wanted to select all states that equal 'Maine', how would I get the decrypted values at the same time as doing the SELECT and having a WHERE? Someone suggested it's going to be a JOIN like this: code:
I also thought this would have something to do with AES_DECRYPT. I'm using MCRYPT_CAST_256 and MCRYPT_MODE_CBC with mcrypt_encrypt. LP0 ON FIRE fucked around with this message at 17:13 on Nov 24, 2015 |
# ? Nov 24, 2015 16:58 |
|
LP0 ON FIRE posted:mysql/php/encryption advice needed! I'm going to be brutally honest. You're obviously confused, and speaking as a professional who works with crypto, I strongly get the impression that you have no idea what you're doing. If this is a personal project, that's fine, and I can give you some advice on how to experiment and start to get a handle on this stuff. This advice probably won't involve solving your current problem, because I think you need to experiment with something simpler to begin with, and frankly your problem is crazy and doesn't seem like it makes sense, on a fundamental level. If this is a professional project, then I suspect you are way beyond your expertise and need to just hire a contractor who knows this stuff. You won't get it right by yourself. I'm not trying to be hurtful here, but there's a lot of fiddly little details involved in this sort of thing that without the right experience you're incredibly likely to get wrong and never notice until someone is suing your company or stealing all your customers' credit cards. If you're in the Pacific Northwest, I can give you some recommendations of contractors who will help you. If you're not, then someone else here can probably point you to a reliable contractor.
|
# ? Nov 24, 2015 17:54 |
|
No I want to do it so I can learn. We're not storing credit cards, and everything is either hashed or has reversible encryption.
|
# ? Nov 24, 2015 18:09 |
|
LP0 ON FIRE posted:No I want to do it so I can learn. We're not storing credit cards, and everything is either hashed or has reversible encryption.
|
# ? Nov 24, 2015 19:07 |
|
Trapick posted:Are you storing anything people would be angry about being public? Hint: yes you are. Email addresses, passwords, phone numbers, names, none of that do you want leaked and on your head if you get this wrong. I don't want to take "safe risks", but all that information is individually encrypted, and the IVs will be stored on a separate server.
|
# ? Nov 24, 2015 19:12 |
|
Hey, we're talking encryption and security! That's awesome. I want to implement a basic client/server API to allow our client programs to send notifications to the server. The only big trick here is that only authorized clients should be able to use this service, and the details of the information they're sending should be kept private (i.e. not sent in the clear). First off, I'm happy to use existing solutions so long as they're secure and open-source compatible; any recommendations? Failing that, here's the sketch of my design: Clients that are authorized are provided with a client ID and a client private key, which they plug into their versions of the program. Server-side: we expose an HTTP server that accepts three types of requests: 1) HTTP GET request for the server's public key ("Key Request"). 2) HTTP GET request to request an authentication challenge ("Challenge"). This request will return a random string encrypted with the client's public key. 3) HTTP POST request to send a new notification ("Notification"). This request contains the following information: - The decrypted random string from a Challenge request (usable once only, and only within a short time window) - JSON string describing the notification, encrypted with the server's public key All requests also include the client ID; we can revoke client IDs/keys if necessary by updating a table on the server side. We can also update the server's public/private keys at any time since each interaction with the server should involve first getting the new key -- it's not embedded into the client program anywhere. The notification process should be fairly obvious from this: request the server's public key, request a challenge token, decrypt the token with the client's private key, encrypt the notification data with the server's public key, send both to the server. The server verifies the token matches what it encrypted and that the client is authorized, and if so, decrypts the notification data and takes appropriate action based on what it finds there. As far as I can tell, the client's information should remain private so long as they keep their private key, well, private -- which is down to proper operational security on their computers and is not something I think I should be particularly worried about. This seems fairly straightforward, but I'm worried that I'm the guy going "computer security is easy! " while walking off a cliff into oceans full of Screaming Eels. So, uh, sanity check please?
|
# ? Nov 24, 2015 20:02 |
TooMuchAbstraction posted:Hey, we're talking encryption and security! That's awesome. I want to implement a basic client/server API to allow our client programs to send notifications to the server. The only big trick here is that only authorized clients should be able to use this service, and the details of the information they're sending should be kept private (i.e. not sent in the clear). If you have control over implementation of client and server, just go with proper TLS and verify the signatures of certificates on both ends. Client connects to server, gets server's cert and public key, verifies it is valid. Client sends its own cert to server, server can verify identity of the client and authenticate it from this. All of that built into the standard protocol.
|
|
# ? Nov 24, 2015 20:13 |
|
|
# ? May 31, 2024 12:05 |
|
TooMuchAbstraction posted:This seems fairly straightforward, but I'm worried that I'm the guy going "computer security is easy! " while walking off a cliff into oceans full of Screaming Eels. So, uh, sanity check please? The only thing I'd be worried about is added complexity over just a simple setup with HTTPS and Basic auth. HTTPS handles channel encryption and protection from MITM, while Basic auth allows you to validate that the client is authorized. This seems to satisfy your requirements and is a lot simpler to implement. e:f,b
|
# ? Nov 24, 2015 20:13 |