Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

April 22, 2014

StackOverflow Like Pagination

Some while ago, I built a pagination system in PHP to display a long list of pagination links. The pagination system showed at most 5 links at a time and additional links were represented by ellipsis (...). However, I was not able to deal with certain edge cases, so I drew some inspiration from the pagination system used on StackOverflow to tackle them. This is what the end result looked like:

Pagination using ellipsis

October 17, 2009

VBScript Ceil and Floor Functions

VBScript does not have native Ceiling and Floor functions. In order to use these function in your financial or mathematical applications, you will have to write your own VBScript implementation. By definition:

The ceiling and floor functions map a real number to the next largest or next smallest integer. More precisely, ceiling(x) is the smallest integer not less than x and floor(x) is the largest integer not greater than x.

So here is the VBScript implementation of these two functions:

July 14, 2009

Export MySQL Data to CSV Using PHP

15 minutes into writing this article, I realized that PHP 5.1 now includes the fputcsv function that was missing from earlier versions of PHP. It formats a line (passed as a fields array) as CSV and write it (terminated by a newline) to the specified file handle. However, it is not properly documented what exactly is the "newline" character; is it CR, LF or CRLF.

I have a habit of re-inventing the wheel, so I've put together a substitute for this function that echoes the CSV data instead of writing to a file and (tries to) closely follow the recommendations described in RFC 4180.

July 9, 2009

Export Recordset Data to CSV Using ASP/VBScript

The CSV (Comma-Separated Values) file format is a text file format in which you can store tabular data, such as data from a database table. This format is can be read by various spread sheet programs such as Microsoft Excel and OpenOffice.org Calc. This format is not suitable for storing binary data.

The following ASP/VBScript code sample allows you to export data from a database table to a CSV file. The code accesses the table through an ADODB Recordset object, formats the data into the CSV format and sends the data to the browser along with appropriate response headers. This code should be saved as an ASP script on a webserver. You should see an "Open/Save As..." dialog when you access the script through a web browser.

June 23, 2009

Generate Random Strings Using ASP/VBScript

This is a simple yet highly customizable function that allows you to generate random strings using VBScript that you can use in your ASP/VBScript applications. The random strings can be used for various purposes, including:

  • Login Systems
    • Random password for new registrations
    • Random password for users requesting password reset
  • Referral Codes
  • Promotional Codes
  • Primary Keys for tables where using integers as primary keys is not desirable

The following code is a VBScript translation of the php random string function I wrote earlier. It generates an 8 character long random string that contains 1 digit:

June 22, 2009

Generate Random Strings Using PHP

This is a simple yet highly customizable function that allows you to generate random strings using PHP. The random strings can be used for various purposes, including:

  • Login Systems
    • Random password for new registrations
    • Random password for users requesting password reset
  • Referral Codes
  • Promotional Codes
  • Primary Keys for tables where using integers as primary keys is not desirable

The following code example generates an 8 characters long random string that contains 1 digit:

May 19, 2009

List Images and Other Files Types in a Directory Using ASP

This is a nice and simple ASP+VBScript code snippet that lists the files present in the specified directory (folder). The ready-to-go example below displays the list of images. However, the code can display files depending on filename extension. The script also returns additional information about the files such as type, size and date modified.