Populating a Form with a dropdown (jQuery)

I thought I’d share this, maybe it’ll help somebody else. Basically this will take the value of the drop down (select) and show() that many input fields.

Javascript

$(document).ready(function(){
$("select[name=example]").change(function () {
$(".hidden_input").hide();
var cnt = $("select[name=example]").val();
while(cnt > 0) {
$(".hidden_input#"+cnt).show();
cnt--;
}
});
});

HTML/CSS

<style>
.hidden_input{
display: none;
}
</style>
<form>
<select name="example">
<option value="1">1 Guests</option>
<option value="2">2 Guests</option>
<option value="3">3 Guests</option>
<option value="4">4 Guests</option>
<option value="5">5 Guests</option>
<option value="6">6 Guests</option>
</select>
</form>
<div id="1" class="hidden_input">1<input name="former" type="text"></div>
<div id="2" class="hidden_input">2<input name="former" type="text"></div>
<div id="3" class="hidden_input">3<input name="former" type="text"></div>
<div id="4" class="hidden_input">4<input name="former" type="text"></div>
<div id="5" class="hidden_input">5<input name="former" type="text"></div>
<div id="6" class="hidden_input">6<input name="former" type="text"></div>

Posted on February 05, 2012

Control Your Windows PC with an Xbox Controller

Xbox 360 Controller

Today I’m going to walk you through setting up an xbox controller to work on your computer and control the mouse / keyboard.

First your going to need an Xbox Controller that works on Windows . If you already have an Xbox controller you can just pick up one of these receivers . (Both links to Amazon, you can find on eBay cheaper).

Next you’ll need to install the drivers for the controller. You can find them on Microsoft’s website here .

Now you should be able to connect your controller to the computer and play any games using it. However you can’t use it to control the mouse yet. What we will need to do next is download JoyToKey from here . I went with the latest Beta version however you can also download the stable (v 4.6 at time of writing).

Now you can edit the configuration of what you’d like each button to do using the JoyToKey GUI.


Posted on January 25, 2012

CSS Code for Wrapping Long URLs and Text

Ran into a problem last night where a long email was messing up a design in smaller screen resolutions.

Perfect fix down below:

pre {
white-space: pre; /* CSS 2.0 */
white-space: pre-wrap; /* CSS 2.1 */
white-space: pre-line; /* CSS 3.0 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
white-space: -moz-pre-wrap; /* Mozilla */
white-space: -hp-pre-wrap; /* HP Printers */
word-wrap: break-word; /* IE 5+ */ }

Thanks to perishable press for this one, read more about it here .


Posted on October 04, 2011

WordPress – Shortcode in PHP files

So in WordPress with plugins etc. you end up using shortcode in posts to keep things simple, an example would be if you want to display a gallery you would just use:

[galleries id="1"]

However trying to this when your outside of the “WordPress Loop” (in your theme files usually) you will hit the problem that WordPress won’t parse the shortcode.

The solution is very simple, just append the following to your shortcode:

echo apply_filters('the_content', '[galleries id="1"]');

And it works!

To read up more on shortcodes in WordPress click here .


Posted on September 11, 2011

Why I am learning Perl

i-want-you-to-learn-perl.jpg

So this post may not be to everyone’s taste, its more a post to remind myself why I’ve decided to learn Perl. If anyone doesn’t know I already know PHP and Java.

Perl is a programming language, It’s Object Oriented, simple to learn and very powerful. Perl stands for: “Practical Extraction and Reporting Language” but others have come up with many more interesting and colorful names for it;

Perl is “the little language that could” it’s designed to be able to do as many tasks as possible in as little time as possible.

“A good perl program is one that gets the job done before your boss fires you.” Larry Wall, the creator of Perl.

Perl is an Interpreted language, so you don’t have to compile it like you do Java, C, C++ etc. For fast development work, that’s a godsend.

Perl has been successfully used for a lot of diverse tasks: text processing, system administration, web programming, web automation, GUI programming, games programming, code generation, bio-informatics and genealogical research, lingual and etymological research, number crunching, and testing and quality assurance.

Perl Pros

  • Cross Platform compatibility. A perl script for linux/unix will work just as well in windows and vice versa, and the only exceptions to that rule are those dictated by the operating system itself. (for example file paths are different in windows and unix.)
  • Online support. Perl has been around since the early 90’s, its exceptionally well known and thousands of tutorial and help sites abound on the internet.
  • CPAN.org, a massive collection of perl modules that can do almost anything, someone has usually done the work for you.
  • Taint mode, this helps you to write secure code by not trusting any data provided by the users until you have tested and declared it safe.

Perl Cons

  • Speed. Apparently with a very large program (Like word or something) the sheer size of it would make it extremely slow to compile at runtime.. This is the only Con I’ve found about Perl!

Posted on August 19, 2011

PyroCMS – CMS on the CodeIgnitor Framework

Update as of August 2020 - PyroCMS now relies upon Laravel.

pyro-cms.png

So lately I’ve been playing around with PyroCMS , for any of you who don’t know about Pyro, its basically an open source content management solution that iss based on the CodeIgnitor framework. What does that mean you ask?

  • MVC design pattern. (Model->View->Controller)
  • Security, Cross-Site Request Forgery protection, XSS filtering and very secure password encryption.
  • Caching, in order to achieve maximum performance.
  • Translated into 16 languages!
  • Extremely lightweight!
  • Support for modules, themes, plugins and widgets!
  • Multi – Site Manager (In Pro Version £45 )

Really it takes the pain out of making your standard websites, you’ll have an area where the client can update their website in a simple environment and thanks to ‘permissions’ you can be sure they won’t mess anything up!

Of course there is always going to be a stage when your better off without a framework, but for projects that it will work for, PyroCMS will save you a BUNCH of time!


Posted on August 14, 2011

Esprimo Mobile v5535 and Ubuntu 10.10

fujitsu_siemens_esprimo_mobile_v5505_v5545.jpg

So I ended up picking up a cheap Esprimo Mobile v5535 a few days ago, long story short; laptop broke, Argos have sent it off for repairs that will take 2-3 weeks, that’s the last time I buy a laptop from Argos.

Anyway the Esprimo Mobile isn’t exactly a cutting edge laptop, if you said it was outdated you wouldn’t be wrong. When I got it the OS installed was Windows Vista, “ambitious” I thought, of course I can’t have any kind of computer without tinkering with it endlessly to find out the best way performance wise for it to be running, Ubuntu was in my head from the start but an apparently broken CD-drive was putting an end to that.. I’ve never tried to install Ubuntu from a network and I wasn’t going to start now, (USB wasn’t an option in boot) instructions on Ubuntu’s Support don’t make a network install look simple!

A few Registry edits later, (one too many in-fact) I had the CD-drive working but Windows locked in that state of “somethings missing, would you like to use Startup Repair?” and then when using Startup repair just rebooting the computer into the same cycle. No worries though at this stage I just began installation of Ubuntu. I was surprised to see that the Wi-Fi worked from the get-go, is nDiswrapper ever needed any more? 😛 The only issue was the resolution seemed to go no higher than 800×600.. Of course a few google searches later and I found this article which explains how to install the drivers for SiS Graphics.

Using their default Xorg.conf and driver I rebooted only to find the machine now screwed graphic wise, lines all down the screen changing.. I originally thought it was the refresh rate but hell this is Linux, you could set every setting to the absolute worst one possible and still be able to change back, where is that option Windows? So I switched to a terminal window (Ctrl + Shift + F5 (any F key) for those interested) opened up Xorg.conf and using sudo nano changed what seemed to be affecting the graphics; Option "UseTiming1366" "yes" to Option "UseTiming1366" "no" (didn’t know yet if it was the problem) rebooted and finally got a 1280×800 resolution!

So the point of this story is; It’s great how in Linux you’ll mess something up and still be able to repair it via a terminal window, and if you need better resolution on your Esprimo Mobile click this link .


Posted on February 04, 2011

Installing PEAR in WAMP

pear.png

So this evening I went about attempting to install PEAR on my WAMP installation, this should be as simple as opening up a command window navigating to C:/wamp/bin/php/*phpversion* and running go-pear.bat, however upon doing this I ran into the following errors:

phar “C:\wamp\bin\php\php5.3.0\PEAR\go-pear.phar” does not have a signature
PHP Warning: require_once(phar://go-pear.phar/index.php): failed to open stream: phar error:
invalid url or non-existent phar “phar://go-pear.phar/index.php” in C:\wamp\bin\php\php5.3.0\PEAR\go-pear.phar on line 1236
Warning: require_once(phar://go-pear.phar/index.php): failed to open stream: phar error:
invalid url or non-existent phar “phar://go-pear.phar/index.php” in C:\wamp\bin\php\php5.3.0\PEAR\go-pear.phar on line 1236
Press any key to continue . . .

A couple of Google searches later I got the answer needed to fix my problem, simply running this command instead:

php -d phar.require_hash=0 PEAR/go-pear.phar

A couple of questions later PEAR was successfully installed and running, so if your running into the above error you now know what to do!


Posted on December 27, 2010

Cross Browser .PNGs

cross-browser-png.png

I don’t know about you, but I’m hoping for a 2011 where all browsers handle .PNG’s the same!


Posted on December 24, 2010

Password Security

password_reuse.png

Credit to XKCD.


Posted on December 24, 2010