user-input

Shrinking font-size at a user types to fit in an input using Javascript

左心房为你撑大大i 提交于 2019-11-26 20:58:57
问题 Apple's MobileMe uses javascript to change the font size in the email login on its homepage as the user types so that the text always fits in the available space without overflow scrolling. While I can see how how to execute a function on each keypress, I'm curious how one would go about caluclating the font-size each time so that it always fits into the input field. Is there a way to measure the length of a piece of text with a variable width font? How do they accomplish this effect? Try it

How to capitalize first letter of first word in a sentence?

笑着哭i 提交于 2019-11-26 20:43:58
I am trying to write a function to clean up user input. I am not trying to make it perfect. I would rather have a few names and acronyms in lowercase than a full paragraph in uppercase. I think the function should use regular expressions but I'm pretty bad with those and I need some help. If the following expressions are followed by a letter, I want to make that letter uppercase. "." ". " (followed by a space) "!" "! " (followed by a space) "?" "? " (followed by a space) Even better, the function could add a space after ".", "!" and "?" if those are followed by a letter. How this can be

Integer.parseInt(scanner.nextLine()) vs scanner.nextInt()

只愿长相守 提交于 2019-11-26 20:04:49
问题 My professor tends to do the following to get a number from the user: Scanner scanner = new Scanner(System.in); Integer.parseInt(scanner.nextLine()); What are the benefits as opposed to simply doing scanner.nextInt() ? java.util.Scanner.java has the following in it: public int nextInt() { return nextInt(defaultRadix); } public int nextInt(int radix) { // Check cached result if ((typeCache != null) && (typeCache instanceof Integer) && this.radix == radix) { int val = ((Integer)typeCache)

How to use View.OnTouchListener instead of onClick

≯℡__Kan透↙ 提交于 2019-11-26 19:55:22
I'm developing an Android 2.2.2 application for a client and he wants to do the following: Now I have a button with an onClick event but he doesn't like, he wants to dectect when user release the button. I've found View.OnTouchListener which I think this is what I need to use but, is there any posibility to add this event to xml like I did with onClick? <ImageButton android:id="@+id/btnSaveNewGate" android:layout_width="@dimen/btnSaveNewGate_width" android:layout_height="@dimen/btnSaveNewGate_height" android:layout_below="@+id/radioGrGateType" android:layout_centerHorizontal="true" android

Simulate user input in bash script [closed]

自古美人都是妖i 提交于 2019-11-26 19:34:05
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I am creating my own bash script, but I am stuck at the moment. Basically, the script would be used to automate server setup in CentOS. Some software normally asks the user to type a password. I want the script to put the password that I have generated and stored as a variable instead of asking the user. When

How to scanf only integer and repeat reading if the user enter non numeric characters?

[亡魂溺海] 提交于 2019-11-26 18:50:37
Here is a little young tyro's problem with C code trying simply to prevent the user from typing a character or an integer less than 0 or more than 23. #include <stdio.h> #include <stdlib.h> int main(void) { const char *input; char *iPtr; int count = 0; int rows; printf("Enter an integer: "); scanf("%s", input); rows = strtol(input, &iPtr, 0); while( *iPtr != '\0') // Check if any character has been inserted { printf("Enter an integer between 1 and 23: "); scanf("%s", input); } while(0 < rows && rows < 24) // check if the user input is within the boundaries { printf("Select an integer from 1 to

While loop to check for valid user input? [duplicate]

守給你的承諾、 提交于 2019-11-26 18:35:44
问题 This question already has answers here : Asking the user for input until they give a valid response (18 answers) Closed last year . Python newbie here so sorry for what I'm sure is a stupid question, but I can't seem to solve the following challenge in a tutorial that is asking me to use a while loop to check for valid user input. (using Python2.7) Here's my code, but it's not working properly: choice = raw_input('Enjoying the course? (y/n)') student_surveyPromptOn = True while student

Getting user input [duplicate]

删除回忆录丶 提交于 2019-11-26 17:24:46
This question already has an answer here: How to read keyboard-input? 5 answers I am running this: import csv import sys reader = csv.reader(open(sys.argv[0], "rb")) for row in reader: print row And I get this in response: ['import csv'] ['import sys'] ['reader = csv.reader(open(sys.argv[0]', ' "rb"))'] ['for row in reader:'] [' print row'] >>> For the sys.argv[0] I would like it to prompt me to enter a filename. How do I get it to prompt me to enter a filename? In python 3.x, use input() instead of raw_input() Dave Webb Use the raw_input() function to get input from users (2.x): print "Enter

Hide Input in Batch File

房东的猫 提交于 2019-11-26 16:56:56
问题 I was wondering how I would go about Hiding the input from a 'set /p' command in a batch file. set /p Password=What is your password? We all know that inputting your password, you would be able to see it. How would I go 'bout hiding it ? I tried conset.exe from here. And used: conset /PH Password=What is your password? And i get "Conset: Error setting variable" :( Another idea I had, was to change the colour of the console window. But how could I change the colour on the same line? So that

Fill os.Stdin for function that reads from it

六月ゝ 毕业季﹏ 提交于 2019-11-26 16:42:08
How do I fill os.Stdin in my test for a function that reads from it using a scanner? I request a user command line input via a scanner using following function: func userInput() error { scanner := bufio.NewScanner(os.Stdin) println("What is your name?") scanner.Scan() username = scanner.Text() /* ... */ } Now how do I test this case and simulate a user input? Following example does not work. Stdin is still empty. func TestUserInput(t *testing.T) { var file *os.File file.Write([]byte("Tom")) os.Stdin = file err := userInput() /* ... */ } Mocking os.Stdin You're on the right track that os.Stdin