Scripting

Ramblings and links to interesting snippets


Edit Join Date mod for PHPBB2

Tags: , , ,

I have written some mods for PHPBB2 (don’t ask why I’m not on 3 :P)  and I havn’t gotten into the habit of documenting them properly so they can shared, but this time I went through the whole nine yards :)  I don’t know how well this file would work with any auto installers, though.

I will give credit where credit it due – this mod is adapted from tomlevens’ “Edit User’s Postcount” mod.

What this mod does is add a field to the user management section of the admin panel which enables you to change a user’s join date.

click here to download join_date.mod

Permalink » No comments

Regular Expressions

Tags: , , , ,

I can never seem to locate a guide that has an easy explanation of the common regular expressions that I use on a regular basis.  I usually just find bits and pieces, or find the right info, but not displayed in a way that’s easy to reference.  So here’s my own notes on RegEx :)

CharacterUsage
.wildcard character - will match anything
|or operator - (this|that) will match either
-range selector - will match a range of character or numbers i.e. 1-9
[]match any character inside the brackets [aeiou] would match anything with a vowel.
^match the start of a string - ^a will match 'atlas' but not 'mad'
[^]don't match - it will negate what you put inside like [^cheese]
$match the end of a string - at$ will match 'mat' but not 'saturn'
?match preceding character 0-1 times - tree? will match 'tre', 'tree', but not 'treee'
*match preceding character 0+ time - same as * except it would match 'treee'+
+match preceding character 1+ times - this version will not match 'tre'
{#}match preceding character # times - tree{3} will match 'treeee'
{#,#2}match preceding character at least #, but not more than #2 - tree{3,4} will match 'treeee' or 'treeeee'
icase insensitive flag - add at end i.e. '#(regex)#i'
sdotall flag - make the "." character match anything
xverbose flag - ignore all whitespace and allows "#" commenting
Regular expression syntax

One piece I use often as kind of a ‘match-all’ is “(.*?)” so preg_match_all(‘#<a>(.*?)</a>#is’, $content, $matches); would match everything in the string that is within anchor tags.

The delimiter can also be changed, in the previous example it is the “#” pound character, but could easily be changed to “/” as in ‘/<a>(.*?)</a>/is’ or changed into whatever is most convenient for the enclosed string.

Permalink » No comments

Javascript Style Reference

Tags: , , , ,

I’m always forgetting what the JavaScript equivalent is of certain CSS styles.  for instance you could change the border by:

document.getElementById(‘myText’).style.border = ‘1px solid #333′;

CSS PropertyJavaScript Reference
backgroundbackground
background-attachmentbackgroundAttachment
background-colorbackgroundColor
background-imagebackgroundImage
background-positionbackgroundPosition
background-repeatbackgroundRepeat
borderborder
border-bottomborderBottom
border-bottom-colorborderBottomColor
border-bottom-styleborderBottomStyle
border-bottom-widthborderBottomWidth
border-colorborderColor
border-leftborderLeft
border-left-colorborderLeftColor
border-left-styleborderLeftStyle
border-left-widthborderLeftWidth
border-rightborderRight
border-right-colorborderRightColor
border-right-styleborderRightStyle
border-right-widthborderRightWidth
border-styleborderStyle
border-topborderTop
border-top-colorborderTopColor
border-top-styleborderTopStyle
border-top-width borderTopWidth
border-widthborderWidth
clearclear
clipclip
colorcolor
cursorcursor
displaydisplay
filterfilter
fontfont
font-familyfontFamily
font-sizefontSize
font-variantfontVariant
font-weightfontWeight
heightheight
leftleft
letter-spacingletterSpacing
line-heightlineHeight
list-stylelistStyle
list-style-imagelistStyleImage
list-style-positionlistStylePosition
list-style-typelistStyleType
marginmargin
margin-bottommarginBottom
margin-leftmarginLeft
margin-rightmarginRight
margin-topmarginTop
overflowoverflow
paddingpadding
padding-bottompaddingBottom
padding-leftpaddingLeft
padding-rightpaddingRight
padding-toppaddingTop
page-break-afterpageBreakAfter
page-break-beforepageBreakBefore
positionposition
floatstyleFloat
text-aligntextAlign
text-decorationtextDecoration
text-decoration: blinktextDecorationBlink
text-decoration: line-throughtextDecorationLineThrough
text-decoration: nonetextDecorationNone
text-decoration: overlinetextDecorationOverline
text-decoration: underlinetextDecorationUnderline
text-indenttextIndent
text-transformtextTransform
toptop
vertical-alignverticalAlign
visibilityvisibility
widthwidth
z-indexz-index
Javascript CSS Style reference

Shamelessly stolen from: http://codepunk.hardwar.org.uk/css2js.htm

Permalink » No comments

Alignment issues

Tags: , , , , ,

Ever have this problem where your centered elements will “wiggle” out of place when you adjust the size of your browser?  It’s just by one pixel, and annoys me to death.

I found this article about it: http://acko.net/blog/css-sub-pixel-background-misalignments

It seems like it’s a margin/padding issue.  I took the offending div element and added “margin-left: 1px;” to it’s class and it worked!  Beautifully :)  You may also need to nudge any background images by one pixel.

It does concern me that other elements on the page align perfectly, where it was only the #footer div that was giving me grief.

UPDATE

The aformentioned fix applies to 100% divs that have a centered background.  I came across this same problem in a div that was set to margin:auto;.  I went ahead and added “margin-left: 1px;” to the body and that fixed everything up nicely :)

Permalink » No comments

ApacheBench

Tags: , , , , ,

I was looking around today for some means to load test my scripts, I happened upon this website:  http://loadimpact.com/

It’s free services were alright, but up to 50 users just won’t put my scripts through they’re paces!  I’ve looked into trying something called ApacheBench before, but had trouble.  It’s something you can only access through SSH, and when in there I kept receiving “-bash: ab: command not found” errors.  Not fun!

The problem was I wasn’t in the right directory.  I found out you can search for ApacheBench but running “find / -name ab” (without quotes)  then you would include the directory when running ApacheBench “/dir/ab -n 100 http://yourdomain.com"

References:
http://sharebear.co.uk/blog/2009/03/12/optimising-django-dreamhost/
http://www.webmaster-talk.com/php-forum/116797-web-stress-tools-recommend.html
http://httpd.apache.org/docs/1.3/programs/ab.html
http://wiki.dreamhost.com/Ssh

Permalink » No comments