Here is a JavaScript function that defined if a value is numeric or not.
function isNumeric(value) {
return value == parseFloat(value);
}
Cheers :-)
Here is a JavaScript function that defined if a value is numeric or not.
function isNumeric(value) {
return value == parseFloat(value);
}
Cheers :-)
While I was reading Ricky Rosario’s blog I took note of an interesting way to implement the startsWith and the endsWith methods for Strings. It may be useful.
String.prototype.startsWith = function(prefix) {
return this.indexOf(prefix) === 0;
}
String.prototype.endsWith = function(suffix) {
return this.match(suffix + "$") == suffix;
}
Cheers :-)
Sometime you need to prevalidate some inputs in a form. You could do this by looping in all the elements of the form. Here is a quick example of doing just that.
<html>
<head>
<title>An example.</title>
<script type="text/javascript">
function loopInFormElements(aForm) {
for (i = 0; i < aForm.elements.length; i++) {
alert(aForm.elements[i].name + " = " + aForm.elements[i].value);
}
}
</script>
</head>
<body>
<form onsubmit="loopInFormElements(this);" action="" method="post">
<input type="text" name="value1" value="1" /><br />
<input type="text" name="value2" value="2" /><br />
<input type="text" name="value3" value="3" /><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
What happen here is when I submit the form, the loopInFormElements method get called. This function loop in all the form’s elements and show the name and the value of the inputs.
I thought it could be handy.
Cheers :-)
Just a quick thought about standards. You should try to keep them simples.
And please, don’t push to hard on best practices. The’re not silver-bullets.
Enough evangelizing for today :-P.
Cheers :-)
Python use two underscores to hide a method. You can use two underscores to hide a variable too.
class MyClass:
def publicMethod(self):
print "Public"
def __privateMethod(self):
print "Private"
So now you can call publicMethod().
def main():
myClass = MyClass()
myClass.publicMethod()
But you can’t call __privateMethod().
def main():
myClass = MyClass()
myClass.__privateMethod()
Traceback (most recent call last):
File "privatetest.py", line 13, in <module>
main()
File "privatetest.py", line 10, in main
myClass.privateMethod()
AttributeError: MyClass instance has no attribute 'privateMethod'
Of course there’s a way to call a private method anyway. But why would you do that?
Here’s a simple example of a game screen written in Python and Pygame.
import pygame
from pygame.locals import *
def main():
# I'm initializing the game's screen.
pygame.display.init()
# I set the width and the height of the screen.
screen = pygame.display.set_mode((300, 200))
# I'm setting the title of the game's screen.
pygame.display.set_caption("The game's title")
# I want to hide the mouse when It over the game's screen.
pygame.mouse.set_visible(0)
running = True
while running:
for event in pygame.event.get():
if event.type == QUIT:
running = False
if __name__ == "__main__":
main()
Cheers :-)
I was fooling around with Python and I wanted to connect to my database using ODBC. While googling on the subject, I found pyodbc. It was quite easy to install this module on my Windows box and I was up and running in no time.
import pyodbc
def main():
connection = pyodbc.connect("Your Connection String")
cursor = connection.cursor()
cursor.execute("select something from myTable")
for row in cursor:
print row.something
if __name__ == "__main__":
main()
Of course, you need to provide a real conntection string.
Cheers :-)
I just finished Getting Real from 37 signals. This book give some insights on how software should be made.
Here some key points from the book :
Don’t try to look corporate. You don’t need to put emphasis on professionnalism. It’s just a matter of fact. Don’t loose your time on all this noise.
Just keep things simple and go make software.
I think that Automatic Updates on Windows help the user to keep his computer up-to-date. But when I press the tiny button Restart Later I really mean to Restart Later.

Disturbing Popup
So when I’m working I don’t need a reminder that will popup every 10 minutes to ask me if I wish to restart my computer. It’s for that reason that I press the Restart Later button.
Why it still bugging me? Why it still asking me? Why…
I guess I should use the Restart Now button instead.
Bandwidth is important for a web application and you should try to keep it as low as possible. You could edit your web pages to strip all the spaces and to put the code on one line. But I think is a very ineffective method cause you creating a nightmare for the application’s maintainers (that’s probably you) and you will not be able to do a better job than a compression algorithm. You should be searching for compression filter instead.
I’m currently working with IIS 6.0. So I will demonstrate how to enable compression for this server. I know that this concept is supported by other servers to.
The server looks for the HTTP header Accept-Encoding in the received requests. If the compression is accepted (Accept-Encoding: gzip, deflate) the server will compress the response before sending it to the client.
A HcDynamicCompressionLevel of 0 is the lowest compression level while 10 is the highest compression level. Be aware that a high compression level means more work for the server’s CPU.
The HcScriptFileExtensions indicate which files to compress. In my case I want my ASP files to be compress. Here a snippet of my C:\Windows\system32\inetsrv\metabase.xml.
<IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/deflate" HcCompressionDll="%windir%\system32\inetsrv\gzip.dll" HcCreateFlags="0" HcDoDynamicCompression="TRUE" HcDoOnDemandCompression="TRUE" HcDoStaticCompression="FALSE" HcDynamicCompressionLevel="9" HcFileExtensions="htm html txt" HcOnDemandCompLevel="10" HcPriority="1" HcScriptFileExtensions="asp dll exe" > </IIsCompressionScheme> <IIsCompressionScheme Location ="/LM/W3SVC/Filters/Compression/gzip" HcCompressionDll="%windir%\system32\inetsrv\gzip.dll" HcCreateFlags="1" HcDoDynamicCompression="TRUE" HcDoOnDemandCompression="TRUE" HcDoStaticCompression="TRUE" HcDynamicCompressionLevel="9" HcFileExtensions="htm html txt" HcOnDemandCompLevel="10" HcPriority="1" HcScriptFileExtensions="asp dll exe" > </IIsCompressionScheme>
There you go folks. Your now saving some bandwidth. I hope it makes a difference for you cause it makes one for me.