Maybe it's because I haven't slept much but I'm struggling with the solution to a simple concept. For context I'm using python but this solution is bound to be super simple and probably cross-applicable to any language, my brain is just broken. I have two arrays/lists/collections of data: The first array is a series of values whose order is important. The second contains numbers that correspond to positions in the first array. code:
If a value's position exists in the array positions, it means that value can be nullified when outputting the contents of the first array values. E.g. these are all the valid possible outputs of values according to positions: code:
code:
Does that make sense? Sulla Faex fucked around with this message at 09:44 on Jun 26, 2014 |
|
# ? Jun 26, 2014 09:35 |
|
|
# ? May 22, 2024 08:54 |
|
Sulla-Marius 88 posted:If a value's position exists in the array positions, it means that value can be nullified when outputting the contents of the first array values. E.g. these are all the valid possible outputs of values according to positions: If I'm understanding you correctly, you want something like this: Python code:
Another advantage of this solution is that it evaluates everything lazily, so if you only need the first N values from subtracted then you don't have to load the rest into memory, or even calculate them.
|
# ? Jun 26, 2014 10:08 |
LOOK I AM A TURTLE posted:If I'm understanding you correctly, you want something like this: That is exactly, 100% what I was looking for, thank you. The order of subtracted's results isn't important. I had found itertools permutable but was thrown off course because that was just a different way of shuffling the order rather than toggling the different options. Perfect! Thank you
|
|
# ? Jun 26, 2014 11:09 |
|
Your problem is pretty similar to the one of computing power sets in general.code:
If the set of positions includes all the positions, you've written a powerset function.
|
# ? Jun 26, 2014 14:38 |
|
If I have more than one version of Java installed can I specify the version I want to kick a program off with via batch file, or do I have to change my environment variable? If I have to change the environment path will the programs that are currently using the other version stop working? I'm thinking no but wanted to make sure.
|
# ? Jun 26, 2014 16:41 |
|
I'm trying to learn XSL in a hurry and not in a good way. Say I have input xml: code:
like: code:
code:
code:
|
# ? Jun 26, 2014 16:54 |
|
pr0k posted:I'm trying to learn XSL in a hurry and not in a good way. You want to ignore critical time zone information?
|
# ? Jun 26, 2014 16:59 |
|
Sulla-Marius 88 posted:Maybe it's because I haven't slept much but I'm struggling with the solution to a simple concept. For context I'm using python but this solution is bound to be super simple and probably cross-applicable to any language, my brain is just broken. As a general loop algorithm (so you're not generating a stack of lists to iterate over), couldn't you take advantage of the fact that combinations of either/or variables can be written pre:O O O O O X O X O O X X X O O X O X X X O X X X pre:i /4 /2 /1 0| 0 0 0 1| 0 0 1 2| 0 1 2 3| 0 1 3 4| 1 2 4 5| 1 2 5 6| 1 3 6 7| 1 3 7 pre:i /4 /2 /1 0| 0 0 0 1| 0 0 1 2| 0 1 0 3| 0 1 1 4| 1 0 0 5| 1 0 1 6| 1 1 0 7| 1 1 1 code:
|
# ? Jun 26, 2014 17:48 |
|
TheEffect posted:If I have more than one version of Java installed can I specify the version I want to kick a program off with via batch file, or do I have to change my environment variable? If I have to change the environment path will the programs that are currently using the other version stop working? I'm thinking no but wanted to make sure.
|
# ? Jun 26, 2014 18:40 |
|
I would like to package a C library as a Python module (it already includes low-level Python bindings but I have made a high-level interface). I have already done all the coding, testing, etc, now I just need to figure out the packaging. I'm posting here because my question has mostly to do with make and I'm not sure what the best practices are, but if this should go in the Python thread let me know. The instructions for installing this library involve editing makefiles to uncomment lines specifying architecture and options then running make in four different places, and finally in the last directory (the included low-level Python bindings) also running make install. This is not the correct way to do things, right? And it seems it creates problems to automate it as part of my package's installation. Another wrinkle is that the library uses a server-client architecture (generally all running on the same machine) so there are a couple extra steps. Currently I have a shell script that does the following:
What I would like to do is automate the above so that installing my library also installs the C library if it is not already installed. But I'm not sure how to go about this. Should I...
I'm clearly pretty clueless about how to package this for other people. My own shell script is basically just a documentation of the steps I took that eventually worked, and in places makes significant changes to makefiles. Even if you don't have answers to my specific situation, maybe something to read on best practices would be helpful. This is basically the first time poking my head out of the scientific Python world and into C and make. Edit to include specifics: The original C library: http://www.cs.unc.edu/Research/vrpn/index.html My shell script: https://gist.github.com/hsharrison/24cbe284bd50973052ee SurgicalOntologist fucked around with this message at 19:07 on Jun 26, 2014 |
# ? Jun 26, 2014 18:58 |
|
Sedro posted:Environment variables are scoped to the process, so you can set your PATH or JAVA_HOME at the beginning of your script without impacting the rest of the system. Or you could just call java with an absolute path e.g. "C:\Program Files\Java\jdk1.8.0_05\bin\java.exe" -jar app.jar Thanks! It seems to be showing both versions when I do a version check now, witht he version I want being labeled as a "HotSpot"? Is that correct? - java version "1.6.0_20" Java(TM) SE Runtime Environment (build 1.6.0_20-b02) Java HotSpot(TM) Client VM (build 16.3-b01, mixed mode, sharing) ConComMon v.1.11.2 - TheEffect fucked around with this message at 19:39 on Jun 26, 2014 |
# ? Jun 26, 2014 19:24 |
TheEffect posted:Thanks! It seems to be showing both versions when I do a version check now, witht he version I want being labeled as a "HotSpot"? Is that correct? Screenshot- You can copy/paste from the terminal by clicking the icon in the top left corner and going to Edit->Mark. Then use your mouse to highlight what you want to copy, and then right click. Now you can paste it somewhere. Also, use http://imgur.com/ for posting images on the forums
|
|
# ? Jun 26, 2014 19:29 |
|
Is there a better book for learning about algorithms than Skiena? I don't think I'm quite at the level that Skiena expects me to be. At least, most of the exercises completely escape me.
|
# ? Jun 26, 2014 19:32 |
|
fletcher posted:You can copy/paste from the terminal by clicking the icon in the top left corner and going to Edit->Mark. Then use your mouse to highlight what you want to copy, and then right click. Now you can paste it somewhere. Oops, thank you. Fixed. Here's what I was talking about- code:
code:
TheEffect fucked around with this message at 20:01 on Jun 26, 2014 |
# ? Jun 26, 2014 19:41 |
|
The version number on the first line is your version, ignore the rest
|
# ? Jun 26, 2014 20:09 |
|
But is that the version that is being run in the current console instance? Because in that example I specifically chose the directory where I have 6u13.
|
# ? Jun 26, 2014 20:22 |
|
No, it's not right. It should say 1.6.0_13 if you're running Update 13. HotSpot is the name of the specific Java Virtual Machine that will be interpreting the byte code, not the version of the Java runtime environment (which includes much more than just the VM; yeah, I know it's a bit confusing.) What sort of folders do you have in C:\Program Files*\Java? Here's what mine looks like with multiple JREs and JDKs installed to the default location, maybe what you want is in here? (I'm not on windows now but that's on my windows drive)
|
# ? Jun 26, 2014 20:38 |
|
carry on then posted:What sort of folders do you have in C:\Program Files*\Java? Here's what mine looks like with multiple JREs and JDKs installed to the default location, maybe what you want is in here? In this instance the older version of Java was installed to its own directory, "C:\Program Files\JavaTest" and it only has a directory named "jre6" in it. My script points to "C:\Program Files\JavaTest\jre6\bin\java.exe". Not sure what's wrong. Edit- If it matters, my "actual" Java directory has two directories inside of it. "jdk1.6.0_20" and "jre6". They seem to have been installed back in 2010 according to the date modified. 6u13 was just installed yesterday to its own directory. Editx2- Figured it out by checking the "javacpl.exe" in the new directory. Looks like my counterpart installed the same version, 6u20, and not 6u13. He told me it was because it wouldn't let him install an older version so he just copied the files over from his machine, and he must've copied his 6_20 install. Confused me because the console kept saying 6u13 for that "HotSpot" thing and I kept wondering where it could have gotten that from other than the fact that (I assumed) 6u13 was installed. I think I have it now. Thanks everyone! TheEffect fucked around with this message at 21:56 on Jun 26, 2014 |
# ? Jun 26, 2014 21:21 |
|
resolved
DholmbladRU fucked around with this message at 22:22 on Jun 26, 2014 |
# ? Jun 26, 2014 22:05 |
|
TheEffect posted:In this instance the older version of Java was installed to its own directory, "C:\Program Files\JavaTest" and it only has a directory named "jre6" in it. My script points to "C:\Program Files\JavaTest\jre6\bin\java.exe". I think you should read it closer, because it's saying 16.3-b01 which isn't the same at all. But good that you figured it out.
|
# ? Jun 26, 2014 22:48 |
|
A link to web page with technical interview questions was posted in the Interview help thread. This question kind of confused me, maybe someone can explain it.quote:Implement an arraylist. Need constant time for adding and removing elements.
|
# ? Jun 26, 2014 23:32 |
|
Kenishi posted:Can you actually create an ArrayList that can do add/remove in O(k)? If you don't need to preserve the order of elements in the list: To remove the ith element, first swap it with the last element, then shrink the array by 1. On an array with O(1) access times, these are both O(1) operations.
|
# ? Jun 26, 2014 23:45 |
|
Kenishi posted:A link to web page with technical interview questions was posted in the Interview help thread. This question kind of confused me, maybe someone can explain it. You should look into amortized analysis, specifically for dynamic arrays (i.e. arraylists): http://en.wikipedia.org/wiki/Dynamic_array#Geometric_expansion_and_amortized_cost. As a somewhat simplified explanation: On the surface it may seem like Add is O(n), but if you consider the entire program as opposed to individual operations you'll see that it will only need to resize the array once for every time it adds N elements, so the constant time cost is maintained. This only holds when you add to the end of the list, and the same goes for Remove(). If we're talking about Insert(idx, item), Remove(item) or Remove(idx), I don't see how any of those can run in constant time -- amortized or otherwise.
|
# ? Jun 27, 2014 10:14 |
|
pr0k posted:I'm trying to learn XSL in a hurry and not in a good way. The issue here is that the XSLT processor has no way of distinguishing the two templates matching createdate. Both your createdate templates have the exact same priority when choosing which template to apply - see this StackOverflow question. This goes into far more detail than you probably need, but the takeaway point is this (my emphasis): W3C posted:It is an error if this leaves more than one matching template rule. An XSLT processor may signal the error; if it does not signal the error, it must recover by choosing, from amongst the matching template rules that are left, the one that occurs last in the stylesheet. I assume this is why both variables end up with the value from the time template. You could fix this by changing the priority of the two templates by adding a mode to the template and the apply-template: XML code:
|
# ? Jun 27, 2014 10:33 |
|
Aha, thank you! I saw the 'mode' suggestion somewhere, probably on SO, but I didn't grok it. Is what I am doing stupid? I have two different backend systems that create the same XML. I need at least two different flat-file outputs, one delimited, one fixed. I figured using XSL would be the way to go. I could just make perl scripts, which seems a lot neater and easier to read and follow...?
|
# ? Jun 27, 2014 14:59 |
|
Are there any Youtube channels that teach non language-specific programming topics (e.g. different paradigms) that aren't boring as hell?
|
# ? Jun 27, 2014 20:38 |
|
Anyone got any go-to references (preferably on the internet) about unit testing philosophy and approaches? I feel like there's a balance to be struck between retesting the same things (because other tests make use of those methods to test something else), and testing once-only and having every single test flame out because a key method broke. Seems like it comes down to how much you divide your code into separate test units too, and reworking some methods can make updating tests less clear and straightforward than I feel it should. Basically unit testing is great, how can I get better at it?
|
# ? Jun 28, 2014 01:07 |
|
pr0k posted:Aha, thank you! I saw the 'mode' suggestion somewhere, probably on SO, but I didn't grok it. Nothing too stupid about processing XML with a tool designed to process XML I can think of a few places at work where we use XSLT to turn XML to CSV and/or JSON (not that I'd recommend creating JSON this way). I guess it depends on how complicated the rest of the output needs to be. If you need to e.g. aggregate data then it may be easier to do it in Perl. If you're got the XSLT mostly written and working and you're happy with it then you might as well keep it. If you're much more comfortable in Perl (and if other people in your organisation are proficient too) then you could definitely use Perl. Just make sure you use a proper XML library for parsing the documents instead of writing a bunch of regexes! Personally, I'd be slightly more inclined to use another language rather than running an XSL transform for writing to a flat file. If the output was XML, I'd almost certainly do XSLT.
|
# ? Jun 28, 2014 03:42 |
|
gandlethorpe posted:Are there any Youtube channels that teach non language-specific programming topics (e.g. different paradigms) that aren't boring as hell? I've recently discovered destroyallsoftware.com, which has screencast series for $40 a season. Not free for sure, but I'm very happy with what I've seen in the first season, and you can have a look at his talks for free to get a feel for his style. 'Boundaries' is a great one. He spends a lot of time in Ruby but his work is largely applicable to more than just Ruby.
|
# ? Jun 28, 2014 10:09 |
|
baka kaba posted:Anyone got any go-to references (preferably on the internet) about unit testing philosophy and approaches? I feel like there's a balance to be struck between retesting the same things (because other tests make use of those methods to test something else), and testing once-only and having every single test flame out because a key method broke. Seems like it comes down to how much you divide your code into separate test units too, and reworking some methods can make updating tests less clear and straightforward than I feel it should. Unit testing should be just a layer in your greater testing scheme. Obviously there are people with many idea and different theories on this, but this is one way to look at it: Layer zero: Static analysis. Running your code through a static code analyzer, for example checkstyle. This step will assure that you are following whatever style standards you have configured. That is, correct indentation, no deeply nested if-structures etc. This step - with some sensible rules - could have stopped the (in)famous "goto fail" bug. Layer one: Unit testing. You are testing single units of your code. Most of the time, this means testing a single public method. Now the thing here is, you'll only want to test the one method under scrutiny. Let's take an example. You have a piece of code that gets the most recent Fart from the FartDAO and then asks the HTTPThingy to send the Fart to whatever server by HTTPThingy.send(). As this is still unit testing, you only want to test two things here: That you are correctly retrieving the latest Fart, and that the method is correctly asking HTTPThingy to send the Fart forwards. After all, we are only testing this methods, not HTTPThingy or FartDAO. HTTPThingy will have it's own tests. The best way, in my experience, to do this is via mocking and Dependency Injection. Example: code:
code:
A perfect unit test would test the method under scrutiny completely. That is, each line, each code path, each possible exception state. If you run into code you can't test, it's often a sign of either unnecessary or badly structured code. You'll probably also want to look at mutation testing. I've found PIT to be the thing I like the most. What it does is fiddle with your code and see if your tests caught the change. This is useful for determining if your tests are rigorous enough to allow for safe refactoring down the line. The purpose of unit testing is to make sure Things work correctly in isolation and independently. The independently part meaning that any of your tests shouldn't depend on a previous test. Layer two: Integration testing. Now that we've made sure that the things work correctly in isolation, it's time to make sure they work when interfacing with each other. One way to look at this is by searching for entry points: Parts where other code would initiate something. If you have a ButtFactory that gets some Farts from FartDAO and creates a new Butt, priming it with all the Farts you would need, you'd likely want to test this part at this stage. Write tests that call the ButtFactory like your other code would, and then assert that they get correctly primed Butts back. Mocking is less useful here. Most of the time you'll just end up rewriting your unit tests. Still, mocking is most likely unavoidable when the thingy you are testing ends up - somewhere down the line - doing something with a third party system. After all, you probably don't want to send real "Kill all humans" messages to your robot control server. The purpose here is to verify that Larger collections of things work together as planned. Layer three: System testing This part is often a bit complicated and I've seen quite a many definition. The one I like the most - especially with WEB stuff - is: "Test things as a user". Whatever you are writing, it most likely has some kind of an interface for third party interactions. This could be the Web front end, the (C/G)UI the user uses to do stuff or possibly just a public interface for third party code to ask your component to do stuff. Write tests that do stuff the user would do and assert that correct things happen. If it's a web thingy, test stuff like "When user fills this form with these things and presses this button, he should see this to indicate that the correct thing happened". Since you've already made sure that your individual components do the right things and that the components interact in the correct way, this step doesn't need to delve deep into the insides of your code. It's basically black box testing, from the viewpoint of the user. If you have the system specs as user stories, this step will probably be about writing tests that make sure that the tasks described in those user stories can be accomplished. This step is also where you test for usability ("Does this UI suck balls"), performance ("Does it crawl to stop after 5 concurrent users") and security ("Does everything break when little Bobby Tables checks in?"). Layer four: Acceptance testing This is something you can't automate. The idea here is to determine if the software fills it purpose: whether it fixes whatever problem the user had and the software was designed to fix. IF you are writing a thingy to allow phone rep people to do thing X easier than before, this step would probably involve getting a few phone rep guys to come over and try the thing out. What we've accomplished So, what have we accomplished? At layer 0, we made sure that code was stylistically up to spec. You have correct indentations, new lines etc. We've made sure that your code is easy for you and other developers to work with. At layer 1, we made sure that the things you wrote worked like they should when in isolation. There are no glaring logical mistakes like you returning the oldest Fart when someone calls FartDAO.getNewest(). At layer 2, we made sure things work together. That when you ask the Http stack to update your Farts from the interweb, you make the correct Http calls to where-ever and the retrieved farts are correctly stored. The thingy works as a black box. At layer 3, we made sure that the thingy works like it should when the user is doing user things. At layer 4, we made sure that we actually built a thing that does what it was supposed to. A random pile of writings. Here's some links, hopefully some of them will be helpful. Writing Great Unit Tests: Best and Worst Practices Top 12 Selected Unit Testing Best Practices Using Customer Tests to Drive Development Mocks Aren't Stubs Acceptance TDD Explained Exploratory Testing Explained What is Exploratory Testing? Loezi fucked around with this message at 14:33 on Jun 28, 2014 |
# ? Jun 28, 2014 10:12 |
|
Wow, thanks for that! That's amazing, I really appreciate it. Right now I'm basically mocking my own classes (which generally works ok) and testing classes in isolation that way. I guess my issue is that it's hard to test methods in isolation, because some of them involve using other methods to build some state, so I can either test once and assume they're fine in the other test (and get multiple failures if they're not), or I can keep checking validity as I go, so I at least know why the other test failed and what needs looking at first. The mocking system you're using there (what is it?) looks way more usable and robust though, so that might be the solution. I'm writing for Android so I'll need to look at what's available. Thanks for the links, I'll have a read through them in a bit
|
# ? Jun 28, 2014 18:05 |
|
Looks like Moq.redleader posted:Nothing too stupid about processing XML with a tool designed to process XML I can think of a few places at work where we use XSLT to turn XML to CSV and/or JSON (not that I'd recommend creating JSON this way). I'm kind of with you there. It's been ten years since I used perl, but I think it would be easier. However, I have another output that I need to make which is PDF. I have XSL that creates XSL-FO for that. Needs a lot of tweaking but it should work, so I was trying to confine the solution to one technology. Since you showed me how to do modes it's getting less painful, so I'm going to keep working on this proof of concept. If I get stuck I'll change gears. Thanks again.
|
# ? Jun 28, 2014 22:29 |
|
The mocking framework in the example is Mockito for Java. Another good one (so I've heard) is powermock.
|
# ? Jun 28, 2014 22:30 |
|
My programming skills have quickly been growing rusty, and so I need some small projects to program to help get my feet wet again. Emphasis on "small", as I would like to do many of them. Any suggestions? Thank you much!
|
# ? Jun 29, 2014 03:27 |
|
pliable posted:My programming skills have quickly been growing rusty, and so I need some small projects to program to help get my feet wet again. Emphasis on "small", as I would like to do many of them. I've been trying out https://www.exercism.io lately and it's really neat. You get a small exe which is a command line application. You can run "exercism fetch python" (replace python with one of the many languages they have if you want) and it gets you an exercise. The exercise consists of a unit test and a readme. You have to make a class/functions/a file that will pass the unit test. Once you've passed the unit test you can run "exercism submit <path to your file>" and then fetch the next task. There seems to be a ton of tasks (no idea how many yet) and they're all pretty small-scale and I've enjoyed the python ones so far as a small thing to jump into if I'm waiting for something.
|
# ? Jun 29, 2014 03:40 |
|
Jewel posted:I've been trying out https://www.exercism.io lately and it's really neat. You get a small exe which is a command line application. You can run "exercism fetch python" (replace python with one of the many languages they have if you want) and it gets you an exercise. That does look really neat, I'll try this out. Thank you EDIT: I just tried the first exercise in Python and you're absolutely right, this is very, very cool. Unfortunately, it doesn't seem like much of an active community. Is there a Something Awful team I can join though? If not, I'll create one! pliable fucked around with this message at 23:09 on Jun 29, 2014 |
# ? Jun 29, 2014 06:36 |
|
I was going to post a GBS style thread about this but I'll start small. I had an idea and wanted to see if anyone else thought it was worth while to invest their time in it. Goons should rewrite the forums in Ruby on Rails and opensource it or better yet only license it to Lowax to use expressly only for SA. Then we write some migrations to port all the old data. We start with gathering a list of all the current features and replicating those, including styles and layout so that the UI doesn't change at all. People hate UI changes. Anyone else think this is a good idea?
|
# ? Jun 30, 2014 03:06 |
|
Are you trolling?
|
# ? Jun 30, 2014 03:29 |
|
Waffleimages is about the closest thing there has been to a successful goon project, and that's been dead & buried for a while now. I don't think a second-system clone of a hacked up version of an ancient vBulletin codebase done in Rails has much of a chance of succeeding nor is worth doing - use your time for some better project imo.
|
# ? Jun 30, 2014 03:31 |
|
|
# ? May 22, 2024 08:54 |
|
Well I mean, we all use these forums a lot, so it has a purpose. And our code wouldn't be hacky because we are just replicating functionality while re-writing the backend cleaner. In fact, we'd be better off never seeing the existing code and just doing this based on replicating the UI and UI functionality or improving it where it makes sense.
|
# ? Jun 30, 2014 03:36 |