C# method to mimic PHP file_get_contents
Here is a nifty little function that I wrote to mimic the PHP function file_get_contents. This C# method will read the string contents of a regular file, or a file from a URL (the response from a http request, not the actual file itself).
Notice you have to convert the byte array results to ASCII using the System.Text assembly.
note:
You might be able to read the actual file from the webserver if you replace the DownloadData method on the webclient object to DownloadFile, but this is purely speculation. This kind of action would be useful if you wanted the actual script file not the results from it.
/// <summary>
/// Will return the string contents of a
/// regular file or the contents of a
/// response from a URL
/// </summary>
/// <param name="fileName">The filename or URL</param>
/// <returns></returns>
protected string file_get_contents(string fileName)
{
string sContents = string.Empty;
if (fileName.ToLower().IndexOf("http:") > -1)
{ // URL
System.Net.WebClient wc = new System.Net.WebClient();
byte[] response = wc.DownloadData(fileName);
sContents = System.Text.Encoding.ASCII.GetString(response);
} else {
// Regular Filename
System.IO.StreamReader sr = new System.IO.StreamReader(fileName);
sContents = sr.ReadToEnd();
sr.Close();
}
return sContents;
}
HOWTO Get the last day of the month with SQL
Have you ever needed to find out what the last day of the month was with SQL. Lets say you needed to round up a date to the last day of the month… I found this necessary when writing a HR Benefits extract… They needed the benefits end date to be the last day of the month, so there was no lapse in medical coverage.
This will get you the actual day number
SELECT DAY(DATEADD(DAY,-1, DATEADD(MONTH,1, DATEADD(DAY,1-DAY(@d),@d)))) AS 'Last day of the month'
If you want the full date just remove the outer DAY function
see http://www.extremeexperts.com/SQL/Tips/DateTrick.aspx for more ways to do it
Quest Collaborate 2006
Quest collaborate 2006 just finished up here in Nashville Tennessee. Some of the highlights:
- Support for EnterpriseOne XE until 2013
- The new tool sets for EnterpriseOne include a web services interface
- EnterpriseOne 8.12 is now available
- The first version of Fusion will ship in 2008
side note: The GL Company has a cool tool called, oddly enough, GL Inquiry… this tool is huge for accounting, job cost, and procurement. They are coming out with a payroll module at some point as well. As a programmer, this product is simple, really simple… in fact with a good grid control, one could easily write a simular inquiry tool in just a matter of weeks… (hmmm…. i might be able to squeeze it into a few weekends ) … so on that note, I have a hard time swallowing the high price tag on this product.
Querying Data From JDE World or Co-Existance OneWorld XE
Here is a short list of resources and some short examples of how to query or extract data from JD Edwards World or OneWorld XE (ExterpriseOne), this also applies to most databases on an iSeries AS/400.
First a warning. Whenever you have direct SQL access to any database you have the power in one accidental enter key press when you ment to press a backspace, and bam! you’ve wiped out your production address book. And whats more older versions of DB2 do NOT incorporate SQL transactions… so you cant rely on the old ‘begin tran / rollback tran’ safety method. you can however use the block comment method to keep your risky updates/deletes away from the sql interpreter (/* */) until your ready for them.
Additionally, JDE in my experiance is very picky about its data, so think twice before you decide to insert or update, and be prepared to restore your database (or at least that table)…
Ok so heres what you need to get on a AS/400 (iSeries) DB2 database.
- A user account with ODBC access to the AS/400
- A good knowledge of the SQL command language
- IBM Client Access installed on your Windows PC (make sure the ODBC and OleDB drivers are installed)
- if you are not on a windows pc you’ll need to find another driver for accessing your iSeries
- A Query Tool
- DB2 SQL Reference Manual, and a DB2 SQL Programming Manual
- Usually you want to turn on the ‘Translate CSSID’ option in your SQL Connection string or your ODBC connnection profile.
Otherwise youll see what looks like garbage for strings, actually this is the database returning the data back in byte arrays.
Do you know what you want to query from JDE, and want to know what the SQL statement is?
Just post your question here as a comment… I will be more than happy to answer what I can.
EnterpriseOne SQL Samples
Here are some JDE EnterpriseOne (OneWorld) SQL examples for extrating various data.
General Ledger
select * from F0911usually you will want to select only posted records, do this by adding a
where glpost='P'
to the end of the statement
Purchasing Headers / Subcontract Headers
select * from f4301
Purchasing Detail / Subcontract Detail
select * from f4311
usually you will want to select only purchase order or subcontracts that are in a ‘printed’ state.. youll need to see what status code your system is setup for printed status po’s here is an example of ours
select * from f4311 where pdnxtr >= '440'
Accounts Payable
select * from f0411
Address Book
select * from f0101
Sometimes I laugh, and don’t know why
http://www.theregister.com/2006/03/09/apple_tv/
I love google’s stuff, but leave it to the register to put everything in perspective
I especially like this line
“the Google Video Store looks like it was designed by a hemorrhaging five-year-old with a predilection for the small box of crayons and bad code.”
Converting Julian Date to .NET DateTime
Want to convert a Julian Date to a .NET DateTime? Heres an easy (C#) way to do that
///<summary>
/// Will Convert a 7 digit Julian Date to a .NET DateTime.
/// 7 digit Julian dates are common in some legacy applications
/// such as JDE World, OneWorld, EnterpriseOne. You can easily make this
/// convert 8 digit julians (more common) just by removing the line that adds
/// 1900000 to the input date.
///</summary>
public static DateTime JulianToDateTime(int julianDate)
{
int RealJulian = julianDate + 1900000;
int Year = Convert.ToInt32(RealJulian.ToString().Substring(0,4));
int DoY = Convert.ToInt32(RealJulian.ToString().Substring(4));
DateTime dtOut = new DateTime(Year,1,1);
return dtOut.AddDays(DoY-1);
}
Converting Videos For Tivo ToGo using FFMPEG
In order to use the Tivo ToGo (galleon calls this the GoBack) feature, your video files not only need to be mpeg files, but they need to meet DVD standards. Here is what tivo recommends. Note: you may be able to encode your files in AC3 even if you are on a standalone tivo (not just the DVD burner tivo’s).
I found a really easy way (and free) to integrate the conversion into your Windows Explorer.
Software Requirements:
- Extract FFMPEG to a folder (like c:\cmdutils)
- Either create a folder for moviesForTivo or edit the next line so that the output files go into the standard c:\tivo recordings directory
- start notepad and paste this text into it
c:\cmdutils\ffmpeg.exe -i %1 -target ntsc-dvd -b 2500 -s 352x480 -hq -ab 160 "c:\data\MoviesForTivo\%~n1.mpg"
Dissecting the actual command line here for FFMPEG
ffmpeg.exe -i %1 -target ntsc-dvd -b 2500 -s 352x480 -hq -ab 160 "f:\data\MoviesForTivo\%~n1.mpg"
This command will produce a MPEG-2 file that is encoded with AC3 as the audio codec (this works on my standalone tivo)
Then all you have to do is associate this to your .AVI’s and .MOV’s and anything else you want to be able to convert from.
RSS for Corporate Data / Intranets
A RSS Revelation
While I was rewriting a small web application for work (a phone book application called peoplefinder that will also show you on map, where the persons cube is located), a revelation came to me. Why not create a RSS feed for the basic phone, name, department, location information… With the link pointing to the map page!
We also are testing dotNetNuke as an intranet portal server. So each department has a ‘home page’, along with anything else that helps other departments interact with them, like forms, org charts and a department employee list. So rather than use the standard Text/HTML block, we use the News Feed (RSS) block… Walla! Now we have a department employee list that gets automatically updated with the peopleFinder database that the receptionist updates.
A further Data Warehouse / Data Aggregation Idea
Using RSS in the workplace, with your custom or even off the shelf databases, by creating you own RSS feeds. You can provide the users customized live data pages. You might even call them dashboards.
So RSS is not just for external uses like blogs and news. It is exactly what it stands for “Really Simple Syndication†… or you can think of it as a generalized way to look dissimilar data.
The data aggregation possibilities are endless. Imagine this; You work for a construction company, your CFO cares most about the data contained in; 3 financial reports from your ERP (JDE, Oracle, SAP), 2 project status reports from all the active construction projects, a phone list, his email inbox, his Outlook calendar, and the wall street journal headlines…. Well by using RSS queries to get the data he really wants from all those systems, and using the external feed from wall street journal… (in addition if you wanted the Outlook data you would probably need to compiled all of this into an Outlook Today Template)… So you setup a simple webpage that pulls the data from all these feeds, and displays them to him… or he just uses a RSS news aggregator to view it.
You can see that this is really a simple way to get data organized for people, thus allowing for a productive enjoyable intranet experience.
News Aggregators that I have personally used
The Reality of QAM HDTV Recording
I recently procured a FusionHDTV 5 Lite. And last night recorded my very first episode of the new seas0n of Lost!
Here’s the hardware setup
• Pentium 4 1.2GHz
• 1 GB RAM
• 80GB dedicated 7200RPM ATA hard drive
• FusionHDTV 5 Lite!
Software Used
• FusionHDTV recording software and scheduler
• Womble MPEG VCR - for commercial cutting
• FFMPEG (compiled for windows) for conversion to DVD (or whatever you want!)
The video source was a Comcast (seattle) cable feed. This FusionHDTV card can decode clear QAM signal on the cable, AND from what I am told, it is one of the few cards that can do this.
The Result
It worked beautifully!!!
• 8GB of MPEG data from the 1 hour show
• I then chopped the commercials out with MPEG VCR, 10 mins and at 5GB now
• Then I converted the file to a NTSC-DVD format with Ffmpeg, 3.5 hours and 1.2GB !!! The re-encoding time will drop if you throw a burlier processor at it… or from what i am reading now the FusionHDTV 5 GOLD card has a MPEG 2 ENCODER on it and the software that is included with it can re-encode the file, thus eliminated the need for ffmpeg… I have NOT confirmed this, and I am unsure of the ease of use to get it into an acceptable DVD format.
command line used for ffmpeg conversion - HDTV transport stream (TP) to NTSC-DVD program stream (PS)
ffmpeg.exe -i lost.tp -target ntsc-dvd lost.mpg
« Previous Page — Next Page »
