language-agnostic

Reordering objects with order property

旧城冷巷雨未停 提交于 2020-01-03 02:57:34
问题 Consider objects with an order property. Objects will be sorted based on this property. How would you assign the order property given the following restrictions and operations? Operations (in order of importance) push(object) : Insert object at index 0. swap(indexN, indexM) : Swap object at index N with object at index M. remove(object) : Remove object. Remaining elements must retain the same order. insert(object) : Insert object with given order. Restrictions Changing the order property of

Balancing Design Principles: Unit Testing

只愿长相守 提交于 2020-01-02 10:25:12
问题 I am writing a simulation of Bananagrams. Currently, I have a GameMaster class that maintains the common collection of pieces. The deal(Player) method deals a certain number of pieces to that player. I want to write unit tests for this. However, at this point, I have no getters, and thus no way to check the status of the objects. Why not add getters? I don't want to add code to the public interface only for testing. Right now, there is no other reason to expose those functions. What am I

Sorting Geographical non-contiguous line segments along an implied curve

时光毁灭记忆、已成空白 提交于 2020-01-02 08:03:22
问题 Given: A Set (for the sake of discussion we will call it S ), which is an unordered collection of line segments. Each line segment is defined as two Longitude-Latitude end-points. While all of the line segments follow an implied curve, there are "gaps" between each of the segments, of various sizes. We refer to this curve as "implied" because it is not explicitly defined anywhere. The only information that we have available are the line segments contained within S . Desired Result: A sequence

Sorting Geographical non-contiguous line segments along an implied curve

南笙酒味 提交于 2020-01-02 08:02:23
问题 Given: A Set (for the sake of discussion we will call it S ), which is an unordered collection of line segments. Each line segment is defined as two Longitude-Latitude end-points. While all of the line segments follow an implied curve, there are "gaps" between each of the segments, of various sizes. We refer to this curve as "implied" because it is not explicitly defined anywhere. The only information that we have available are the line segments contained within S . Desired Result: A sequence

What are the extensible languages people are using today?

你说的曾经没有我的故事 提交于 2020-01-02 07:50:29
问题 Wikipedia says: Extensible programming is a term used in computer science to describe a style of computer programming that focuses on mechanisms to extend the programming language, compiler and runtime environment. For example, Tcl lets you write your own control structures. See here. I'm interested in compiling a list of extensible programming languages that are being used in real-world code. It would be nice if you could supply an example for your language as well. 回答1: Languages in the

How to copy a large file in Windows XP?

我只是一个虾纸丫 提交于 2020-01-02 07:35:09
问题 I have a large file in windows XP - its 38GB. (a VM image) I cannot seem to copy it. Dragging on the desktop - gives error of "Insufficient system resources exist to complete the requested service" Using Java - FileChannel.transferTo(0, fileSize, dest) fails for all files > 2GB Using Java - FileChannel.transferTo() in chunks of 100Mb fails after ~18Gb java.io.IOException: Insufficient system resources exist to complete the requested service at sun.nio.ch.FileDispatcher.write0(Native Method)

Random number generator that fills an interval

大憨熊 提交于 2020-01-02 05:31:26
问题 How would you implement a random number generator that, given an interval, (randomly) generates all numbers in that interval, without any repetition? It should consume as little time and memory as possible. Example in a just-invented C#-ruby-ish pseudocode: interval = new Interval(0,9) rg = new RandomGenerator(interval); count = interval.Count // equals 10 count.times.do{ print rg.GetNext() + " " } This should output something like : 1 4 3 2 7 5 0 9 8 6 回答1: Fill an array with the interval,

When writing XML, is it better to hand write it, or to use a generator such as simpleXML in PHP?

大兔子大兔子 提交于 2020-01-02 04:45:15
问题 I have normally hand written xml like this: <tag><?= $value ?></tag> Having found tools such as simpleXML, should I be using those instead? What's the advantage of doing it using a tool like that? 回答1: Good XML tools will ensure that the resulting XML file properly validates against the DTD you are using. Good XML tools also save a bunch of repetitive typing of tags. 回答2: If you're dealing with a small bit of XML, there's little harm in doing it by hand (as long as you can avoid typos).

In ideal MVC should the view know the model?

生来就可爱ヽ(ⅴ<●) 提交于 2020-01-02 03:34:28
问题 My question is about the ideal or the original MVC interpretation http://heim.ifi.uio.no/~trygver/themes/mvc/mvc-index.html As MVC goal is to reduce dependencies, should the View knows the Model ? Then what would prevent it to become fat and call directly Model Methods without asking Controller ? Update: as I read answer below, I'll take a concrete example: Let's say you create a complex calculator (not just some simple one let's say an option pricer for stock market). It only needs input

Deserialization vs. parsing

旧巷老猫 提交于 2020-01-02 02:04:11
问题 As far as I understand, deserialization is turning a stream of bytes into an object. Parsing is kinda the same, usually turning a string into some data structure. Is parsing a type of deserialization? Can you consider them synonymous? 回答1: Parsing is the more general term. Deserialization is commonly used in the context of object oriented languages. The result of deserialization is an object while the result of parsing can be any type of data. Even in the context of object creation, parsing