I have started a new tech blog called codegin.com. This blog is a place where I can post tips, hacks, recipes, and code examples about everything.
I am really excited about this new blog, please visit to check it out.
Started New Tech Blog CodeGin.Com
Creating a Web Spider with PHP
I used this for spidering my site.
function get_links($url) {
$req = new httprequest();
$html = $req->get($url);
$regex = ‘/mhref/m’;
$preg = ‘/<a href=”([^0-9].+?)”/’; // 1 or more
$preg = ‘/<a href=”([^0-9].*?)”/’; // 0 or more
$urls = array ();
preg_match_all($preg, $html, $urls);
$count = 0;
foreach ($urls as $url => $links) {
if ($count == 1) {
foreach ($links as $link) {
echo “link-> ” . $link [...]
Managing Office Douments with PHP
I decided to write a class to manage office documents with PHP.
Word:
function write_word() {
$word = new COM(”word.application”);
$word->Visible = 0;
$word->Documents->Add();
$word->Selection->PageSetup->LeftMargin = ‘2″‘;
$word->Selection->PageSetup->RightMargin = ‘2″‘;
//Setup the font
$word->Selection->Font->Name = ‘Verdana’;
$word->Selection->Font->Size = 8;
//Write some text
$word->Selection->TypeText(”This is a test document”);
//Insert an image
$word->Selection->InlineShapes->addPicture(”C:\\temp\\test.png”);
//Save the document [...]
Get Competition Keywords
One thing I found useful when searching on keywords for SEO was to Google the keywords I wanted to “own”, then grab all the top 10 results from Google. Then I would go to the site and “View Source” to see what keywords they were using and then would manually go back and review [...]
Getting Text From The Internet with PHP
This is a class very close to the Ruby version to get text.
<?php
class httprequest {
function httprequest() {
}
function get($url) {
if (substr($url,0,7) != “http://”){
$url = ‘http://’.$url;
}
$html = implode(”, file($url));
return $html;
}
function post() {
}
}
?>
Adding Text To Microsoft Word with Ruby
I actually created this to automate the cut and paste of text from the web to a word document for consumption by my “plain-text-challenged” customers.
require ‘win32ole’
word = WIN32OLE.new(’word.application’)
word.visible = true
word.documents.add
word.selection.typetext(”Hello World!\n”)
Text To Speech (TTS) with Ruby and PHP
I was working with some scripts for having my PC talk. The first one is in Ruby:
require “win32/sapi5″
include Win32
v = SpVoice.new
v.Speak(”this is the easiest thing to do since I have started working with ruby..”)
Now this one in PHP:
<?php
$tts = new COM(”SAPI.SpVoice”);
$tts->speak(”this is a test”);
?>
Getting Data From MySQL Using Ruby.
I wanted a fast way to get data from mysql using ruby. after i installed the mysql gem it was really easy. This program gets all rows, but only displays the id,name and zip.
require “mysql”
dbh = Mysql.real_connect(”localhost”, “root”, “password”, “scottwork”)
res = dbh.query(”SELECT name,address,city,state,zip,email FROM contacts”)
while row = res.fetch_row do
id = row[0]
[...]
Invoking Java From Ruby
I did this using the rubygem Java-Ruby-Bridge. I did this because I was having problems with JRuby and wanted to execute my class from within Ruby.
Here is a simple way to do it, as long as you remember the classpath.
require ‘rjb’
Rjb::load(classpath = ‘../../TestJava/bin’, jvmargs=[])
test = Rjb::import(’Test’)
c = test.new
c.foo3
This way I was able to invoke a [...]
Opening Internet Explorer with Ruby
I have been doing a lot of web automation these days for testing and automating web based applications without APIs.
To open Internet Explorer with Ruby just use OLE.
require ‘win32ole’
ie = WIN32OLE.new(’InternetExplorer.Application’)
ie.visible = true
ie.gohome
Twitter Updates
Subscribe
My Sites
Categories
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Dec | Feb » | |||||
| 1 | 2 | 3 | 4 | 5 | 6 | |
| 7 | 8 | 9 | 10 | 11 | 12 | 13 |
| 14 | 15 | 16 | 17 | 18 | 19 | 20 |
| 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| 28 | 29 | 30 | 31 | |||
Archives
-
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008
- February 2008
- January 2008
- December 2007
- November 2007
- October 2007
- September 2007
- August 2007
- July 2007
- June 2007
- May 2007
- April 2007
- March 2007
- February 2007
- January 2007
- December 2006
- November 2006
- October 2006
- August 2006
- July 2006
- June 2006
- May 2006
- March 2006
- February 2006
- January 2006
- December 2005
- November 2005
- October 2005
- September 2005
- August 2005
- July 2005
- June 2005
- May 2005
- February 2005
- January 2005
- November 2004
- October 2004
- September 2004
- August 2004
- July 2004
- June 2004
- May 2004
- April 2004
- March 2004

