Author Archive
Reordering an Array in PHP for an Image Gallery
by admin on Jun.06, 2011, under Uncategorized
Say I have a homepage image rotator (as seen here), and grabbing the images in any logical order (by date, by name) is not an option. Well, its time to make an array and shuffle it!
The following code snippet grabs all the image files within a certain directory, turns them into an array (using the readdir function, which un-modified would order them according to the timestamp on the server), and then randomizes it.
Check it out:
$image_dir = "$_SERVER[DOCUMENT_ROOT]/images/home"; // directory on server
$image_relative_path = '/images/home'; // path to images relative to script
$file_types = array('jpg','jpeg','gif','png');
$image_time = '10000'; // seconds each image will display (10000 = 10 seconds)
if ($handle = opendir($image_dir)) {
$dir_array = array();
$count = 0;
while (false !== ($file = readdir($handle))) {
if($file!="." && $file!=".."){
$dir_array[$count] = $file;
$count = $count + 1;
}
}
// ive got my array, now lets Randomize it!
shuffle($dir_array);
$i = (int)(0);
while ($i < $count){
$image_rotation .= /add html around this: '.$image_relative_path.'/'.$dir_array[$i].' ;
$i = $i + 1;
}
closedir($handle);
}
The code uses a jQuery plugin called innerfade to create a cool UX. Enjoy!
Domains for sale.
by admin on Jan.28, 2011, under Uncategorized
Today, I got an interesting email for one of the domains I own.
it reads:
Hey, my name is Seth Chilcutt with Secured Premium Domains.
nosarahouserentals.com will be available for purchase soon.
Since you own nosarahouserental.com, I think you may be interested in nosarahouserentals.com.It is recommended to eliminate any confusion to nosarahouserental.com, to own both the singular/plural versions of the domain.
Your purchase will be a one time fee only that includes one year of complimentary registration.
You also have the option to forward nosarahouserentals.com to nosarahouserental.com at no cost.
After purchasing nosarahouserentals.com you will never be charged again by Secured Premium Domains.If you do have an interest in purchasing nosarahouserentals.com, please visit:
http://www.securedpremiumdomains.com/prioritysales/04fqSp1m9j3dOnce nosarahouserentals.com is ready for purchase, one of my account specialists will contact you.
Thank you and have a good day.
To which, I responded:
Hey, my name is Eric Gehrman.
nosarahouserental.com will be available for purchase soon.
Since you own nosarahouserentals.com, I think you may be interested in nosarahouserental.com.It is recommended to eliminate any confusion to nosarahouserental.com, to own both the singular/plural versions of the domain.
Your purchase will be a one time fee only that includes one year of complimentary registration.
You also have the option to forward nosarahouserental.com to nosarahouserentals.com at no cost.
After purchasing nosarahouserental.com you will never be charged again by Creative Empire.If you do have an interest in purchasing nosarahouserental.com, please email:
xx@ericgehrman.comOnce nosarahouserental.com is ready for purchase, one of my account specialists will contact you.
Thank you and have a good day.
I haven’t gotten a response yet. I’ll let you know when I do.
center a div vertically and horizontally – with jquery
by admin on Sep.21, 2010, under tech
I’ve recently had various issues where I wanted to center a div on a page vertically or horizontally. Doesn’t sound too hard, right?
Before CSS dictated the way a website was displayed, tables ran rampant and everything was laid out in columns and rows. Then CSS evolved a bit and things started to get laid out in block elements or ‘divs’. But divs lack a good way to vertically center an element on the page.
Throw in various screen resolutions and you can get your site looking like *ish very quickly.
There are various ways to vertically center a div on a page – Douglas Heriot goes into a few of them over here. But, nothing really worked until I found an article from Neil Gosskopf.
Basically, the plugin looks at the outside height/width of the element you are trying to center and places a margin on that element accordingly and absolutely positions it.
And the code is as simple as:
$(‘#elementID’).vAlign();
$(‘#elementID’).hAlign();
Ah, jquery. Where have you been my whole life?
Anyways, if nobody else comes across this article, at least I’ll have a reference to it next time I need to vAlign or hAlign an element on a page.
It’s been too long -
by admin on Aug.04, 2010, under Uncategorized
Since I’ve posted up here. What’s been going on you ask?
Well….
I am finally working at a great place, springbox. I absolutely love it too! I’m surrounded by dynamic, passionate, and skilled people. Everyone here brings a great asset to the table and I truly enjoy coming to work everyday! Oh, and their work is pretty good too.
I am still rocking out crossfit, or rather sicfit as it is being called now. The dogs are happy, Amber is beautiful. And I bought a tablesaw. Hopefully the next post will be pictures of something I build!
Anyways, figured I’d open the door for a flood of new posts. Enjoy!
-E
I’m a Mac now, Apparently
by admin on Aug.04, 2010, under Uncategorized
Originally posted 5/04/2009:
So I did it. I sold my old trusty IBM thinkpad and purchased a 6 month old black macbook. Here are my first thoughts:
THIS THING IS AWESOME.
Other thoughts? Besides the obvious, I’m REALLY happy with this laptop. I bought a program called Parallels which basically is a virtual machine where I can run windows (any version) on top of the Mac OSX.
This means that I can have my trusty Visual Studio and MS SQL Server running on my mac. Woo Hoo!! This mac runs pc stuff way better than, well, my pc does. Crazy isnt it? Besides the expensive price tag (which I think now is TOTALLY worth it), I can’t really find anything wrong with this badboy. I upgraded to 4GB of RAM for $40 from newegg. This thing is a hoss.
Visual studio had one thing where I had to figure out – When you step into while debugging, the f11 button was set on mac osx to show the desktop. I went into system preferences and unchecked that as a default key, and whallah! I’m stepping thru just fine now.
Also, the fine folks over at zagg make an invisibleshield for the macbook too; keeping it ever so pretty.
So anyways, if anyone is wondering whether or not to make the switch, I say DO IT!!! It’s totally worth it! I love it
Select Distinct on DataSets
by admin on Aug.04, 2010, under tech
Have you ever wondered how to do a “SELECT DISTINCT” on a dataset column? Well, here’s the low down:
I came across this handy little method for querying a DataSet for distinct records . Say that my data is already in my app and I need to do something with it. Going back to SQL or re-writing the query just isn’t an option, so what can I do?
Microsoft has a helpful kb where it defines a dataset helper class and a SelectDistinct method for accessing data in this way – here. But as always, Microsoft makes simple things complicated. And who wants to write a bunch of classes and functions when we can do the same thing in one line?
Say we have a DataSet ds like so:
| ID | grID | value |
| 1 | 100 | abc |
| 2 | 100 | def |
| 3 | 110 | efg |
| 4 | 120 | hij |
To select distinct grIDs we can just do this:
DataTable distinctDT = ds.Tables[0].DefaultView.ToTable(true, new string [] { “grID” });
This returns:
| grID |
| 100 |
| 110 |
| 120 |
We can now use this distinct DataTable to make our queries on our original DataSet:
ds.Tables[0].Select(“grID = ” distinctDT.Rows[0]["grID"].toString());
Yeah! No helper classes and no extra methods taking up that valuable development space. Hope this helps someone!
I did it, yeay!
by admin on Nov.03, 2008, under running
So as the title suggests, I did it. I did the marathon. I finished in the time that I was hoping for. I could have been a little faster, but hey- couldn’t we all?
What an amazing experience! That was the coolest thing I’ve ever done. I’ll get into the details later. But for now, just know that I did it. Effin A.
E
Im at the start
by admin on Nov.02, 2008, under Uncategorized
Here at the start on staten island. I’m glowing!
So freakin excited. The crowds are crazy. About to get corraled. Yipee!!!
This is awesome.
E
Holy Shnip!
by admin on Nov.01, 2008, under running
Well,
I’m writing this on my way up to NYC from Baltimore. Tomorrow is the big race. I’m riding with both of my bros and my parents. I’m about 75% excited and about 25% nervous.
I finally made my donation goal. Thanks to everyone for that. Now I have one more thing to do – RUN!
The weather couldn’t be more ideal. It’s about 60 degrees and supposed to drop about 10 degrees by tomorrow. The conditions couldn’t be better.
I gotta get into NYC and head into the javitts center to pick up my race packet. I think I’m gonna get those commemorative NYC marathon asics that are on sale at the expo.
Anyways that’s it. I’m excited. I’m nervous. I’m gonna run this mf marathon like a champ.
I’ll tell you all about it when I’m done. I’ll have my phone with me so I’ll be taking as many photos as I can.
Wish me luck!
E
NYC Marathon – 8 More Days, Yipeee!!!!
by admin on Oct.24, 2008, under running
Whew -
So, as the title says, there are only 8 more days until the marathon. I am getting really excited! This has been one hell of a task and I think I am ready for the challenge.
Last Saturday, I finished 20 miles in a little under 4 hours. It was tough. Very tough. I think I’ve officially seen the wall, and it hit me hard. That dreaded thing hit me at about 18 miles. “Stop, you fool!” is what my brain kept telling me. But my heart kept telling me that if i stopped, I would have no chance of finishing in the 26.2 mile marathon. So I kept going.
And although you probably can’t label what I was doing for those last two miles as “running”, god knows I was doing everything I had left in me.
So I am hoping that the crowds of runners and spectators are going to be that extra umph that I’m going to need to finish that damn race. I’ve been training for 5 months, and I’ve racked up something like 472.45 miles since. I am going to do fine (the mantra in my head).
Alright. Well, hopefully I’ll post again once I get closer to the race. But, if not – Wish me luck! I’m going to need it!
-E
