Categories
ASP.NET Bible tags C# Christianity LINQ Programming

Working on Bible Verse Tags for ASP.NET (C#)

To do:

  • build Regex to detect bible verses in tags
  • put in named back-references
  • find a way to choose different tables with LINQ
  • make it work for an entire chapter
  • add error messages
  • move it to a class file instead of in the page
  • run it from the filterText method if IndexOf(“[bible]”) !=-1
  • fix toVerse in case it goes out of range
  • fix misspelled or abbreviated bookName with value from database
  • change to Compiled Queries
  • add footnotes
  • pretty up error messages
  • clean up final code
public class bibleParts
{
	public static Func<bibleDataContext, string, IQueryable<bibleParts>>
		theVersion = CompiledQuery.Compile((bibleDataContext context, string bibleVersion) =>
			(from v in context.bibles_infos
			 where v.bibleName == bibleVersion
			 select new bibleParts
				 {
					 version = v.bibleID,
					 language = v.language,
					 copyright = v.copyright
				 }));

	public static Func<bibleDataContext, int, string, IQueryable<bibleParts>>
		theBook = CompiledQuery.Compile((bibleDataContext context, int bookLang, string book) =>
			(from b in context.book_names
			 where (b.book == book || b.abbreviation == book || b.alt == book) && b.language == bookLang
			 select new bibleParts
			 {
				 bookID = b.book_id,
				 book = b.book
			 }));
	public static Func<bibleDataContext, int, int, int, IQueryable<bibleParts>>
		theVerses = CompiledQuery.Compile((bibleDataContext context, int version, int book, int chapter) =>
			(from v in context.verses
			 where v.versionID == version && v.bookID == book && v.chapter == chapter
			 select new bibleParts
			 {
				 verseNum = v.verse1,
				 thisVerse = v.text
			 }));

	public int version {get;set;}
	public int language {get;set;}
	public string copyright {get;set;}
	public int bookID {get;set;}
	public string book {get;set;}
	public int verseNum {get;set;}
	public string thisVerse {get;set;}
}
</pre></pre>
<pre><pre>private string verseMod(string text)
{
	string textVal = text;
	string errorValue = "";
	string verseNumBegin = "<sup>";
	string verseNumEnd = "</sup>";
	string footerBegin = "<em> - ";
	string footerEnd = "</em>";
	string bibleVersion = "kjv";  //default version if none is specified
	string pat = @"\[bible[=]?(?<version>[a-zäëïöüæø]*)](?<entire>(?<book>([0-9][\s]?)?[a-zäëïöüæø]*[\s]{1}([a-zäëïöüæø]*[\s]?[a-zäëïöüæø]*[\s]{1})?)(?<chapter>[0-9]{1,3})(:{1}(?<verse>[0-9]{1,3})(-{1}(?<toVerse>[0-9]{1,3}))?)?)\[/bible]";

	Regex r = new Regex(pat, RegexOptions.IgnoreCase);

	MatchCollection m = r.Matches(textVal);
	foreach (Match match in m)
	{
		string verseVal = "";
		string errorText = "";
		if (!String.IsNullOrEmpty(match.Groups["version"].Value))
			bibleVersion = match.Groups["version"].Value;
		string thisBook = match.Groups["book"].Value;
		int fromVerse = 0;
		int toVerse;
		if (!String.IsNullOrEmpty(match.Groups["verse"].Value))
			fromVerse = Convert.ToInt32(match.Groups["verse"].Value);
		toVerse = fromVerse;
		if (!String.IsNullOrEmpty(match.Groups["toVerse"].Value))
			toVerse = Convert.ToInt32(match.Groups["toVerse"].Value);

		using (var bdc = new bibleDataContext())
		{
			var searchVersion = bibleParts.theVersion(bdc, bibleVersion).SingleOrDefault();
			if (searchVersion != null)
			{
				var searchBook = bibleParts.theBook(bdc, searchVersion.language, thisBook).SingleOrDefault();
				if (searchBook != null)
				{
					var searchVerses = bibleParts.theVerses(bdc, searchVersion.version, searchBook.bookID, Convert.ToInt32(match.Groups["chapter"].Value));
						if (fromVerse != 0)
						{
							searchVerses = from v in searchVerses
										   where v.verseNum >= fromVerse && v.verseNum <= toVerse
										   select v;
						}
							string realToVerse = "";
							verseVal += String.Format("{1}{0}{2}", match.Groups["entire"].Value.Replace(match.Groups["book"].Value.Trim(), searchBook.book), "<span class=\"bibleHead\">", "</span>");
							verseVal += "<span class=\"bibleContent\">";
							foreach (var theVerse in searchVerses)
							{
								string verseFormat = "{2}{1}{3}{0} ";
								if (String.IsNullOrEmpty(match.Groups["toVerse"].Value) && !String.IsNullOrEmpty(match.Groups["verse"].Value))
									verseFormat = "{0} ";

								verseVal += String.Format(verseFormat, theVerse.thisVerse, theVerse.verseNum, verseNumBegin, verseNumEnd);
								realToVerse = theVerse.verseNum.ToString();
							}
							verseVal += String.Format("{1}{0}{2}</span>", searchVersion.copyright, footerBegin, footerEnd);
							verseVal = verseVal.Replace(String.Format("-{0}", toVerse), String.Format("-{0}", realToVerse));
							verseVal = verseVal.Replace("-</span>", "</span>");
				}
				else
				{
					errorText = "The book \"{0}\" does not exist.  Please check the spelling and try again.";
					errorValue = match.Groups["book"].Value;
				}
			}
			else
			{
				errorText = "The version \"{0}\" is not installed on this server";
				errorValue = match.Groups["version"].Value;
			}
			if (String.IsNullOrEmpty(errorText))
			{
				textVal = textVal.Replace(match.Groups[0].Value, verseVal);
			}
			else
			{
				textVal = textVal.Replace(match.Groups[0].Value,String.Format(errorText,errorValue.Trim()));
			}
		}
	}
	return textVal;
}

Currently active at newcastlechurchofChrist.com.

Categories
Web design

Firebug primer by Hugo

For those that are not aware Firebug is a add-on for Firefox, and is essentially a development debugging tool, that allows you to inspect various aspects of a web page.

It has become – for those that have used it for a while – one of those indispensable tools that make day to day coding life that much more productive.

This post is by way of introducing those unfamiliar with it to it’s most basic functionality, I do not attempt to explore any of the deeper functions but concentrate on the HTML / CSS tools available.

The image below shows the Firebug console on initial activation.

The HTML tab is selected and this shows an initial view of the pages markup in the panel to the left hand side at the bottom. To the right is a view of the CSS rules that apply to this page and to this element specifically in the initial view and is selected using the tab above marked ‘CSS’ (more about the other views later).

The image above shows the options selectable for the HTML markup view.
The important options are the three bottom ones:

  • ‘Highlight changes’ this will place a background to the element being viewed or that is receiving focus and helps greatly when the markup dynamically changes
  • ‘Expand changes’ this feature will automatically reveal collapsed branches in the markup (note the plus sign against the element nodes in the makup view which are clickable to inspect nested detail) when the page refreshes or one inspects an element in the main viewport (see later explanation on ‘inspecting’)
  • ‘Scroll Changes into view’ very useful as this moves the html view to the element in question rather than you have to find it in a large and complicated page

Next is where Firebug starts to get interesting!

The image below shows a view when one uses the ‘inspect’ button whilst in html view

Note the blue bounding border around the text in the viewport; when you click the ‘Inspect’ button you can then move your pointer over any portion of the rendered viewport display, as you highlight elements they will be demarcated by the blue border, as this happens you will notice two things occurring firstly the html markup view will be scrolling to the element that you have hovered over and the CSS view in the right hand pane will jump to the specific CSS rulesets that style this element.

When an element is highlighted you may click on the element and this will ‘fix’ this element in the two view panes in Firebug allowing you to further inspect aspects without loosing the focus on that element.

The image above shows a further method to inspecting elements and one that provides a further level of detail that is extremely useful. By clicking on any element in the left hand Firebug pane showing the page markup you will be able to highlight the elements padding and margins, this can be seen as the yellow highlight which represents the margins of the element and the purple highlight which represents the elements padding applied.

Moving on to the CSS aspect of Firebug demonstrates some invaluable tools and information that make dealing with CSS cascade and inheritance much easier and is perhaps is a feature above all others that would justify installing and learning to work with Firebug.

Looking at the right hand pane showing CSS rulesets shows us some very important information firstly it show us all the rulesets and properties that have been applied to the element highlighted in the left hand pane but much more than that it shows us specifically the specificity order of those rulesets in other words it shows us those rules that carry the heaviest most important weight first it then shows rulesets of a lesser value but that have been applied to the element, and thirdly it shows us properties that have been inherited by the element from parents or ancestors, note the “Inherited from div.content” heading, this is telling us that there was a font-size applied to any div with a class ‘.content’ and that as .submit and/or a paragraph was a child element of that div.content it had inherited that font-size; which brings us to the final feature of this CSS view, note the strikethrough on that inherited ruleset font-size, Firebug is telling us that in actual fact although this property was inherited in reality it was overwritten bu a more specific font-size described on the child element.

This set of features and information make debugging CSS problems extremely fast and far easier than having to wade through the stylesheet trying to understand where there might be an inheritance or specificity issue. On a final note please observe the line numbers to the right of the rulesets these correspond to the actual line numbers in your stylesheet which further speeds up locating specific rulesets; In the examples I have used grabbed from the forum It went unnoticed until too late that cetain styles/stylesheets appear to be ‘packed’ or ‘minified’ and thus all rulesets are in fact collapsed to a single line to preserve space and reduce file size, hence we mainly see ‘(line 1)’ normally this would show as mentioned earlier, an example of actual line numbers can be seen if you look further down at the third rulest that has a file name html.css and a line number of ‘(line 65)’

A further aspect of the right hand view can be seen in the image below where the ‘layout’ button has been selected. This speaks for itself but briefly it shows the aspects of the elements box model.

Lastly in either viewing pane one can edit in real time either the markup or, as shown in the image, the CSS rulesets, you can add new properties, delete existing ones or simply modify existing ones.

Conclusion:

Firebug is a very powerful tool and one that simply increases ones productivity; I can’t stress enough though that I have only scrapped at the surface of what it can show and do and concentrated on the basic HTML/CSS features, if you’re working with client side scripting Firebug becomes equally indispensable in allowing you to observe in real time dynamic changes to the page.

There are other aspects that I leave to the reader to discover but once you do you’ll realise why you can’t really do without this tool 🙂

Categories
Web design

Join Project Honeypot

Stop Spam Harvesters, Join Project Honey Pot

Categories
Web design

Let me check my calendar

OK, this is 2008. I know there are tons of hack web designers out there that bought a copy of dreamweaver but please give me a break. Hey, I’m not against hacks, I mean someone’s got to do pages for $10 or else the bait shop won’t ever get a web site. I just want to help you not look completely incompetent.

I have my speakers on because I sometimes like to listen to music when I’m working. A lot of other people do, too. When I go to a web page I. DO NOT. WANT. The accursed thing to scream at me or play me a flourish or orchestral hit. Sometimes I have my speakers on at night when others in the house are sleeping and that’s not only unprofessional, it’s just not courteous.

So please, since for some reason you refuse to do away with your stupid, worthless, out of date since 1997 splash pages at least get rid of the idiotic automatic sound. That is, of course, unless you enjoy being a laughing stock and enjoy your marvelous hit counter to remain at one visit (from your mother, she’s the only one that would bother to look).

I was going to post links to offending pages but the last 5 I ran across have been from the same “web design” company. 🙄

Categories
Web design Web standards

Third annual CSS Naked day

April 5th, 2008 is Bette Davis’ 100th birthday and it is also the third annual CSS Naked Day. If you are viewing this on April 5th then you will see no styling. Any other day it will look normal. A properly written web page should fail gracefully and still be useable by browsers that do not understand CSS. It is the web standards way. 🙂

The idea behind this event is to promote Web Standards. Plain and simple. This includes proper use of (x)html, semantic markup, a good hierarchy structure, and; well, a fun play on words. I mean, who doesn’t want to get naked?. Feel free to see the original reference article for more information.

Categories
ASP.NET Programming

Firing a click event using the enter key

This one had me stumped for a few minutes. I had a text box that would post to a google search. Entering text in and hitting the enter key would just post back to the page and have no effect.

Hmm. Frustrating. I don’t expect everyone to type in their search criteria and grab the mouse to click the tiny little button so here’s what you have to do.

                <asp:Panel ID="searchPanel" DefaultButton="topSearchButton" runat="server">
                <asp:TextBox ID="topSearch" columns="21" CssClass ="formbox" runat="server" EnableViewState="False" />
                <asp:ImageButton ID="topSearchButton" ImageURL="images/bg/buttonGoHome.gif" OnClick="topSearchButton_Click" CSSClass="buttonGoHome" AlternateText="Submit" runat="server" />  
                </asp:Panel>

OnClick event:

    protected void topSearchButton_Click(object sender, ImageClickEventArgs e)
    {       Response.Redirect("http://www.google.com/u/xxx?domains=www.xxx.edu&sitesearch=www.xxx.edu&q=" + topSearch.Text);
    }

The DefaultButton attribute names the ID of the button you want to fire. The only issue is it doesn’t work on a text box (or any other form item) it only works on a Panel. I suppose it makes sense because you usually don’t just have one form field and a button, it’s usually many text boxes, any of which can fire the click event using the enter key.

I figured there was no point in having ViewState on a text box that posts to another site so EnableViewState should be set to False in this case.

Categories
Classic ASP Programming

FPDF.asp carriage return / line feed in MultiCell

Recently I was given the task of printing address labels from a database using Avery 5160 labels. These labels are 3 columns of 10 rows. 2.625″ x 1″ (66.6mm x 25.4mm).

I was having trouble with carriage returns. First problem is that the ASP version of FPDF doesn’t seem to recognize the \n line feed. It was easy enough to replace it with Chr(10) but I suppose I had a misconception of how FPDF handles line feeds in that it used the entire height of the multicell height for every line of text.

At first I used this incorrect code to test (notice the carriage return has no effect):

<%@language=vbscript%>
<!--#include file="fpdf.asp"-->
<%
Dim i,pdf
Set pdf=CreateJsObject("FPDF")
     pdf.CreatePDF "P","cm","Letter"
     pdf.SetPath("fpdf/")
     pdf.SetTopMargin(1.27)
     pdf.SetLeftMargin(.42)
     pdf.SetRightMargin(.42)
     pdf.Open()
     pdf.AddPage()
     pdf.SetFont "Times","",9
for i=0 to 40
          labelText = "Client #" & i & Chr(13) & "<--carriage return there address" & Chr(10) & "City, State  Zip "
     pdf.MultiCell 6.66,2.54,labelText,1,L
Next
     pdf.Close()
     pdf.Output()
Set pdf = Nothing
%>

with the results shown below:
bad line feeds

Then after googling a bit I found a php version of a script for creating a PDF for Avery 5160 labels and ported it to ASP:

<%@language=vbscript%>
<!--#include file="fpdf.asp"-->
<%
Set pdf = CreateJsObject("FPDF")
	pdf.CreatePDF "P","mm","Letter"
	pdf.Open()
	pdf.AddPage()
	pdf.SetFont "Arial","B",10
	pdf.SetMargins 0,0
	pdf.SetAutoPageBreak(0)
x = 0
y = 0
' instead of for next call names and addresses from database
for a = 1 to 40
	' Make label text
	LabelText = "Contact Name" & a & chr(10) & "Entire Company Name" & a & chr(10) & "1313 Mockingbird Lane" & chr(10) & "Chicago, IL  60617"
	LeftMargin = 4.2
	TopMargin = 12.7
	LabelWidth = 66.6
	LabelHeight = 25.45
	' Create Co-Ords of Upper left of the Label
	AbsX = LeftMargin + ((LabelWidth + 4.22) * x)
	AbsY = TopMargin + (LabelHeight * y)
	pdf.SetXY AbsX+3,AbsY+3
	pdf.MultiCell LabelWidth-8,4.5,LabelText,0,L
	y=y+1
	if (y=10) then
		x=x+1
		y = 0
		if (x = 3) then
			x = 0
			y = 0
			pdf.AddPage()
		end if
	end if
next
	pdf.Output()
Set pdf = Nothing
%>

Just change the for-next loop to a database call and you’re in business.

I find FPDF extremely useful and am sure to use it in the future.

Categories
Programming

Making FTP work on Windows Vista

I just built a Windows machine from parts and installed Windows Vista Ultimate 64bit. The only problem I was having was the FTP service would not stay active upon shutdown or restart. I had to start it manually every time.

If anyone else is wondering, here is how to make it work (if you already have FTP installed and just need it to start on reboot then start at step 7):

  1. Control Panels
  2. Programs
  3. Turn Windows features on or off
  4. locate and check FTP Publishing Service
  5. Click OK to install the items you selected
  6. You may or may not have to start FTP through IIS 6 but it may work without this step
  7. Start Menu
  8. right-click “Computer”
  9. Select “Manage”
  10. Select “Services” under “Services and Applications”
  11. double-click “FTP Publishing Service”
  12. Change “Startup Type” to “Automatic”
  13. Click OK

Let me know if this helps. I don’t know, it may be obvious to everyone that knows Windows but I’ve been a Macintosh guy since I bought my second computer back in 1995 (I had a Texas Instruments TI-99/4A before that). I’m used to starting FTP with one click in the Sharing control panel. 😉

For comparison here’s how turn on FTP under Mac OS X:

  1. Apple Menu
  2. System Preferences…
  3. Sharing
  4. Click the “FTP Access” checkbox

This also opens the port in the firewall and keeps it active any time the Mac is started.

Categories
Web design

Second annual CSS Naked Day

April 5th, 2007 is the second annual CSS Naked Day. If you are viewing this on April 5th then you will see no styling. Any other day it will look normal. A properly written web page should fail gracefully and still be useable by browsers that do not understand CSS. It is the web standards way. 🙂

The idea behind this event is to promote Web Standards. Plain and simple. This includes proper use of (x)html, semantic markup, a good hierarchy structure, and; well, a fun play on words. I mean, who doesn’t want to get naked?. Feel free to see the original reference article for more information.

Categories
Bible tags Christianity Wordpress

Bible verse tags 2.0

See here for more information on the new version of the Bible verse tags.

I hope that this plugin can be used to spread the good news throughout the earth.

Let me know if you need any help installing it.

John 3:16For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life. - King James Version
1 John 11That which was from the beginning, that which we have heard, that which we have seen with our eyes, that which we beheld, and our hands handled, concerning the Word of life   2(and the life was manifested, and we have seen, and bear witness, and declare unto you the life, the eternal [life], which was with the Father, and was manifested unto us);   3that which we have seen and heard declare we unto you also, that ye also may have fellowship with us: yea, and our fellowship is with the Father, and with his Son Jesus Christ:   4and these things we write, that our joy may be made full.   5And this is the message which we have heard from him and announce unto you, that God is light, and in him is no darkness at all.   6If we say that we have fellowship with him and walk in the darkness, we lie, and do not the truth:   7but if we walk in the light, as he is in the light, we have fellowship one with another, and the blood of Jesus his Son cleanseth us from all sin.   8If we say that we have no sin, we deceive ourselves, and the truth is not in us.   9If we confess our sins, he is faithful and righteous to forgive us our sins, and to cleanse us from all unrighteousness.   10If we say that we have not sinned, we make him a liar, and his word is not in us.      - American Standard Version
1 Mosebog 3:12Adam svarede: "Kvinden, som du satte ved min Side, gav mig af Træet, og så spiste jeg." - Dansk bibel
Kolosser 3:1-31Seid ihr nun mit Christo auferstanden, so suchet, was droben ist, da Christus ist, sitzend zu der Rechten Gottes.   2Trachtet nach dem, was droben ist, nicht nach dem, was auf Erden ist.   3Denn ihr seid gestorben, und euer Leben ist verborgen mit Christo in Gott.    - Luther bibel

Trackbacked to:
Open Trackback @ Samantha Burns dot com
Cao’s Blog
Diane’s Stuff

Categories
Trackbacks Wordpress

Open trackback problems (sorry)

Thanks to Cao over at Cao’s blog for pointing out that the link to my open trackback post was broken.

I was wondering why I haven’t got any for a long time.

I’m going to have to ping everyone to let them know it’s back up and active.

Please accept my heartfelt apology. 🙂

Mark B.

Su. InMuscatine
Su. Onemanbandwidth
Su. The Blazer Blog
Su. Miceland
Su. Where are my socks?
Su. Peakah’s Provocations
Su. Otimaster
Su. Grandinite
Su. Free Constitution
Su. Conservative Culture (Su, T)
Su. – a metamorphoself
Su. The Amboy Times
Su. Stageleft
M. Courting Destiny (M, W)
M. Bloggin’ Outloud (M, F.)
M. The Land of Ozz
M. DragonLady’s World
M. Committees of Correspondence
M. The Tar Pit
M. Pirates! Man your Women!
M. WebKittyn Warbles
M. Forward Biased
M. Urban Paradise
M. Perri Nelson’s Website (M, W, F)
T. The Liberal Wrong Wing
T. Tor’s Rants
T. Those Bastards! (T, F.)
T. The Business of America is Business
T. RightPundits.com (T, F)
T. historymike’s musings
T. Common Folk Using Common Sense
T. Rightlinx
T. The Median Sib
T. The Path to Endarkenment
T. Stingray: a blog for salty Christians
T. Planck’s Constant
T. Renaissance Blogger (T, Th.)
T. Signaleer
W. third world county (W, F.)
W. Gribbit’s Word (W, S.)
W. Stop The ACLU (W, S.)
W. Diane’s Stuff
W. Stuck On Stupid
W. This May…Or Not
W. rashbre central
W. Cigar Intelligence Agency (W, Wknds)
W. Jack of All Trades
W. Right Truth
W. Chaotic Synaptic Activity
Th. Liberal Common Sense
Th. TMH’s Bacon Bits
Th. customerservant.com
Th. A Quiet Noise
Th. Mental Rhinorrhea
Th. Sed Vitae (Th, F)
Th. Republispin
Th. Diary of the Mad Pigeon
F. Pirate’s Cove (M, F)
F. Dan Mancini
F. MacBros’ Place
F. The World According To Carl
F. Gospel Fiction
F. Comedian Jenée: People are Idiots
F. Woman Honor Thyself
F. Publius Rendezvous (wknd)
F. Madman Returns
F. The Hill Chronicles
S. The Crazy Rants of Samantha Burns
S. Point Five
S. 7 Deadly Sins
S. Assorted Babble
S. Church and State
S. Selective Amnesia
S. Case Notes from the Artsy Asylum
S. Neocon Express
D. The Conservative Cat
D. Don Surber
D. The Dumb Ox
D. NIF
D. Right Wing Nation
D. Colbert Report
D. imagine kitty magazine
D. partyblog.ca
D. Robinik Open Blog
D. Culturetastic
D. Rightwing Guy
Wknd. Oblogatory Anecdotes
Wknd. Borknat
Wknd. Blue Star Chronicles
Wknd. The Right Nation
Wknd. Leaning Straight Up
Wknd. The Uncooperative Blogger
Wknd. Stuck On Stupid
Wknd. The Bullwinkle Blog
Wknd. 123beta (F, Wknd)
Wknd. Robinik.net
Wknd. The Clash of Civilizations (W, F, Wknd)

Categories
Trackbacks Wordpress

Word Press 2.0 Trackback fix revisit

Well, wordpress still stinks in the trackback department. I’ve applied Paul Ooi’s Word Press 2.0 Trackback fix and am attempting to send a trackback to that post.

Let’s see if it works. *sigh*