language-agnostic

Script working in two modes (preview and update)

对着背影说爱祢 提交于 2019-12-25 12:43:27
问题 I'm writing a script which works in two modes: 'preview' and 'update' . When it runs in 'preview' mode, the script generates a preview of the changes that will be made (something like a diff output). When it runs in 'update' mode, it applies those changes. The preview output could be generalized in this way: Item 231234 is new to the db. It will be added to the db with the following data: Name: Description: etc... Item 211012 already exists in the database, but some changes have been made:

Updating display of elements on the web page without refreshing the whole page

别说谁变了你拦得住时间么 提交于 2019-12-25 08:48:27
问题 Last time I coded a web application was almost 10 years ago. I used Java/JSP/HTML/CSS etc. I've been coding non-web applications only ever since. When I look at modern sites now (like this one), I realize how my web development skills are obsolete. Maybe the most obvious "feature" that I wouldn't know how to implement now is the update of elements on the page after user input without having to refresh the whole page (e.g. the voting/downvoting here updates the vote count without reloading the

Language with apps hungarian support?

好久不见. 提交于 2019-12-25 08:03:11
问题 Basically, I wonder if a language exists where this code will be invalid because even though counter and distance are both int under the hood, they represent incompatible types in the real world : #include <stdio.h> typedef int counter; typedef int distance; int main() { counter pies = 1; distance lengthOfBiscuit = 4; printf("total pies: %d\n", pies + lengthOfBiscuit); return 0; } That compiles with no warnings with "gcc -pedantic -Wall" and all other languages where I've tried it. It seems

Sudoku box indices start position

为君一笑 提交于 2019-12-25 07:38:31
问题 I'm implementing a sudoku solver using backtracking. It reads a sudoku board in the form: 027800061000030008910005420500016030000970200070000096700000080006027000030480007 I know how I can figure the elements on a column by doing index % 9 (and then doing a simple arithmetic progression of ratio 9) as well the elements on a line by using index/9 (and then by adding one until I get every one of them), where index is a number in the range [0,80]. What I cannot figure out is how to get the

Why make a class create an instance of itself?

余生长醉 提交于 2019-12-25 06:34:51
问题 I recently came across some code recently and although I know that it can work, I really don't see why a class would ever need to create an instance of itself within itself? I can't find any explanation for why you would do this, only how you do it. For example: public class Simple1 { /** Main entry point. */ public static void main(String args[]) throws ParseException { Simple1 parser = new Simple1(System.in); parser.Input(); } } 回答1: Execution in a Java program starts up in public static

If “if” is the last control statement in function and its block always executes “return”, then should I use “else”?

懵懂的女人 提交于 2019-12-25 05:46:07
问题 Consider this code (written in C to demonstrate the problem): int foo1(int a) { if(a) return 33; return 22; } int foo2(int a) { if(a) return 33; else return 22; } As you can see, foo1(int a) does exactly the same as foo2(int a) . foo1(int a) is shorter, however I get the impression that foo2(int a) is just more logical (that's only my impression). Which one is better? Is it good to use else with if that is the last control statement in function code and its block always executes return ? 回答1:

Generation of uniformly distributed random noise

青春壹個敷衍的年華 提交于 2019-12-25 04:44:22
问题 I've been working on generating Perlin noise for a map generator of mine. The problem I've run into is that the random noise is not distributed normally, and is more likely a normal distribution of kinds. Given two integers X and Y, and a seed value, I do the following: Use MurmurHash2 to generate a random number (-1,1). This is uniformly distributed. Interpolate points between integer values with cubic interpolation. Values now fall in the range (-2.25, 2.25) because the interpolation can

How to have procedural code wait for user input from a GUI before continuing?

我怕爱的太早我们不能终老 提交于 2019-12-25 01:45:52
问题 In my program there is a complex calculation that requires the user to evaluate intermediate results. This works well in a command line application (which is what my code looks like now) because the interactive prompt halts the program execution until the user hits enter. The command line code looks something like this: def calculate(starting): result1 = initial_calculation(starting) user_input1 = input("What is your choice for " + result1 + "?") result2 = calculate1(user_input1) user_input2

Design dilemma: If e-mail address already used, send e-mail “e-mail address already registered”, but can't because can't add duplicate to table

北城以北 提交于 2019-12-24 19:55:19
问题 A registration form asks for username and e-mail address . After the data passes validation it's added to the accounts table. It stores data such as username, password and e-mail address. If the username has already been taken the user will be notified and no data will be added to the table. It was seen as a security issue if the user was immediately notified that the e-mail address was already in the table. The suggested solution to this was to always send a verification e-mail and if the

What is the best way to limit voting on our website?

一笑奈何 提交于 2019-12-24 19:29:08
问题 We have website with articles users can vote for. What is the recommended method of limiting votes? There are so many sites that have voting implemented that I know some possible solutions but I guess that is some basic bulletproof recommended method based on sessions, IPs, time limit, etc. What is the best way to send votes from browser? Basic GET/POST or AJAX request? Is it necessary to use some pregenerated request-id? Update: We cannot use user registration. 回答1: [...] bulletproof [...]