language-agnostic

Similar language features to compare with Perl and Ruby __END__

风流意气都作罢 提交于 2019-12-24 19:27:08
问题 Background Perl and Ruby have the __END__ and __DATA__ tokens that allow embedding of arbitrary data directly inside a source code file. Although this practice may not be well-advised for general-purpose programming use, it is pretty useful for "one-off" quick scripts for routine tasks. Question: What other programming languages support this same or similar feature, and how do they do it? 回答1: Perl supports the __DATA__ marker, which you can access the contents of as though it were a regular

Avoiding Language Keyword Conflicts

邮差的信 提交于 2019-12-24 19:00:28
问题 How do you guys avoid keyword conflicts in your language? For example, I'm creating a class (VB 2008) to hold all the configuration variables for some reports we generate. Naturally, one of the variables is "Date". And of course you can't have anything named the same as a keyword. In VB 2008 you do have the option of surrounding a conflicting word with []'s and fix it but I've always seen that as a hack. Any suggestions? What are your names to get around common keywords? Code to help

How to click on a coordinate on a screen?

断了今生、忘了曾经 提交于 2019-12-24 18:21:24
问题 I have a program that wants to be able to click on the screen; say my screen is X by Y pixels, I want to make my program send clicks to coordinate (x, y). Any language is acceptable, but preferably Ruby, Java, or Python :) Preferably on Windows, Ubuntu is another possibility. Thanks for the help. 回答1: With Ubuntu: from Xlib import X, display disp = display.Display() screen = disp.screen() root = screen.root root.warp_pointer(300, 300) disp.sync() So as a function: from Xlib import X, display

Generate all lists of size n, such that each element is between 0 and m (inclusive)

依然范特西╮ 提交于 2019-12-24 16:53:23
问题 Generate all lists of size n , such that each element is between 0 and m (inclusive). There are (m+1)^n such lists. 回答1: There are two easy ways of writing the general case. One is described in the existing answer from @didierc. The alternative is recursion. For example, think about a method that takes a String as an argument: if(input string is long enough) print or store it else iterate over digit range recursive call with the digit appended to the string 回答2: This is just like enumerating

Confusion with polymorphism: Parametric, Inclusion, Coercion, and Overloading

萝らか妹 提交于 2019-12-24 12:33:43
问题 Reading stackoverflow questions, the general consensus seems to be that overloading is not part of polymorphism. However, my OOP lecture notes state that: "There are four kinds of polymorphism: Parametric, Inclusion, Coercion, and Overloading". In the notes, it refers to overloading with methods with different parameters, and also overloading operators, e.g. + in the sense of ints and floats. Wikipedia also states "Ad hoc polymorphism is supported in many languages using function overloading.

What is the proper way to maintain a project that meets two versions of a platform?

假如想象 提交于 2019-12-24 11:14:47
问题 Suppose I have a project implemented in a specific programming language whose use is fragmented into two (or more) versions, for any reason. These two versions provide different mechanisms to implement some functionality of the project. Thus, the same code is not portable between versions. How to organize this situation in a git repository? Nevertheless, Keep directories for specific versions within a branch? Duplicates branchs in the same repository? Or use different repositories for each

I need an algorithm that can fit n rectangles of any size in a larger one minimizing its area

夙愿已清 提交于 2019-12-24 10:08:10
问题 I need an algorithm that would take n rectangles of any sizes, and calculate a rectangle big enough to fit them all, minimizing its area so the wasted area is minimum, and also returning the position of all the smaller rectangles within. The specific task I need this to implement on is in a sprite sheet compiler that would take individual PNG files and make a large PNG with all the images in it, so individual frames can be blitted from this surface at run time. A nice to have feature would be

what are design patterns and how can it benefit one's programming productivity?

99封情书 提交于 2019-12-24 09:50:08
问题 I've been reading various programming styles like XP (writing the test first), and came across a Java book that just has design patterns, what seems to be like pseudocodes. What are these design patterns used for ? what does design apttern in the context of programming refer to and what are it's applications ? Is it like blue prints for building a domain specific application ? 回答1: A Design Pattern is a general reusable solution to a commonly occuring design problem. Actually, we can

How does this integer encoding work?

北慕城南 提交于 2019-12-24 09:03:54
问题 In this code golf question, there is a python answer that encodes the lengths of all integers from 1 to 99 in english to a big number: 7886778663788677866389978897746775667552677566755267756675527886778663788677866355644553301220112001 To get the length of n , you just have to calculate 3 + (the_big_number / (10**n)) % 10 . How does this work? 回答1: (the_big_number / (10^n)) % 10 pulls out the n th least significant digit of the big number, so the lengths are just stored starting with the

How can you get a screenshot from someone's web browser?

时光怂恿深爱的人放手 提交于 2019-12-24 08:16:37
问题 I didn't think this was possible, but http://www.snapabug.com provides a service that uses screen capture technology to generate reports that helps you help your users. How are they able to do this?? Apparently, their service does not require any extra browser plugins or extensions. My guess is that it uses Flash, since this doesn't seem possible in JavaScript, and loading a Java applet is ridiculously slow. 回答1: SnapABug uses a Java Applet to get the screenshot of the Browser. A Java Runtime