How to create a random string using PHP?

If you want to allow repetitive occurences of characters, you can use this function: function randString($length, $charset=”ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789″) { $str=””; $count = strlen($charset); while ($length–) { $str .= $charset[mt_rand(0, $count-1)]; } return $str; } The basic algorithm is to generate <length> times a random number between 0 and <number of characters> − 1 we use as …

Read more

Keyboard events in a WPF MVVM application?

To bring an updated answer, the .net 4.0 framework enables you to do this nicely by letting you bind a KeyBinding Command to a command in a viewmodel. So… If you wanted to listen for the Enter key, you’d do something like this: <TextBox AcceptsReturn=”False”> <TextBox.InputBindings> <KeyBinding Key=”Enter” Command=”{Binding SearchCommand}” CommandParameter=”{Binding Path=Text, RelativeSource={RelativeSource AncestorType={x:Type TextBox}}}” …

Read more

Palindrome check in Javascript

Maybe I will suggest alternative solution: function checkPalindrom (str) { return str == str.split(”).reverse().join(”); } UPD. Keep in mind however that this is pretty much “cheating” approach, a demonstration of smart usage of language features, but not the most practical algorithm (time O(n), space O(n)). For real life application or coding interview you should definitely …

Read more

Should we hire someone who writes C in Perl? [closed]

I advise people to never hire Perl programmers, or C programmers, or Java programmers, and so on. Just hire good people. The programmers who I’ve hired to write Perl were also skilled in various other languages. I hired them because they were good programmers, and good programmers can deal with multiple languages. Now, that code …

Read more

How can I transition height: 0; to height: auto; using CSS?

Use max-height in the transition and not height. And set a value on max-height to something bigger than your box will ever get. See JSFiddle demo provided by Chris Jordan in another answer here. #menu #list { max-height: 0; transition: max-height 0.15s ease-out; overflow: hidden; background: #d5d5d5; } #menu:hover #list { max-height: 500px; transition: max-height …

Read more

Which programming languages can be used to develop in Android? [duplicate]

At launch, Java was the only officially supported programming language for building distributable third-party Android software. Android Native Development Kit (Android NDK) which will allow developers to build Android software components with C and C++. In addition to delivering support for native code, Google is also extending Android to support popular dynamic scripting languages. Earlier …

Read more