Sunday, July 01, 2007

Perl scripts for finding URLs of Squishdot posts.

In your Squishdot site go to "Manage Postings" and save the page to a file.

Then run the following Perl script, passing the filename that you saved the page to as a parameter:


#!c:\perl\bin -wnl

if(/.<*A HREF="(\d+)*/)
{print $1;
$first += 1;
if($first == 1)
{print "The first match is on line $.";}
}

Check that the above result is correct.

Then run:

#!c:\perl\bin -wnl

if(/.*

Monday, April 23, 2007

test class for baseball program MyProject

// The following code was generated by Microsoft Visual Studio 2005.
// The test owner should check each test for validity.
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Text;
using System.Collections.Generic;
using MyProject;
namespace TestMyProject
{
///
///This is a test class for MyProject.Form1 and is intended
///to contain all MyProject.Form1 Unit Tests
///

[TestClass()]
public class Form1Test
{


private TestContext testContextInstance;

///
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///

public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region Additional test attributes
//
//You can use the following additional attributes as you write your tests:
//
//Use ClassInitialize to run code before running the first test in the class
//
//[ClassInitialize()]
//public static void MyClassInitialize(TestContext testContext)
//{
//}
//
//Use ClassCleanup to run code after all tests in a class have run
//
//[ClassCleanup()]
//public static void MyClassCleanup()
//{
//}
//
//Use TestInitialize to run code before running each test
//
//[TestInitialize()]
//public void MyTestInitialize()
//{
//}
//
//Use TestCleanup to run code after each test has run
//
//[TestCleanup()]
//public void MyTestCleanup()
//{
//}
//
#endregion


///
///A test for Form1 ()
///

[TestMethod()]
public void ConstructorTest()
{
Form1 target = new Form1();

// TODO: Implement code to verify target
Assert.AreEqual(target.Basepath.Count, 3);
}


///
///A test for oneBagger ()
///

[TestMethod()]
public void oneBaggerTest()
{
Form1 target = new Form1();

target.oneBagger();

Assert.AreEqual(target.Basepath.Pop(), 1);

Assert.AreEqual(target.Basepath.Pop(), 0);


}

///
///A test for twoBagger ()
///

[TestMethod()]
public void twoBaggerTest()
{
Form1 target = new Form1();

target.oneBagger();

target.twoBagger();

Assert.AreEqual(target.Basepath.Count, 8);
}

///
///A test for threeBagger ()
///

[TestMethod()]
public void threeBaggerTest()
{
Form1 target = new Form1();
target.oneBagger();
target.twoBagger();
target.threeBagger();


Assert.AreEqual(target.Basepath.Count, 11);

Assert.AreEqual(target.Basepath.Pop(), 0);

Assert.AreEqual(target.Basepath.Pop(), 0);

Assert.AreEqual(target.Basepath.Pop(), 1);




}

///
///A test for homer ()
///

[TestMethod()]
public void homerTest()
{
Form1 target = new Form1();

target.homer();

Assert.AreEqual(target.Basepath.Count, 7);

Assert.AreEqual(target.Basepath.Pop(), 0);

Assert.AreEqual(target.Basepath.Pop(), 0);

Assert.AreEqual(target.Basepath.Pop(), 0);


}

///
///A test for walk ()
///

[TestMethod()]
public void walkTest()
{
Form1 target = new Form1();

target.threeBagger();
target.walk();
Assert.AreEqual(target.Basepath.Count, 6);
target.walk();
Assert.AreEqual(target.Basepath.Count, 6);
target.walk();
Assert.AreEqual(target.Basepath.Count, 7);

}

///
///A test for addRuns ()
///

[TestMethod()]
public void addRunsTest()
{
Form1 target = new Form1();



target.threeBagger();
target.walk();
Assert.AreEqual(target.Basepath.Count, 6);
target.walk();
Assert.AreEqual(target.Basepath.Count, 6);
target.walk();
Assert.AreEqual(target.Basepath.Count, 7);

target.twoBagger();

target.addRuns();



Assert.AreEqual(target.Runs, 4);
}

///
///A test for strikeout ()
///

[TestMethod()]
public void strikeoutTest()
{
Form1 target = new Form1();

target.strikeout();
target.strikeout();
target.walk();
target.walk();
target.walk();
target.strikeout();
target.homer();
target.strikeout();
target.strikeout();



target.addRuns();



Assert.AreEqual(target.Runs, 1);




}

///
///A test for bat ()
///

[TestMethod()]
public void batTest()
{
Form1 target = new Form1();

for (int i = 0; i < 28; i++ )
target.bat();

target.addRuns();

Assert.IsTrue(target.Runs < 21);
Assert.IsTrue(target.Runs >= 0);


}
}


}

Sunday, April 22, 2007

Perl one-liner for text replacement

Perl one-liners contain a single command terminated with a semi-colon, followed by a list of the files that it should operate on.

Here is an example, which removes a reference to a file name 1169048439 inside a file:


perl -wpl -e 's/1169048439\///g;' 1169048439

The above will only print to the screen. If you want to replace the file with the corrected file one way to do it is to say

perl -wpl -e 's/1149008916\///g;' 1149008916 > tempo

and then

mv tempo 1149008916

Writing the output directly on top of the modified file creates a blank file in Centos 4

Thursday, April 19, 2007

C# Baseball Simulation Program

// The following program assumes a Form called Form1 which has three checkboxes
// and two buttons and two labels. All objects should use their default names
// and there should have been no other objects on the form.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyProject
{
public partial class Form1 : Form
{
int runs = 0;
int outs = 0;
int innings = 0;
Random RandomClass = new Random();

//A basepath is a string of zeroes and ones. The first three elements are the three bases.
//A one means the base is occupied. A zero means it is empty.
//Any 1s beyond the first three elements represent runners who scored.
//Zeroes beyond the first three elements can be ignored.

Stack basepath = new Stack();

int[] intArray;





public Form1()
{
InitializeComponent();
//create the three bases and set them to empty.
basepath.Push(0);
basepath.Push(0);
basepath.Push(0);
}


public void oneBagger()
{
//advance runners two bases.
basepath.Push(0);
basepath.Push(1);

}


public void twoBagger()
{
//advance runners three bases.
basepath.Push(0);
basepath.Push(1);
basepath.Push(0);

}

public void threeBagger()
{
basepath.Push(1);
basepath.Push(0);
basepath.Push(0);

}

public void homer()
{
basepath.Push(1);
basepath.Push(0);
basepath.Push(0);
basepath.Push(0);
}

public void walk()
{
// look for first empty base and
// place a runner there.
// if all bases are occupied move all runners forward one base.
if (basepath.Pop() == 0)
basepath.Push(1);
else if (basepath.Pop() == 0)
{
basepath.Push(1);
basepath.Push(1);
}
else if (basepath.Pop() == 0)
{
basepath.Push(1);
basepath.Push(1);
basepath.Push(1);
}
else
{
basepath.Push(1);
basepath.Push(1);
basepath.Push(1);
basepath.Push(1);
}
}

public void addRuns()
{
//for use at end of game.
//Throw away baserunners since they can never score.
basepath.Pop();
basepath.Pop();
basepath.Pop();
intArray = basepath.ToArray();
for (int i = 0; i < intArray.GetLength(0); i++)
{
if (intArray[i] == 1)
{
runs++;
}
}

label1.Text = runs.ToString();

}

public void strikeout()
{
outs = outs + 1;
label2.Text = outs.ToString();
if (outs > 2)
{
// end of inning;
outs = 0;
label2.Text = outs.ToString();
innings = innings + 1;
basepath.Pop();
basepath.Pop();
basepath.Pop();
basepath.Push(0);
basepath.Push(0);
basepath.Push(0);
checkBox1.Checked = false;
checkBox2.Checked = false;
checkBox3.Checked = false;
}

if (innings > 8)
label2.Text = "Game Over";

}

public void bat()
{
double num = RandomClass.NextDouble();
if (label2.Text == "Game Over")
{
label1.Text = "Press For Totals";
}
else if (num < .225)
{
oneBagger();
}
else if (num < .275)
{
twoBagger();
}
else if (num < .300)
{
threeBagger();
}

else if (num < .325)
{
homer();
}
else if (num < .400)
{
walk();
}

else
{
strikeout();
}

intArray = basepath.ToArray();

// set checkboxes based upon whether bases are occupied.
if (intArray[0] == 1)
{
checkBox1.Checked = true;
}
else
{
checkBox1.Checked = false;
}


if (intArray[1] == 1)
{
checkBox2.Checked = true;
}
else
{
checkBox2.Checked = false;
}


if (intArray[2] == 1)
{
checkBox3.Checked = true;
}
else
{
checkBox3.Checked = false;
}




}



private void button1_Click(object sender, EventArgs e)
{

addRuns();
}

private void button2_Click(object sender, EventArgs e)
{

bat();



}

private void label1_Click(object sender, EventArgs e)
{

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{

}
}
}

Thursday, April 05, 2007

To find Squishdot pages with file uploads google "Click To Download Attachment"

Thursday, March 22, 2007

Blogspot's Atom Feed

http://groups.google.com/group/blogger-help-howdoi/browse_thread/thread/e83b140ad5a1aecf/b4bb492fe6ef74d8?lnk=gst&q=RSS&rnum=1#b4bb492fe6ef74d8


Jennifer, RSS is beneficial to you and your readership.

All three of your blogs publish an RSS feed already.


Format Versions:


Your blog publishes the following feeds


http://goodnessgraciousness.blogspot.com/rss.xml


http://goodnessgraciousness.blogspot.com/feeds/posts/default


http://goodnessgraciousness.blogspot.com/feeds/posts/default?alt=rss


A link to your post atom feed is at the bottom of your page. Scroll to
the bottom and you'll notice it says Subscribe to: Posts (Atom).


http://goodnessgraciousness.blogspot.com/feeds/posts/default



How Do I Change My Site Feed Settings?:


You have your feed set to full, I recommend logging into your account
and setting it to short.


The best way to deal with content theft, is to have your
site feed set on short.


Click on settings/ site feed/ and change it to Blog Posts Feed short.


If you have your feed set to full when splogs scape your content they
are getting your full content.


In July of this year Pankaj Saini was republishing my content without
permission and the content from a missing children's site on his porn
sites in a bid to promote "teen" pornography.


Grabbing content from feeds is a growing concern for many bloggers.
Blog content theft is not just a tiny problem. It is a huge one.
Sploggers are making money off your hard work that you are creating. I
don't know about you, but I resent this.


How do people use feeds?


Now with your feed url, I can syndicate your posts on my blog.


"You can add content from a site feed to your blog by clicking on
layout add a page element, feeds, enter the feed URL and click
"Continue." You will then be able to add a title, select the number of
items to show (up to 5 max.) and display the item dates and/or authors
by selecting the appropriate check boxes."


You can also use your feed to syndicate your posts on sites like
rojo.com


Users can take your RSS feed and read it in a news reader.


Notice when you click on your feeds there is a drop down menu that says
subscribe to this feed using and then it gives you the option to
subscribe to your blog and read it using Bloglines, Yahoo, and Google
reader.


This means that I could subscribe to your blog, log into My Yahoo and
read your blog.


http://my.yahoo.com/


By publishing an RSS feed people do not have to go to your blog.


Telling People About Your Feed


You can add a subscribe to button in your sidebar. To do this, log in
to Blogger. Click on layout, add a page element and choose
HTML/JavaScript, add to your blog and paste the code into the box and
save. You can then move the page element to where you want it position
on your sidebar. If you don't want to use feedburner you can use
http://www.toprankblog.com/tools/rss-buttons/


RSS can be very beneficial for your blog. There are several directories
online where you can submit your RSS feed too.


I hope this helps you better understand RSS.


Feel free to pm me at bloggertalk.net or email me if you have any more
questions.


Rose
http://rosedesrochers.com

Monday, March 19, 2007

Google-Friendly Redirects

Click here to ensure that a redirect is proper. http://www.seochat.com/seo-tools/redirect-check/

The HTTP code for temporary redirect is 307