Skip to main content

Posts

Express (JS, of course)

Q: What's ExpressJS? A: quite possibly the coolest thing to happen to Node.JS... EVAR!  This is awesome news for web developers and programmers. OK, you're interested now.  So, if you've followed my blog recently, you know that JavaScript is pure awesomeness.  You also know that server-side JavaScript is the way of the future.  Node.JS is the server-side JavaScript environment.  ExpressJS is the library. Q: So, what do you currently do to write web applications and web services? A: I write PHP code that runs on an Apache web server (or Lighttpd-FastCGI if you prefer).  The PHP code does cool stuff like session handling, parsing URL-encoded POST responses, talking to a database (probably MySQL), generating HTML, etc.  I use HTML, CSS, and JavaScript for the client-side stuff. Q: What do you REALLY want to do? A: Uhhh.... write awesome JavaScript code??? YES!  That's exactly right! You don't need PHP anymore! (Wha???)  You don't ev...

JavaScript Closures

What are closures in JavaScript? Taken from  http://jibbering.com/faq/notes/closures/ : The simple explanation of a Closure is that ECMAScript allows inner functions; function definitions and function expressions that are inside the function bodes of other functions. And that those inner functions are allowed access to all of the local variables, parameters and declared inner functions within their outer function(s). A closure is formed when one of those inner functions is made accessible outside of the function in which it was contained, so that it may be executed after the outer function has returned. At which point it still has access to the local variables, parameters and inner function declarations of its outer function. Those local variables, parameter and function declarations (initially) have the values that they had when the outer function returned and may be interacted with by the inner function. For Example: var x; function foo() {     var i = 2; ...

JavaScript Rocks

Here's a bold statement... (so I made the font bold) JavaScript is the best programming language Here's why... The language is extremely powerful .  Let's imagine that we are inventing a new programming language.  The most important thing we will focus on is "power."  That means... write more elegant , more flexible , more readable programs... and write them  even faster . Closures.  A completely awesome, overlooked feature of JavaScript that we all (hopefully) take for granted.  Closures allow you to create a new instance of a function which retains access to the context in which it was created.  Examples are here:  http://en.wikipedia.org/wiki/Closure_(computer_science) . Dynamic data types.  JavaScript variables aren't restricted to any particular datatype.  Store a String, store a number, or store an Object.  JavaScript automatically casts datatypes back and forth as needed. Objects are basically associ...

Top 25 Explanations by Programmers when their programs don't work

I found this list absolutely hilarious.  I've starred the ones that I use the most.  :) Top 25 Explanations by Programmers when their programs don't work: 1. Strange...  **** 2. I've never heard about that. 3. It did work yesterday. ** 4. Well, the program needs some fixing. 5. How is this possible? ****** 6. The machine seems to be broken. 7. Has the operating system been updated? 8. The user has made an error again. **** 9. There is something wrong in your test data. 10. I have not touched that module! 11. Yes yes, it will be ready in time. ** 12. You must have the wrong executable. 13. Oh, it's just a feature. ** 14. I'm almost ready. ** 15. Of course, I just have to do these small fixes. **** 16. It will be done in no time at all. *** 17. It's just some unlucky coincidence. 18. I can't test everything! 19. THIS can't do THAT. 20. Didn't I fix it already? ****** 21. It's already there, but it has not been tested. 22. I...

Alright... Who Configured Sudo?

noob@genie:~$ make me lots of money bash: make: command not found (thinks...) "Ah ha!" noob@genie:~$ sudo apt-get install make [sudo] password for root: Where did you learn to type? [sudo] password for root: Maybe if you used more than just two fingers... [sudo] password for root: Just what do you think you're doing Dave? sudo: 3 incorrect password attempts (whaa... Aw, crap!  Why do I need root's password?!?!)  "Who configured sudo on this server?  Oh wait... I know..." noob@genie:~$ sudo apt-get install make [sudo] password for root: Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed:   make 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. ... (after a short while) noob@genie:~$ make me lots of money bash: No more wishes remaining.  Goodbye! logout ".... $&#*"

Recurring Events in MySQL

This article describes how to store recurring events in a MySQL database. This might be useful if you're building a calendar or some sort of job scheduler. The table for storing recurring events is inspired by cron http://www.manpagez.com/man/5/crontab/ . You will notice obvious similarities between the table structure and the structure of a crontab file. The table structure also uses the SET datatype in MySQL. You should be familiar with this type before you continue. Documentation can be found here . Just as an example, I'll create a table that can be used to schedule the automatic updating of files. Here is the SQL statement you might use to create this table: CREATE TABLE `File Update Scheduler` (  `Filename` varchar(255) NOT NULL default '',  `LastRefreshed` timestamp NULL default NULL COMMENT 'Timestamp indicating when the file was last refreshed',  `ScheduledMinutes` set('0','15','30','45') NOT NULL COMMENT...

JavaScript Sticky Footer and Scroll Effect

This post talks about two different HTML/JavaScript effects: How to keep a page footer stuck at the bottom of the browser window. How to create a scrolling <div> without using a scroll bar OK. So... you have a website. You want a header stuck at the top of your page and the footer stuck at the bottom of your page. The stuff in the middle, you want to be able to scrollable. But, you don't want those ugly scrollbars to the right of your scrollable text. Maybe, instead, you'll have up arrows and down arrows above and below your <div>. When you mouseover the arrows, the text in the <div> will move up or down and create a scrolling effect. Suppose your page looks like this... <html> <head> <title>Test</title> </head> <body> <div style="position: relative; width: 700px; margin-left: auto; margin-right: auto;"> <div id="header">Header</div> <div id="scrollUp...