Librenix
Headlines | Linux | Apps | Coding | BSD | Admin | News
Information for Linux System Administration 

JSEclipse Tutorial: A JavaScript Eclipse Tool

Up
vote
Down

JSEclipse — an Eclipse plug-in that provides many of those same features for JavaScript applications. JSEclipse gives JavaScript developers the same ease of use that Eclipse has been providing in the Java language. This tutorial covers the JSEclipse tool, which plugs into Eclipse and provides features like code completion and templates. read more...
permapage | score:9089 | -solrac, December 23, 2007

Scripting: Put a clock in your bash terminal

Up
vote
Down

In the original version, the cursor positioning didn't work on my Mac OS X system. If that happens to you, try this simplified variant:
  #!/bin/bash
while true
do
tput sc
tput cup 0 60
echo -en `date +"%H:%M:%S %F"`
tput rc
sleep 1
done
Also, note that you'll need to run either script in the background to use your terminal.
The script saves the current cursor position with an ANSI escape sequence instruction. Then, using the tput command, the cursor is sent to row 0 (the top of the screen) and the last column minus 19 characters (19 is the length of HH:MM:SS YYYY-MM-DD). The formatted date command is displayed in green inverted color. The cursor is then sent back to its original position with another ANSI sequence that restores the original saved position.
read more...
mail this link | permapage | score:9083 | -Ray, January 22, 2008

Forking vs. Threading

Up
vote
Down

What is Fork/Forking:
Fork is nothing but a new process that looks exactly like the old or the parent process but still it is a different process with different process ID and having it’s own memory. Parent process creates a separate address space for child. Both parent and child process possess the same code segment, but execute independently from each other.

What are Threads/Threading:
Threads are Light Weight Processes (LWPs). Traditionally, a thread is just a CPU (and some other minimal state) state with the process containing the remains (data, stack, I/O, signals). Threads require less overhead than “forking” or spawning a new process because the system does not initialize a new system virtual memory space and environment for the process. read more...
mail this link | permapage | score:9075 | -Napster, March 1, 2010

DWR Java Ajax: User Interface (pdf)

Up
vote
Down

Caution: this article is in PDF format. -Ed.

In this article, the author of the book DWR Java Ajax Application shows how to develop samples based on DWR, which demonstrate how to dynamically change the common user interface elements such as tables, lists, and field completion. It also covers steps to make a dynamic user interface skeleton for these samples.

The section on dynamic user interfaces shows how to get started with a DWR application, and it presents a user interface skeleton that will be used to hold the tables and lists sample, and the field completion sample.

The article is divided into the following three sections:

  • Creating a Dynamic User Interface—starts with creating a web project and a basis for samples mentioned in this chapter
  • Implementing Tables and Lists—shows us how to use DWR with them
  • Implementing Field Completion—has a sample for typical field completion
read more...
mail this link | permapage | score:9073 | -Niraja Mulye, December 30, 2008

Import XML into OpenOffice Calc with XSLT

Up
vote
Down

When it comes to importing generic XML into OpenOffice, the user is on his own. This article offers a quick XSLT tool for this purpose and demonstrates the Calc import of records-oriented XML. In addition to learning a practical trick for working with Calc, you might also learn a few handy XSLT techniques for using dynamic criteria to transform XML.
The popular open source office suite OpenOffice.org is XML-savvy at its core. It uses XML in its file formats and offers several XML-processing plug-ins, so you might expect it to have nice tools built in for importing XML data. Unfortunately, things are not so simple, and a bit of work is required to manipulate general XML into delimited text format in order to import the data into its spreadsheet component, Calc.
read more...
mail this link | permapage | score:9071 | -solrac, April 4, 2005

Debugging Shell Scripts

Up
vote
Down

Learning how to find the errors in your shell scripts is an important skill for successful shell scripting. The debug options in the Bash shell can help with that. read more...
permapage | score:9068 | -aweber, February 2, 2012

Programming the Sony PS3 SPE cores under Linux

Up
vote
Down

Take even greater advantage of the synergistic processing elements (SPEs) of the Sony PS3 in this installment of Programming high-performance applications on the Cell BE processor. Part 2 looks in depth at the Cell Broadband Engine processor's SPEs and how they work at the lowest level, while Part 1 showed how to install Linux on the PS3 and explored a short example program. read more...
mail this link | permapage | score:9065 | -Ida Momtaheni, February 21, 2007

Pattern matching in shell scripting

Up
vote
Down

This article is excerpted from the book Beginning Portable Shell Scripting.
Shell programming is heavily dependent on string processing. The term string is used generically to refer to any sequence of characters; typical examples of strings might be a line of input or a single argument to a command. Users enter responses to prompts, file names are generated, and commands produce output. Recurring throughout this is the need to determine whether a given string conforms to a given pattern; this process is called pattern matching. The shell has a fair amount of built-in pattern matching functionality.
read more...
mail this link | permapage | score:9059 | -Ray, January 1, 2009

Tutorial: Linux Dialog Boxes

Up
vote
Down

Dialog lets you create dialog boxes from Unix/Linux shell scripts...
'dialog' is a utility for building console-based 'front ends' in UNIX like operating systems.

In this brief tutorial I am mentioning the usage of few important basic controls available with this 'dialog' utility and later I have created a very simple front end application in UNIX bash scripting using dialog.
read more...
permapage | score:9040 | -Ray, January 1, 2010

Online Ruby Interpreter

Up
vote
Down

Try Ruby online with this online tutorial / interpreter. It runs in your browser.
Ruby is a programming language from Japan (available at ruby-lang.org) which is revolutionizing the web. The beauty of Ruby is found in its balance between simplicity and power.

Try out Ruby code at the prompt above. In addition to Ruby's builtin methods, the following commands are available:
read more...
permapage | score:9017 | -Ray, November 30, 2005

Space Tyrant: A threaded C game project: First Code

Up
vote
Down

First code: This is the first code release of Space Tyrant. This is an early stage of development and, at this point, only implements the listening thread, the two IO threads for each player connection, and a skeletal game logic thread that does little beyond proof-of-concept code.

The design of the code was discussed in this article so you should probably go back and read that article if this is your first brush with this project.

The first code release -- what we will be discussing in this article -- is online as spacetyrant1.c. Download it as well as the shell script you’ll need to compile it: makeit1.sh. The script should work under both Linux and Mac OS X. The code will require a single line change to compile under Mac OS X. Search the code for the string OSX to find the line to decomment and the corresponding line to comment out.

Currently, the program allows multiple people to connect using telnet and echos anything they type to all other connected sessions. Some familiarity with the C programming language will be assumed in this article and those to follow.

Configuration constants: There are several ‘configuration constants’ defined by #define statements. The key constants and their meanings are:

MAXTH: This number represents the maximum number of users that can connect simultaneously. This constant is used to set limits on loops and to define the number of elements in various arrays. This number must be a power of 2.

MAXTHBITS: This is simply the number of bits necessary to form an unsigned int to index into arrays of MAXTH size. This number is used to declare bit fields for use with various items that occur MAXTH times. In the code we use a MAXTH of 256 and since 2^8 equals 256, MAXTHBITS is set to 8. Note that if you change MAXTH, you must make an appropriate change to MAXTHBITS!

MAXBUF: This is the number of buffers used in various places. For example, the input threads each get MAXBUF numbers of buffers.

MAXBUFBITS: This number matches MAXBUF in that it is the number of bits necessary to express the number MAXBUF in the same way that MAXTHBITS relates to MAXTH.

MAXLINE: This is the maximum length (in bytes) that is allowed for network input and output. The IO buffers, for example, are declared to be size MAXLINE + 1. The ‘+ 1’ is to allow room for a terminating 0.

RADPAD: This is added to MAXLINE to determine the length of a radio buffer. Radio buffers need to be larger than IO buffers since they must allow room for headers.

Data structures: Next, we declare a struct to contain most of the data associated with each thread. Note that this struct contains no player-specific data; it is used only to contain the data necessary to define an input thread and an output thread used to define one user connection. ‘threc’, as we will call the struct, will be an array with MAXTH elements. It will contain the thread ID of both the input and output threads, the timestamp of the last input from the input thread, the number of the socket descriptor, and various flags and indexes that will be used to coordinate the activities of the input, output, and game logic threads. Look at the code comments themselves for details on the variables.

Note that MAXBUFBITS is used to declare the size of inndx, outndx, inptr, and outptr. These variables, when incremented past the number of buffers, wrap back to zero, making it easy to implement ring buffers. That is why the MAXBUF number must be a power of 2.

The thread functions: In this program main() has two primary functions. First, it calls any initialization functions and clears the various data structures and spawns any other permanent threads. Second, it goes into an endless loop of accepting user connections and spawning IO threads to handle the newly connected users.

The next thread function, gameloop(), has the hard job. It constantly loops though the input buffers, looks for input that needs to be processed, and does it. While looping around the buffers, it also looks for input threads that have gone idle and terminates (‘reaps’) them. Currently, the only input processing it does to call a function named broadcast() with any data it finds in the input buffers. The broadcast() function simply copies the input to output buffers. This bit of processing is for proof-of-concept purposes only and will be replaced by actual game logic as it is developed.

The last important thread functions, userin() and userout(), exist in multiple pairs to perform network input and output duties for each connected user. The userin() thread reads the network connection and loads data into the next available input buffer (‘inbuf’). It then timestamps it, and goes back to waiting for more input. The userout() thread loops continously waiting for anything to appear in the next output buffer (‘outbuf’). When new data is placed in an output buffer by the gameloop() thread, userout() writes it to the user’s network socket.

Note that because userout() and gameloop() loop continously, they sleep after each ‘idle’ loop. That is, when they pass through their logic loop and find no actual work to do, they call the usleep() function to sleep a tiny fraction of a second. This sleeping prevents them from consuming unnecessary processor cycles.

[Update, June 25, 2005: A Space Tyrant home page has been created as a central index to the various ST articles, links, and files.]
mail this link | permapage | score:8986 | -Ray, March 27, 2005 (Updated: June 25, 2005)

PowerPC assembly language

Up
vote
Down

The POWER5 processor is a 64-bit workhorse used in a variety of settings. Starting with this introduction to assembly language concepts and the PowerPC instruction set, this series of articles introduces assembly language in general and specifically for the POWER5. read more...
mail this link | permapage | score:8976 | -solrac, April 4, 2007

Space Tyrant: A threaded game server project in C

Up
vote
Down

[Update, June 25, 2005: A Space Tyrant home page has been created as a central index to the various ST articles, links, and files.]

[Update, March 21, 2007: A Space Tyrant has its own website! It's small but growing and will provide quick access to the latest code and developments in the ST universe.]

Space Tyrant: Today we kick off a new multithreaded, network socket programming project which we will call Space Tyrant. Our mission is to write an open source, multiplayer, networked, strategy game in the C programming language. The goal of this project is to make a solid code base which implements a simple space trading game upon which other games can then be built. The game will be a subset of The Last Resort (TLR) that currently runs at [offline]. This project will be a learning exercise for me as well as for any interested readers. The current state of the source code will be released with each article update.

The game design: While my TLR game consists of over 25,000 lines of C source code and supports a web interface as well as telnet and a graphical client, this code will be far smaller and simpler. It will initially only support telnet and will implement a far simpler game design.

Players will be able to telnet into the game, create an account, and play in a universe that contains ports, planets, as well as other players. Each player will be issued a starship, some cargo holds, and an amount of starship fuel. Additional fuel will be issued hourly and will accumulate in the starship. Fuel will be used to move the ship between sectors -- locations within the game universe -- and to dock with ports. Once a ship runs out of fuel it can't move at all until new fuel is issued.

Players will be able to buy and sell commodities (Iron, alcohol, and hardware) between the three different kinds of ports. Each port type will sell one of the three commodities and buy the other two. Prices will be based on supply and demand with rarely-used ports offering the better prices.

With the money players earn trading they will be able to buy more cargo holds to make their ships more efficient for trading. They will also be able to buy fighters -- small military drones -- that can be used to attack other ships or deployed to guard a sector and its contents. The fighters carried with a ship will guard it against attacks from other players.

Games will run for a predetermined length of time, then reset and start anew.

The programming model: Now, on to the software design. I've compared and considered various models for the server design. TLR is based on the forking model using inetd or xinetd to handle the listening and forking. While the forking model is inherently distributable to multiple processors, it introduces inefficiencies (forking multiple processes) and makes interprocess communications more difficult and slower.

Next, I considered a non-blocking, single process model. In this approach, one process handles everything in a single thread. It would use non-blocking IO (read and write functions that never wait for completion but, rather, return immediately if they aren't ready to read or write actual data). The thttpd web server is an example of a non-blocking, single process server. It's extremely fast and efficient. However, this model is quite complicated to code, and, I believe would make it more likely to introduce subtle timing bugs.

Next, I considered a pure multithreaded, single process model with a thread for each player. While appealing in many ways, this model would require the same kind of coordination between threads that the forking model requires between processes. Such interprocess communication would be simplified in that the various threads share memory, but the coordination issues otherwise remain the same.

Last, I considered another multithreaded model, this time with only IO threads for each user and a single thread that implements all game logic. While that one central thread might someday be a bottleneck that limits scalability on large SMP systems, it does distribute the IO on any additional processors that might be present, and requires minimal coordination. In short, this model combines the logic simplicity of the non-blocking single process model with the coding simplicity of the threaded model, while separating the IO from the main logic. There will also be two other simple threads in this model. There will be a thread that listens for new connections and spawns the IO threads for each new connection. There will also be a thread that writes the data to disk periodically.

This is the approach that I intend to take for this project. The code will be written for both Linux and Mac OS X.

More info: I have set up an email address for programmers following this series to provide recommendations, bug reports, and other feedback. Send email about this project to spacetyrant [at] librenix.com.
mail this link | permapage | score:8972 | -Ray, March 18, 2005 (Updated: July 26, 2008)

Porting C / C++ code from Windows to Linux / Unix

Up
vote
Down

Software programs are often made to run on systems that are completely different from the system in which the program is coded or developed. This process of adapting software across systems is known as porting. This article shows you how to port your software from one environment to another. read more...
permapage | score:8919 | -BlueVoodoo, September 20, 2007

Build Apps with Android SDK, Eclipse, PhoneGap (Ubuntu 10.10)

Up
vote
Down

This tutorial describes how you can set up a development environment for building Android apps on an Ubuntu 10.10 desktop using Eclipse, the Android SDK, and PhoneGap. I will describe how to build Android apps from the command line with PhoneGap and from the GUI with Eclipse and PhoneGap and how to test them in an Android emulator and on a real Android device. PhoneGap allows you to develop your Android applications using web technologies such as HTML, CSS, and JavaScript (e.g. with JavaScript libraries such as jQuery/jQTouch), and it will turn these web apps into native Android apps (in fact, PhoneGap supports multiple platforms such as Android, iPhone, Palm, Windows Mobile, Symbian, so you can use the same sources to create apps for multiple platforms). read more...
mail this link | permapage | score:8908 | -falko, January 27, 2011

Tutorial: Build your first application with Spring Framework

Up
vote
Down

Learn how to create a simple application on Apache Geronimo using the Spring Framework, a layered Java Platform, Java EE and J2EE application framework. Develop, configure, and deploy your first application based on the Spring Framework. You'll also see how Geronimo's Web Console simplifies deploying and managing Web applications. read more...
permapage | score:8878 | -solrac, October 3, 2006

String matching in regular expressions

Up
vote
Down

Use parentheses to create the string matches you need in regular expressions. Parentheses allows you to use pipes for multiple matches. read more...
permapage | score:8866 | -aweber, September 12, 2011

Mono-culture and the .NETwork effect

Up
vote
Down

Consider a future where Microsoft has succeeded in migrating most Windows development to the .NET framework. With the considerable power that Microsoft wields over corporate desktop computing, the success of .NET is easy to foresee.

Now, imagine for a moment that Mono, following in .NET's footsteps, is also hugely successful. Further, imagine that, in its success, Mono displaces a large portion of traditional Linux software development over the next few years.

I believe that if the above scenario becomes reality it could lead to a disaster for Linux. In such a future, Microsoft would have tremendous leverage over Linux, Linux programmers, and businesses using Linux.

Microsoft can, at a carefully selected time, change key interfaces, sue for patent infringement, and release otherwise standard .NET components that break or obsolete pieces of Mono. They can also use the powers of the DMCA to prevent Mono developers from gaining access to obfuscated components of .NET technology. While hobbyists and Linux-centric companies will be able to withstand such inconveniences (with the possible exception of patent suits, of course), general businesses and organizations will not be able to resist such pressure.

Of course, Microsoft is well aware of how this scenario could unfold and has thought of many more exploitable details than a casual observer such as myself.

Mono, if successful, is a gift from heaven to Microsoft that, when the timing is right, can be used to set Linux deployment back years, or worse, depending on the devastating psychological and economic effects such a maneuver would have on Linux developers and businesses.

For Microsoft, their best strategy to do real damage to Linux is to make it easy for Mono to succeed while carefully laying their traps. They can quietly go about the business of patenting all of the key functions of .NET. Anyone who has followed the trend of software patents must realize that Microsoft could have dozens of patent claims covering .NET before Mono rises to prominence.

Then, Microsoft need only wait. The optimum time to shut down Mono will be after much Linux development has committed to it. By then, Mono technology will have infected many projects. Perhaps worse, it will be easier for Mono programmers to simply switch platforms and become Windows developers rather than learn alternative methods and tools of Linux development. Programmers have to eat and software development houses must pay the bills. In such a scenario, there is not a year to burn while everyone ramps up their skills with new tools and practices.

Meanwhile, businesses will be forced to abandon any Linux packages that are .NET-encumbered. Since a .NET version of each Mono-based program would already exist, it would take only a few such packages to convince a business to migrate off of Linux. The headaches of replacing such packages under Linux need only exceed the alternative headache of simply switching to Windows.

A company with their own custom Mono-based software would have fewer options. Microsoft, however, would likely provide an easy solution; simply move the Mono software to .NET and it will all be legal.

I am not the first person to have thought about this. Several Slashdot users have posted cautionary messages about developers placing their trust in the good intentions of Microsoft. [1, 2, 3, 4, and 5].

Dave Winer also seems to wonder about Microsoft's oddly open behavior:
The first clue should be that Microsoft is not protecting the source of .NET, in fact they're publishing it, with some constraints, but if you want to see how they do it, they say there will be no mysteries and no poison pills. So they're making it not impossible to clone. Why are they being so generous? (A little sarcasm, sorry.)
Even Miguel de Icaza1, the founder of the Mono project, acknowledges the compatibility hazards:
If Microsoft decided to make our life really hard in terms of compatibility, it would also hurt its own customers. If it changes the APIs, that affects its customers as well. So I think the APIs will remain fairly stable, and I hope that Microsoft won't go into proprietary protocols or protocols that would make it really hard for us to implement Mono. There's is always the possibility it will do so. Microsoft has some strange patterns in terms of how it competes. I really hope it will "behave like a good citizen," as Steve Ballmer said recently it would.
What I've described here is probably a worst-case scenario; in all likelihood Mono will not be so successful as to cause a large problem for Linux if and when Microsoft decides to kill it. However, even in a favorable sequence of events, Microsoft will still hold the power to cause a large amount of open source effort and code to be lost.

1. Miguel rebuts one of my points here.
mail this link | permapage | score:8862 | -Ray, October 13, 2003 (Updated: October 14, 2003)

Why Programmers are not Software Engineers

Up
vote
Down

People toss about the term 'software engineering' as if programming were just another engineering discipline.

Programming is 100 percent design. And that design is vastly more complex than the typical true engineering effort of comparable cost. Said another way, an engineering project of similar logical complexity to a software program is far more expensive.

Much of the reason for that low cost is that programming has no comparable build phase that, in some other field, might consume the vast majority of the total cost.

Programming is dramatically cheaper than a similarly complex physical project.

Programming doesn't fail in the same sense that an engineering project can fail. Programs never fail because of faulty materials or shoddy workmanship -- except in the compilation phase, perhaps, but in that case the program doesn't even exist. Programs don't fail because of use beyond their rated capacities, although they may fail because they foolishly accept input or a load beyond their capacities.

Programs only fail due to design flaws.

Ignoring terminology for the moment, the reason that software quality is so much lower than one might expect is fundamentally economic. The 'engineering' phase, the design, represents nearly the entire cost of the actual development. The only place where costs can be shaved is design. The building blocks of the actual construction, opcodes, are essentially free.

Software doesn't meet engineering standards, largely for economic reasons.

And, lastly, an engineer is one so designated by government. With that title comes certain legal responsibilities. 'Software engineers' are neither designated as such nor are they held to engineering standards.

Engineer is a title conferred by the state and it may not even be legal to call yourself a 'software engineer'.

On the other hand, the best programmers I've met don't call themselves engineers at all. They call themselves programmers, coders, and hackers. Evidently, there is no shame in that. Let's leave the engineering title to those who have earned it and accept the responsibilities that come with it.

We should be thankful that we aren't held legally responsible for the performance of our designs.
mail this link | permapage | score:8840 | -Ray, November 25, 2002

Tutorial: Write your own operating system

Up
vote
Down

A rather ambitious tutorial.
Writing an operating system is something that can not only be interesting (if you're one of those people that get turned on by Int 13....) but it is also a great learning experience. Through creating your own operating system you will learn exactly what goes on behind the scenes, elevating you above the average programmer...
[In addition to the tutorial linked from [read more] below, you might also be interested in this FAQ on developing your own OS. -Ed] read more...
mail this link | permapage | score:8831 | -Ray, June 18, 2003 (Updated: August 24, 2008)
More coding articles...
Gallery Wrapped Abstract Art

coding headlines

I wrote my first programming e-book: Awk One-Liners Explained

Tutorial: UDP socket based client server C programs

Tutorial: Write a Qt program with Qt Designer

Java: Real numbers

Tutorial: Android app development environment on Debian 6

Tutorial: MySQL Select statement

PHP: Associative Array Tricks

Why software sucks

Review: DevelopGo: A Linux Live CD for Programmers

Create native looking Firefox web apps

Development tools: Autotools vs. CMake

Quick and Dirty Vimdiff Tutorial

PHP vs. ASP

Tutorial: Android development environment on Fedora 14

13 Regex Features

Command line functions

Ten more One-Liners from CommandLineFu explained

Secure String Coding in C and C++

Python for Kids

Programming Language Tradeoffs: 3GL vs 4GL

BASIC for Linux

Parsing a Web Form with Shell Scripts

Tutorial: Install the Aptana AJAX IDE on Ubuntu

Tutorial: Write a PHP wiki

Tutorial: MySQL Linux C API

Tutorial: Install SVN, Configure multi-protocol access (Ubuntu 11.10)

Tutorial: How to use named pipes

Art animation with the Java 2D API

Best practices for XML in Java programming

The life cycle of a programmer

Java J2EE Tutorial: Secret Santa Web Application

Vim Plugins: ragtag.vim

Book Review: Invent Your Own Computer Games with Python, 2nd Ed.

Dzil: a casual walkthrough of Dist::Zilla

strace tutorial

Tutorial: Multithreaded Programming with pthreads

The Vim Scripting editor

Perl tips

HTML5: Drag and Drop to a webpage

libhugetlbfs: Using transparent pages on Linux

 

Firefox sidebar

Site map

Site info

News feed

Features

Login
(to post)

Search

 
Articles are owned by their authors.   © 2000-2012 Ray Yeargin