Archive

Archive for the ‘Tips’ Category

List Users in a Linux Server

April 19th, 2010 Frank No comments

At some point during the weekend, I needed to pull a list of existing users on my Linux server. While I expected this to be a trivial task, it took me sometime to come up with the solution.

Part of the problem, ironically, is that it is easy to do but done in an unexpected way. Basically, you accomplish it via the passwd file.

Simply execute the following (on the console, as this is a server and I wouldn’t expect it to have a GUI).

cat /etc/passwd

I originally pulled this information from: http://www.linuxquestions.org/questions/linux-software-2/get-a-list-of-linux-users-179102/

Note: I didn’t definitively explore all of the possible ways one could accomplish this. Once I found this method that effectively gave me the information I was after, I quit looking. If you have additional methods, please post a comment below and I will work it in to the article citing you (and linking to your site) as the source. I would truly appreciate any and all additional methods — even if specific to a distribution.

Categories: Random, Tips Tags: , ,

Common Linux Server Administration Commands Summary

April 19th, 2010 Frank No comments

One of the most difficult aspects of starting to use Linux– a server distribution in particular — is remembering all of the different command line programs that exist in order to aid your work.

Obviously, man is a great reference but that is actually difficult to use when getting started as it itself is a command line program. I was searching for a command to list all of the users on a system (I found it and will post a brief article on that soon) and I stumbled across this, so I wanted to share it (as well as retain it for future reference.)

http://www.reallylinux.com/docs/admin.shtml

This covers such things as:

  • Networking information / status (arp, ifconfig, netstat, etc)
  • File system information (df)
  • Disk Size / utilization information (du)
  • How to search for files with find
  • Easy-to-use console text editors (nano, joe)
  • Process management / information (ps, top)

In addition to listing the commands, it lists common usage scenarios and command line flags of note.

Violet UML Editor

March 2nd, 2010 Frank No comments

I use UML to do quick brain storming and when exploring software. While I’ve not posted many write ups here (grad-school!),  I generally don’t want to invest a lot of time in my UML diagrams and only sometimes do I even want to save them.

Often times, especially lately, I’ve been drawing on a whiteboard that I keep in my office.  I find this to be efficient (even over paper because I’d end up throwing it away).

OO Design & Patterns, 2nd Ed Book CoverIn one of my current grad-school classes, we are using “Object-Oriented Design & Patterns” by Cay S. Horstmann as the class text book. I’ve enjoyed the book and it provides some decent examples. I bring the book up because apparently the author of the book created a UML package called Violet UML. I’ve found this to be the best software based UML brain-storming software I’ve ever found. Here are my reasons:

  • It loads quickly
  • I can efficiently draw diagrams without warnings or complex menus to navigate though.
  • The lack of UML rules enforcement means that I can draw partial diagrams; diagrams that mean nothing out of context.
  • It’s open source
  • So far, its more stable / reliable to ArgoUML

If you are looking for a UML package, I must recommend this. I searched and searched for a UML package a while back and I never came up with this. I looked at everything, no matter what and still never found it. So, if you like it, please spread the word (via your own blog, twitter, facebook, etc). I think it is well done software and worth some attention.

http://violet.sourceforge.net/

ORM patterns which are ‘Invisible to the eye’

February 10th, 2010 Frank No comments

The more I work with design patterns*, the more I come to respect them as a design tool. For grad-school, I’m writing a DVCS and I needed some information on ORM patterns. While I’m not sure if this is a real term, I Googled it and found a great article on Invisible to the eye.

The article can be found at: http://giorgiosironi.blogspot.com/2009/08/10-orm-patterns-components-of-object.html

For my project, I’m mainly interested in the Data Mapper and the Table Data Gateway. Both are patterns from Martin Folwer’s book Patterns of Enterprise Application Architecture.

While I’ve not read the book yet, I think I might… After classes…. Anyway, I mostly wanted to share on the 10 ROM patterns listed at Invisible to the eye.

*If  you’d like a good intro to design patterns, I love Head First Design Patterns

Invisible to the eye

Using COALESCE to Build Comma-Delimited String directly in SQL

October 27th, 2009 Frank No comments

The following article covers a great should-know piece of information for any SQL Server developer. Though, comma delimited strings are not usually desired in database, it can be nice to receive data this way for things like embedding in to a query string or passing over a web service*.

http://www.sqlteam.com/article/using-coalesce-to-build-comma-delimited-string

*I don’t necessarily suggest the web service idea. I was just saying for illustrative purposes…

Categories: SQL Server, Tips Tags:

Python Memory Performance

October 8th, 2009 Frank No comments

I’ve been studying Python because it is extensively used in open source projects to script certain types of work or actions. I think Mozilla uses it to verify build time requirements, for example.

But, python itself is a full fledged programming language — not really a scripting language. In fact, Mercurial is written in Python which at first amazed me.

So, anyway as part of my pursuit of studying Firefox, I thought I should (at least) learn the basics of Python so that I could read any relevant scripts. Python is quite different from other languages I’ve encountered.

One thing I started to notice about python is that it seems to use more memory. I’m not sure, nor am I suggesting that it uses more than other languages. I just noticed that memory consumption seemed to grow rapidly when running a python script.

The following article seems to explain why. Instantiating a class is expensive. According to the article, a class is 336 bytes. Since in general, a class will use multiple other classes, I can see why memory consumption was growing rapidly.

Ultimately, I don’t think it matters. You just need to be aware that it happens. A modern computer will run the script without any notice to this phenomenon. You’d need to create a lot of objects to cause a problem. But I do beleive it is worth acknowledge that it happens so that you can be aware of the memory usage. It’s mostly noticeable on my work computer (the company provided) which only has 1 GBs of RAM (it runs Windows XP).

http://www.valuedlessons.com/2008/10/blog-post.html

Categories: Python, Random, Tips Tags:

Debug VBScript with Visual Studio

May 21st, 2009 Frank 13 comments

For a project that I work on at at my primary employer, we use VBScript inside of DTS packages. Until this project, I’ve not had too much experience with VBScript. What I’ve found most frustrating about the language is the inability to step though the code… until a recent discovery. I’ve found that if I save the target code to my local machine as a VBS file and execute it with WScript.exe, I can attach a debugger to it.

I’ve discovered this by poking around and I don’t know too much about WScript.exe. I’m sure if you Google it, you can find more about it.

For this to work, you’ll need a copy of Visual Studio installed. I am not sure if any of the express editions will work. Drop a line in the comments if you find it will. As a quick walk though:

  1. Save your code as a VBS file. Don’t forget to call Main (or your main) function as wscript won’t automatically call main.
  2. Open a command prompt.
  3. Navigate to the location of the file.
  4. Type: WScript.exe FileName.vbs //D //X
  5. You should be prompted to select a debugger, select a new instance of either Visual Studio 2003, 2005 or 2008.
  6. Visual studio will open up and break at the very first line.
  7. Step though the code.

For an example, save the following as “Example.vbs” on your desktop.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
MsgBox "Starting Script!"
Dim i : i = 0
Const C_Max = 100
Dim sPrimeNumberList : sPrimeNumberList = "Prime Numbers: " & vbCrLf
For i = 0 to C_Max
  If IsNumberPrimeNumber(i) Then
     sPrimeNumberList = sPrimeNumberList & cStr(i) & ", "
  End If
Next
MsgBox sPrimeNumberList
MsgBox "Script Completed."

Public Function IsNumberPrimeNumber(ByVal iNumber)
Dim bIsPrime : bIsPrime = True
For j = 2 To iNumber\2
  bIsPrime = iNumber Mod j > 0
  If Not bIsPrime Then Exit For
Next
IsNumberPrimeNumber = bIsPrime
End Function

Open a command prompt and navigate to your desktop:

Command Prompt for Debugging VBScript from Visual Studio

Command Prompt for Debugging VBScript from Visual Studio

Once there, type in the following:

1
 wscript Example.vbs //D //X

You should then be presented with a dialog similar to the following:

Visual Studio Debugging VBScript

Visual Studio Debugging VBScript

Once you make a selection, you should get something like the following:

Debugging VBScript from Visual Studio

Debugging VBScript from Visual Studio

From here, I’ll assume you are familiar enough with Visual Studio to play with the debugger and learn how it works. When debugging VBScript, I’ve found that you don’t have all the options that you might be used to such as Step In To, but for me simply having this much is a life saver.

To get around the step-in-to thing, I simply use Run to Cursor. It works like a charm.

Update: I just found that (at least on this computer) and in Visual Studio 2003, I have all my standard code-stepping buttons available. I’m not sure why on my work computer I only have Step-Over but either way, this is still a life saver.

Object Relational Mapping > A ‘Design Pattern’ Solution

April 23rd, 2009 Frank No comments

There has been a lot written about Object Relational Mapping — or ORM but I came up with a design that I intend to apply to my own projects and wanted to publish and share the idea.

This idea was my own; when I wrote this I hadn’t seen this idea published elsewhere. However, the idea is derived from a set of very common design patterns. It would not surprise me in the least if another designer/developer already implemented a similar idea. However, I digress…

Preliminary Information

The ORM is a method to take data stored in a relational database-type structure and represent the same data as object orientated classes.

I feel that the ten thousand foot level the idea is straight-forward. Assume that we are using the MVC (Model-View-Controller) design pattern for your application. Furthermore, lets assume that we’ve got a simple object to which will represent our Model (part of the MVC).

Lets assume our model object is the following:

Data Model Example

Data Model Example

The idea is to take a mix of the strategy and the decorator pattern. The strategy pattern is a design pattern that allows you to define the interface for an algorithm which can be different depending on the implementation.

The idea of the decorator pattern is to simply add responsibility to a class (through inheritance). My ORM is a combination of the two patterns.

The Design – a Class Diagram

The pattern is simple.

Diagram with OR Design

Diagram with OR Design

We use the interface to represent the ability to write out or read in with the Encoder. You’d implement the interface on to a derived class of the target class.

Why do we implement this interface on a derived class? Strictly speaking, we don’t have to. Though, this is intentional and part of the pattern that I’m trying to describe. This is the part of the strategy pattern working for us. This would allow us to implement different encoders for different types of storage mediums.

This means that we could create a set for SQL server, XML and perhaps a web service if so inclined.

Usage

The usage, I imagine, to be simple. Setup your basic interface and then derive a target class and apply the interface. Implement your interface to write the object and read the object to/from your storage medium.

One point of doing this, is that if a model object contains a collection  or an instances of another model object, you can use this interface to write and retrieve that object.

An Example

In all honesty, I had hoped to put together a simple but working example of this. I’ve not had the time and I’ve been sitting on this post for a while. I wanted to get this post out. I still hope to get together a simple example but for the time being the description is all I’m posting.

If you have specific interest in an actual implemention of my concept here, please leave a message below. The interest will help modivate me to take the time to get something together.

“Windows OOP” vs. “Cocoa MVC”

March 23rd, 2009 Frank No comments

While I don’t agree with the following article that windows developers (the author is looking at .NET, I believe) can’t implement the MVC design pattern, I do agree with the article that MVC is probably a better way to implement one’s interface. I want to direct your attention to the following article.

http://www.cimgf.com/2008/07/29/cocoa-tutorial-windows-oop-vs-cocoa-mvc/

CLR (.NET) Strings in Memory

February 25th, 2009 Frank No comments

The following is an interesting article related to how .NET handles strings. I’m not sure if the same thing might apply to Java; I’d be interested to find out.

Anyway, I’m posting this here for safe keeping and to share it…

http://www.simple-talk.com/community/blogs/jcrease/archive/2009/01/16/71678.aspx

Categories: .Net, Coding Tip, Technologies, Tips Tags: , ,