background preloader

Learning Javascript with Object Graphs

Learning Javascript with Object Graphs
HEADS UP! This article was written for an older version of node. More up-to-date information may be available elsewhere. One of the secrets to being a super effective JavaScript developer is to truly understand the semantics of the language. References Everywhere A variable in JavaScript is simply a label that references a value in memory somewhere. Local Variables In the following example, we will create four local variables in the top-level scope and point them to some primitive values: variables.js // Let's create some local variables in the top scopevar name = "Tim Caswell";var age = 28;var isProgrammer = true;var likesJavaScript = true;// Test to see if the two variables reference the same valueisProgrammer === likesJavaScript; Notice that the two boolean variables point to the same value in memory. In the code snippet we checked to see if the two references pointed to the same value using === and the result was true. The outer box represents the outermost closure scope. objects.js Related:  averroesfr

8 ways to be a better programmer in 6 minutes. 'hacka' on Sun, 08 Feb 2009 10:12:44 GMT, sez: stop using .net 'lb' on Sun, 08 Feb 2009 10:14:27 GMT, sez: @Hacka Ouch! 'Don2' on Sun, 08 Feb 2009 10:26:20 GMT, sez: The bigger font-size idea is excellent. Now I am better, and I can get on with my life. 'just honest' on Sun, 08 Feb 2009 10:35:21 GMT, sez: Maybe if I turned up to work sober once in a while. 'nagoff' on Sun, 08 Feb 2009 12:04:28 GMT, sez: How about 'remove some (all?) 'Michael' on Sun, 08 Feb 2009 14:40:49 GMT, sez: Learn a design pattern and try it out the next time an appropriate opportunity arises. 'Stephan Schmidt' on Sun, 08 Feb 2009 17:24:02 GMT, sez: Nice, made me think. Stephan -- Programming is hard - 'nagoff' on Sun, 08 Feb 2009 17:59:07 GMT, sez: I missed an obvious one that only occurred to me later - chat to a customer. 'jm' on Sun, 08 Feb 2009 18:00:49 GMT, sez: Read an open source project in six minutes? 'dccrowley' on Sun, 08 Feb 2009 19:07:17 GMT, sez: 1. 1.

Learning Javascript with Object Graphs (Part II) Static Version The first article using graphs to describe JavaScript semantics was so popular that I've decided to try the technique with some more advanced ideas. In this article I'll explain three common techniques for creating objects. My goal is that this will help people understand the strengths and weaknesses of each technique and understand what's really going on. Classical JavaScript Constructors First let's create a simple constructor function with a prototype. classical.js#rectangle function Rectangle(width, height) { this.width = width; this.height = height;}Rectangle.prototype.getArea = function getArea() { return this.width * this.height;};Rectangle.prototype.getPerimeter = function getPerimeter() { return 2 * (this.width + this.height);};Rectangle.prototype.toString = function toString() { return + " a=" + this.getArea() + " p=" + this.getPerimeter();}; Now let's define a new class of objects called Squares that inherit from Rectangles. classical.js#test

HTML Tutorial CSS Sprites: Image Slicing’s Kiss of Death Back when video games were still fun (we’re talking about the 8-bit glory days here), graphics were a much simpler matter by necessity. Bitmapped 2-dimensional character data and background scenery was individually drawn, much like today’s resurgent pixel art. Hundreds and later thousands of small graphics called sprites were the building blocks for all things visual in a game. Article Continues Below As game complexity increased, techniques developed to manage the multitude of sprites while keeping game play flowing. And what does this have to do with the web? Everything old is new again, and though the rise of 3D games has made sprite maps obsolete, the concurrent rise of mobile devices with 2D gaming capabilities have brought them back into vogue. Specifically, we’re going to replace old-school image slicing and dicing (and the necessary JavaScript) with a CSS solution. How do CSS Sprites work? Let’s start with the master image itself. On to the HTML. Applying the CSS#applyingcss

Online Python Tutor - Learn programming by visualizing code execution The New Boston » Java A true story about survival in the Adirondack Mountains. The park covers 6.1 million acres, a land area greater than Vermont, or than Yellowstone, Yosemite, Grand Canyon, Glacier, and Great Smoky Mountains National Parks combined. The Adirondacks are also home to thousands of black bears, deadly snakes, and countless other dangers. Abandoned in the middle of the park with no survival experience and very few supplies, the entire journey was documented and filmed. Click here to watch the whole series! Welcome to thenewboston, the ultimate source for free video tutorials on the internet! There is also a new and improved thenewboston Official Forum. If you are ever on YouTube, make sure to check out my channel at Feel free to donate to help support thenewboston. I hope you all enjoy the website, and thank you to everyone for all of your support!

Learning Javascript with Object Graphs (Part III) Static Version Part I of this series explained basic object graphs and visually described references, closures, and basic inheritance in JavaScript. Part II compared different styles for doing object-oriented programming in JavaScript. Now in Part III we'll get creative and look as Ruby's object model and compare it to how JavaScript works. Also I'll show how to implement some Ruby style classes. Why Ruby Ok, I'll admit, I used to be a ruby guy. Also I chose ruby because I've noticed that several newcomers to the node.js community come from ruby and other languages with similar object systems. What are Objects Both languages are object oriented languages. Methods versus Functions Probably the biggest difference between the object models when you get down to it and ignore syntax is the fact that Ruby has methods and JavaScript has first-class functions. Gotta keep them separated In classical OO, there is this idea that you must separate function from state. Controlled Inheritance A String Ruby

10 Puzzle Websites to Sharpen Your Programming Skills Solving programming puzzles is a fun way to develop your logical and problem solving abilities. Also, when you’re familiarizing yourself with a new programming language, solving puzzles for that language can help speed up the learning process. Here are the top 10 popular programming puzzle sites that will help test your thinking and improve your programming, problem solving, and logical thinking skills. 1. Programming Praxis Programming Praxis is a blog that includes a range of interesting problems with solutions usually available in several different programming languages. 2. CodeKata is a blog of programming puzzles written by Dave Thomas, who’s most famous for the groundbreaking book, Pragmatic Programmer. 3. TopCoder is an active programming community of developers who love to solve puzzles. 4. 5. Facebook has a collection of very challenging programming puzzles that–should you manage to solve them–could result in you getting a job at Facebook! 6. 7. 8. 9. 10. 99 Prolog Problems

Using the memcached telnet interface This is a short summary of everything important that helps to inspect a running memcached instance. You need to know that memcached requires you to connect to it via telnet. The following post describes the usage of this interface. How To Connect Use "ps -ef" to find out which IP and port was passed when memcached was started and use the same with telnet to connect to memcache. Example: telnet 11211 Supported Commands The supported commands (the official ones and some unofficial) are documented in the doc/protocol.txt document. Sadly the syntax description isn't really clear and a simple help command listing the existing commands would be much better. Traffic Statistics You can query the current traffic statistics using the command stats You will get a listing which serves the number of connections, bytes in/out and much more. Example Output: Memory Statistics You can query the current memory statistics using stats slabs Which Keys Are Used? stats items Never Set a Timeout > 30 Days!

The Ultimate Guide to WordPress Multisite We’ve been developing plugins for it since the old days when it was WordPress MU, and we use it to power Edublogs, a huge network of blogs for educators and students. Personally I also use Multisite a lot. I use it to host client websites, to create sites demonstrating techniques I outline in my books and tutorials, and to keep everything in one place. In this guide to Multisite I’m going to show you everything you need to know to get started with Multisite and create your own network of blogs or sites. I’ll cover: What is Multisite and how is it different from regular WordPress? But first, let’s get some terminology straight. Network refers to the entire Multisite network, i.e. your WordPress installationSite refers to one of the blogs or sites created as part of the network. So when I refer to your site, I don’t mean your whole network of sites, but just one of the sites on it. So now we’ve got that sorted, let’s take a look at Multisite! What is Multisite? Uses for Multisite Creating a Site

Why use "closure"? Static Version One of the greatest features of the JavaScript language is closure. I've discussed this concept some in the "What is This?" What is a closure Again from wikipedia: In computer science, a closure is a first-class function with free variables that are bound in the lexical environment. Or the way I understand it intuitively: A closure is a function defined within another scope that has access to all the variables within the outer scope. Using closure to hide state Imagine this piece of code: greet_plain.js function greet(message) { console.log(message);} function greeter(name, age) { return name + ", who is " + age + " years old, says hi!" // Generate the messagevar message = greeter("Bob", 47); // Pass it explicitly to greetgreet(message); Output Bob, who is 47 years old, says hi! We're manually passing the internal state around so that the other functions can get ahold of it. Clearly there must be a better way. greeter.js return function greet() { console.log(message); };} personclass.js

Programming 101 - The 5 Basic Concepts of any Programming Language - How to Program with Java First off, I’d like to say that I’m writing these preliminary posts in a way that I’ll assume you have very little knowledge in programming. I want this content to provide anyone “walking in off the street” the knowledge to be able to write their first program with the Java programming language with as little pain as possible. So, let’s get started with our first topic: The 5 basic concepts of any programming language. So here are the 5 basic concepts of any programming language: I recognize that these words probably look foreign to you, but don’t worry, I’ll do my very best at taking the mystery out of them. What is a variable? Variables are the backbone of any program, and thus the backbone of any programming language. This concept is extremely powerful in programming and is used constantly. Now, if we want to get more specific, when it comes to the Java programming language, variables have different types. What the heck are String, Integer and Double? Excellent question!

Get To Know Linux: The /etc/init.d Directory If you use Linux you most likely have heard of the init.d directory. But what exactly does this directory do? It ultimately does one thing but it does that one thing for your entire system, so init.d is very important. The init.d directory contains a number of start/stop scripts for various services on your system. Everything from acpid to x11-common is controlled from this directory. Of course it's not exactly that simple. If you look at the /etc directory you will find directories that are in the form rc#.d (Where # is a number reflects a specific initialization level - from 0 to 6). Now if you are using a distribution like Fedora you might find this directory in /etc/rc.d/init.d. In order to control any of the scripts in init.d manually you have to have root (or sudo) access. /etc/init.d/command OPTION Where command is the actual command to run and OPTION can be one of the following: startstopreloadrestartforce-reload Most often you will use either start, stop, or restart.

Collecting all the cheat sheets