Archive for July, 2009
How to select the First row from a MySQL table
Posted by Rui Miguel Feio in MySQL on July 6th, 2009
You can use the following command to get the first row from a MySQL table:
SELECT * FROM table LIMIT 1
Explanation:
table - table name
By limiting the returns to 1 (LIMIT 1) we get the first row from the table.
Example:
SELECT * FROM tusers LIMIT 1
How to select the Last row from a MySQL table
Posted by Rui Miguel Feio in MySQL on July 6th, 2009
You can use the following command to get the last row from a MySQL table:
SELECT * FROM table ORDER BY field DESC LIMIT 1
Explanation:
table - table name
field - table field
This command orders the table by DESCENDING order and limits the number of rows returned to 1. Since DESCENDING reverses the normal table order, we get its last row.
Example:
SELECT * FROM tusers ORDER BY user_id DESC LIMIT 1
Select random rows from a MySQL table
Posted by Rui Miguel Feio in MySQL on July 6th, 2009
If you ever come across the need of randomly select rows from a MySQL table:
SELECT * FROM table WHERE field1 = value ORDER BY RAND() LIMIT x
Explanation:
table - table name
field1 - table field
value - value you want field1 to be
x – number of rows to return
Example:
SELECT * FROM tusers WHERE active_user = ‘Yes‘ ORDER BY RAND() LIMIT 10
This command returns 10 random rows of active users from table tusers.
The 12 Principles Of Successful Freelancing
Posted by Rui Miguel Feio in Business on July 5th, 2009
This was taken from the book “The Principles Of Successful Freelancing” authored by Miles Burke (which I highly recommend) and should be used as guide lines to your sucessful freelancing career:
- Get Organized – Keep your workspace tidy and plan ahead (short- and long-term).
- Control Stress – Remain calm and work through issues to avoid early burnout..
- Research – Spend quality time researching your proposed business-it’s more than a five minute web surf.
- Be Passionate – Love your work! You should enjoy what you do for a living.
- Budget – Save for a rainy day rather than spend every cent as it comes in.
- Value your Health – Bad health stops you from working. Take time to exercise and maintain a nutritious diet.
- Embrace Selling – Enjoy the sales challenge-it’s easier than you think!
- Satisfy Customers – Don’t do average work-exceed their expectations and make them need you.
- Grow Your Network – Value family and friends’ support, and meet new people all the time.
- Maintain Cashflow – It’s what is in the bank that counts, not what you are billing-understand the difference.
- Continually Learn – Keep acquiring new skills and knowledge, every week. Let it slip and you could be left behind.
- Achieve a Work/Life Balance – Your life should be more than work-maintain a good balance for health and success.
How to check if an LPAR is part of a SYSPLEX?
Posted by Rui Miguel Feio in MVS on July 3rd, 2009
If you need to check if an LPAR is part of a SYSPLEX or the SYSPLEX name it belongs to simply issue the command: D XCF
Example:
D XCF
Returns:
RESPONSE=TST1
IXC334I 09.32.10 DISPLAY XCF 309
SYSPLEX TESTPLEX: TST1 TST2 TST3
Notes:
- the command was issued from LPAR TST1
- in red we can see the SYSPLEX name (TESTPLEX)
- in blue we can see that 3 LPARs (TST1, TST2 and TST3) are part of the SYSPLEX TESTPLEX
How to know which IODF file is currently being used?
Posted by Rui Miguel Feio in MVS on July 3rd, 2009
If for whatever reason you need to know which IODF file is currently being used by the system, just issue the command: D IOS,CONFIG
Example:
D IOS,CONFIG
Returns:
RESPONSE=TST1
IOS506I 10.18.20 I/O CONFIG DATA 118
ACTIVE IODF DATA SET = SYS1.IODF19
CONFIGURATION ID = TEST01 EDT ID = 00
TOKEN: PROCESSOR DATE TIME DESCRIPTION
SOURCE: CMOS03 08-02-19 14:05:33 SYS1 IODF19
ACTIVE CSS: 0 SUBCHANNEL SETS CONFIGURED: 0
CHANNEL MEASUREMENT BLOCK FACILITY IS ACTIVE
As you can see LPAR TST1 is currently using IODF file SYS1.IODF19
Pro PHP Security – Review
Posted by Rui Miguel Feio in Books on July 3rd, 2009
PHP being such a popular and versatile scripting language it’s natural that security is not to be taken lightly.
There are thousands of web sites in the internet dedicated to this subject as well as dozens of books. Finding the right one… now that’s a challenge!
“Pro PHP Security” is probably one of the best. I warn you however, that sometimes it can be a tiresome book if you intend to read it from page 1 to the last one.
I say this because it details encryption methods, secure network connections and the likes that for a PHP developer it can be boring.
Lets face it, there are already encryption functions available and the need to know exactly and in detail how each encryption method works can be questionable.
However, no one forces you to read the entire book. You can skip the not so interesting parts and go directly to the good stuff.
The last two parts of this book (part 3 – Practicing Secure PHP Programming and part 4 – Practicing Secure Operations) are the crown jewels of this book, with lots of tips and PHP examples.
This book has the following Parts and Chapters:
- PART 1 – The Importance of Security
- Chapter 1 – Why Is Secure Programming a Concern?
- PART 2 – Maintaining a Secure Environment
- Chapter 2 – Dealing with Shared Hosts
- Chapter 3 – Maintaining Separate Development and Production Environments
- Chapter 4 – Keeping Software Up to Date
- Chapter 5 – Using Encryption I: Theory
- Chapter 6 – Using Encryption II: Practice
- Chapter 7 – Securing Network Connections I: SSL
- Chapter 8 – Securing Network Connections II: SSH
- Chapter 9 – Controlling Access I: Authentication
- Chapter 10 – Controlling Access II: Permissions and Restrictions
- PART 3 – Practicing Secure PHP Programming
- Chapter 11 – Validating User Input
- Chapter 12 – Preventing SQL Injection
- Chapter 13 – Preventing Cross-Site Scripting
- Chapter 14 – Preventing Remote Execution
- Chapter 15 – Enforcing Security for Temporary Files
- Chapter 16 – Preventing Session Hijacking
- PART 4 – Practicing Secure Operations
- Chapter 17 – Allowing Only Human Users
- Chapter 18 – Verifying Your Users’ Identities
- Chapter 19 – Using Roles to Authorize Actions
- Chapter 20 – Adding Accountability to Track Your Users
- Chapter 21 – Preventing Data Loss
- Chapter 22 – Safely Executing System Commands
- Chapter 23 – Handling Remote Procedure Calls Safely
- Chapter 24 – Taking Advantage of Peer Review
“Pro PHP Security” should be one of the books in your bookshelf if you want to develop Secure PHP scripts.
The Principles Of Successful Freelancing – Review
Posted by Rui Miguel Feio in Books on July 2nd, 2009
When I first saw this book I must confess it got me curious. I read some reviews (which were good) and I decided to give it a shot and buy it.
When I got the book (yes, because I buy most of my books online) I gave it a cursory glance and decided to drop the book I had been reading to start this one.
I don’t have much free time to read a book in one day or just a few hours but this one was quick. It took me three days and I must tell you, what a great book!
It gives you a realistic approach on how to become a freelancer, what to consider, what to avoid, and what you should do to succeed as a freelancer.
The book presents you with advantages and disadvantages of freelancing which are of great value.
This book is of easy reading and it’s less then 200 pages which is great!
This book has the following chapters:
- Considering Freelancing?
- Prepare for the Transition
- Manage Your Money
- Set Yourself Up
- Win the Work
- Give Great Service
- Achieve Work-Life Balance
- Where to from Here?
I strongly recommend “The Principles Of Successful Freelancing” if you’re considering becoming a freelancer or if you’re already one and would like to check if you’re doing it right.
How to dynamically add or remove libraries from APF list
Posted by Rui Miguel Feio in MVS on July 2nd, 2009
Countless times I’ve been asked if I remember the command to dynamically change the APF list.
Well, I’ve decided to include it here so that next time someone asks me I can tell them to come here.
Now, this can be done in many different ways but I normally follow this path:
1. Add/Remove just a few libraries to APF list
If the number of libraries we’re talking is not much, then we can do it by issuing the following commands for each of the libraries (datasets):
To add: SETPROG APF,ADD,DSNAME=dataset_name,VOLUME=volser
To remove: SETPROG APF,DELETE,DSNAME=dataset_name,VOLUME=volser
Notes:
- If the datasets are in an SMS managed volumes then instead of VOLUME=volser it should be SMS.
- If the system is IPLed and you did not reflect the changes to your PROGxx member in PARMLIB then these changes will be lost.
2. Add/Remove lots of libraries from APF list
If we’re talking of a considerable number of libraries then the best way is to update the PROGxx member of PARMLIB and then activate it dynamically.
Let’s assume:
PARMLIB: SYS1.PARMLIB
PROGxx: PROG00
In this case we would do the following:
- Update SYS1.PARMLIB(PROG00) and add/remove the libraries from APF list
- Issue command: SET PROG=00
How to validate an email address format
Posted by Rui Miguel Feio in PHP on July 2nd, 2009
There are several ways of validating an email address format.
Normally, I do it the following way:
1. I first define the regular expression for the email format:
define (“FORMAT”,”^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$”);
2. To validate the email address provided is correct:
if ( !eregi (FORMAT, $email)) echo “The email provided has an invalid format”;
Regular expressions can be a pain to understand and if it’s hard for you then I would recommend you read “Sams Teach Yourself Regular Expressions in 10 Minutes” from Ben Forta.
If however you are simply interested in some practical examples that you could use then I recommend “Regular Expressions Cookbook” from Jan Goyvaerts and Steven Levithan.

