[Tip] How to pass an array as an argument to a function.

| No Comments »

Problem: Help! Iis it possible to pass the values of an array as an argument in my function?

Anwer: Conveniently, Yes! You can indeed use set an array as the argument of a function.

var mapArgs = [0,20,50,10];
draw.apply(this, mapArgs);

function draw(x1,x2,y1,y2)
{ // do something…
alert(x1 + ‘ ‘ + x2 + ‘ ‘ + +y1 + ‘ ‘+ y2);
}

Of course you can use it in a more creative way

var run = { ready : ["Is this awesome?"], getset : ["or…"], go: ["What?!"] }
var func = {
ready: function(str)
{
alert(str);
},
getset: function(str)
{
alert(str.toUpperCase());
},
go: function(str)
{
alert(str + ‘!!!’);
}
}

for (x in run)
func[x].apply(this, run[x]);


[Super Tip!] How to loop or iterate over an object’s key/value pair.

| No Comments »

Problem: Help! Is it possible to loop or iterate through each object’s key/value pair like an array? Answer: A very useful trick for iterating over objects is the use of (for x in object), with this you can completely use objects as array!

myObject = {
“this” : “value1″,
“is” : “value2″,
“awesome” : “value3″
}

for (x in myObject)
alert(‘key : ‘ + x + ‘ / value : ‘ + myObject[x]);


[Solution] How to use this in setInterval and setTimeout problems inside objects

| No Comments »

Problem: One of the problems we find when using setInterval and setTimeout functions in javascript is how the special variable this is switched to the window object on the instance the function executes inside the interval.

Answer: Store the current object in a variable (for this example, the variable is called self) and use that variable for your interval’s function instead of this.

function foo()
{
this.init = function () {
var self = this;
this.interval = setInterval(function(){ self.update(); }, 1000); // this can be setTimeout
};

this.update = function () {
this.counter++;
console.log(this.counter);
};
}

Json Example


How to login as root or how to fix the permission problems when running su commands in WHM

| No Comments »

You can’t use the root user when SSH’ing to WHM but what you can do is issue a SU command once you’ve logged in with another user which isn’t root. On some occassions, you may encounter a no permission error when doing this.

Problem: Help! I can’t seem to login as root in whm so I need to do a SU command instead but i’m getting a permission error!

Answer: In your whm panel, access Security Center -> Manage Wheel Group Users and you will be able to assign the username to the group that allows SU

And that’s the solution to your problem!


How to find, look or search for a specific file in linux

| No Comments »

A common problem for those aren’t aware of using linux are locating certain files(this is when troubleshooting, or simply doing steps from a guide)

Problem: I’m looking for a file in linux! How do I find this?

Answer: You can easily find a file by using the find command:

find / -name “httpd.conf” -print

Note: the -print option will print out the location of the name, / represents what location to start.

If you are interested in knowing more about the find command, look no further than the following link: http://www.ling.ohio-state.edu/~kyoon/tts/unix-help/unix-find-command-examples.htm


Solution for Headers Already Sent problem in php scripts and frameworks

| No Comments »

Headers already sent issue?

Here’s how to fix one of the most common problems in frameworks and websites:

Problem: Help! i’m getting the errors and/or warnings – “Headers already sent!

Answer #1: Check the php files which are usually found in your headers(the ones which are loaded first, typically config.php) and look for extra spaces before your <?php start tag and spaces after ?> end tag. Delete them and voila! Problem Solved!

Answer #2: Check your header scripts(The first few lines of code) and make sure you’re not outputting anything(e.g: an echo, sprintf or a warning message) before using header.


mySQL Super-tip! How to comma-delimit or comma-separate your query results!

| No Comments »

_Problem_: Help! I’d like to make it so my query results to be a comma delimited format!

_Answer_: No problemo! Simply use mySQL’s group_concat function and you’ll get your results in comma delimited values!

SELECT GROUP_CONCAT(id) FROM users WHERE authenticated=1 ORDER BY NULL LIMIT 1 Note: (Optional) ORDER BY NULL is used to prevent unnecessary sorting with filesort

This query would result to: 1,3,4,6,11

That’s It! This is pretty useful when you are going to use the SELECT… IN statement for your subqueries.


mySQL Super-tip! Use LIMIT and OFFSET to paginate your SELECT statements!

| No Comments »

Awesome, it seems that mySQL now supports the OFFSET clause.

This is very useful for paginating your SQL statements.

The following will return the first 10 entries of your select statement:

“SELECT field FROM table LIMIT 10″

This, on the otherhand, will OFFSET your result by 10, selecting your entries #10-20:

“SELECT field FROM table LIMIT 10 OFFSET 10″

Here’s an example of how to capture entries #10-30:

“SELECT field FROM table LIMIT 20 OFFSET 10″

Things just keeps on getting easier and easier!


mySQL: Simplify your multiple WHERE queries with WHERE in

| No Comments »

_Problem #1_: How do I simplify my mySql where queries? _Problem #2_: How can I search through an array in my where statement?

Answer: An awesome trick when it comes to querying multiple where clauses is to use the WHERE <…> IN command.

$id = ’1,4,3,6,8,2′; “SELECT * FROM <…> WHERE id IN ($id)”

Oh and did I mention you can prepend the NOT statement to show results which is NOT included in the list?

$id = ’5,7′; “SELECT * FROM <…> WHERE id NOT IN ($id)”

Oh-Some!


Ultimate guide to installing Windows 7 64-Bit(x64) in your Macbook White and solutions to Bootcamp driver problems!

| 9 Comments »

Problem #1: Help Me! How do I install Windows 7 in my macbook while retaining Mac OSX.

Problem #2: Driver issues! I can’t install my 64 bit bootcamp drivers in Windows 7!

Problem #3: Sound: My Macbook sounds very tinny and awful in Windows 7

Problem #4: Right Clicking: How do I right click in Windows 7 using macbook?

Problem #5: How do I disable my trackpad if my mouse is present in Windows 7?

Problem #6: How do I rebind some of my macbook keys in Windows 7?

_Introduction_: This guide will help you install Windows 7 to your Macbook and also solve the Mac driver issues in Windows 7. Although the case sounds like Bootcamp Drivers doesn’t support Windows 7 64 bit on some macs(Core 2 duo), this is not exactly true as you can still install the 64 bit drivers(Scroll down to the “Windows 64-bit drivers installation” section to see more details). Another solution is to use a virtual machine like VMWare Fusion and Parallels. They basically put Windows and OSX side-by-side and it works wonderfully (Great for web developers and those who want to have that coolness factor added to OSX)

How To Install Windows 7 while retaining your current OSX Installation:

Step 1. Start OSX (Leopard / Snow Leopard), Run Bootcamp Migration Assistant (type “bootcamp” in your finder)

Step 2. During the Bootcamp Migration Wizard, create a partition with around 30gb+ of disk space. After completing the wizard, OSX will prompt you to restart with the Windows 7 CD in your drive.

If OSX is complaining about being unable to continue with bootcamp, you probably need to defrag your Macintosh Drive. To do this, download a defragger software such as “iDefrag” and do a complete defrag on your primary hard disk, unfortunately you can’t really do a complete defrag on the hard disk you are currently running OSX in so you will need an external hard disk to boot from in order to do this. Please see step 1 of “How to backup your OSX and do a Fresh Install of Windows 7 and Leopard / Snow Leopard in your Macbook” below to find out how to run OSX from an external hard disk. Once you’re running OSX in your external drive, run “iDefrag” and defrag your primary hard-drive. Once defragged, restart macbook and you should be able to complete Bootcamp now.

Step 3. After restarting, you’ll be greeted by the Windows 7 setup, complete each steps until Windows 7 asks you where to install it, simply select the drive that is labeled: “BootCamp” and format it(it is disabled until you format it, don’t worry it’s safe.).

Step 4. Congratulations! Windows 7 has been installed, now insert your Leopard / Snow Leopard Installation Disk and Navigate to your CD Drive Folder —> Boot Camp —> Drivers —> Apple and open “BootCamp64″. If an alert window is informing you that your current OS is not supported, don’t worry as it’s easy to fix that. Please scroll down until you get to the Windows 7 64 bit Driver Installation for Macbook section.

How to backup your OSX and do a Fresh Install of Windows 7 and Leopard / Snow Leopard in your Macbook:

Step 1: Backup your system to an external hard disk: Connect an external hard disk to your macbook and run this awesome software called SuperDuper to backup your files. Once backed up restart your macbook and hold Alt/Option until your see a boot selection menu, select the external hard disk with the backup you made in SuperDuper, if all goes well you should be running OSX, only this time, you’re running it in your external hard-drive(your backup). If you are comfortable with how the backup looks, proceed with the following steps:

Step 2. Run Disk Utility (type “disk” in finder to see it from the list of Applications)

Step 3. Format your Macbook’s Hard-drive(Take care that you don’t select the external one.).

Step 4. Insert your Leopard / Snow Leopard Installation CD, while restarting hold ALT/Option to get to the boot menu. Select your Leopard / Snow Leopard CD and complete your OSX installation.

Step 5. After Installation, boot your newly installed OSX and run Bootcamp Migration Assistant (type “bootcamp” in your finder), complete the Bootcamp Migration Wizard and insert your Windows 7 CD before proceeding to restart:

Step 6. After restarting, proceed to install your Windows 7, when Windows 7 ask you where to install it, simply select the drive that is labeled: “BootCamp” and press the format button(don’t worry it’s safe).

Step 7. Congratulations! Windows 7 has been installed, now insert your Leopard / Snow Leopard Installation Disk and Navigate to your CD Drive —> Boot Camp —> Drivers —> Apple and open “BootCamp64″. If an alert window is informing you that your current OS is not supported, don’t worry as it’s easy to fix that in the next section.

Installing your macbook’s Windows 7 64 Bit Drivers. Important: The following is only required if you can’t install the 64bit drivers that’s included in your Leopard/Snow Leopard Installation Disk.

Step 1. In Windows, press Start —> Select “Run” — Type “Cmd”, from the Programs List, right click on “cmd.exe” and select “Run as Administrator”

Step 2. In Windows Command Prompt, enter the following command: net user administrator /active:yes

Step 3. Press Start —> Logout and re-login, select the “Administrator” Account from the selection.

Step 4. Navigate to your Leopard CD Drive Folder —> Boot Camp —> Drivers —> Apple and open “BootCamp64″, complete the installation and you’re all set!

Step 5. Remove the administrator account from showing up by going to Start —> Run —> Cmd —> press enter. Type the following command from the command prompt: net user administrator /active:no

After the installation of these drivers, you may notice your macbook sounding really tinny or pitchy, this is easily fixed by installing the sound driver from Realtek.

Step 6. Download Realtek HD Audio Drivers here.

Step 7. That’s it! Perhaps the final step is to tweak your keyboard/trackpad settings by accessing the Bootcamp Control Panel (This can be seen in your system tray — lower right portion of your task bar, click the arrow besides the date if you can’t see it. If you still can’t see it, simply press Start and type “boot camp” to find it.)

To right click in Windows 7 using your trackpad, touch your trackpad with 2 fingers and click on the button. If you are like me, you may prefer to do a 2 finger tap to do a right click, you can do this by going to Boot Camp Control Panel(Press start and type “Boot Camp” to find it), go to the trackpad tab and click on One Finger Tap to Click and secondary click below Two Fingers.
There’s a nice software called Trackpad Magic, it’s a very handy tool that allows you to disable your trackpad easily via the system tray. It also have a nifty option that automatically disables your trackpad when a mouse is present/plugged in. For the best effect, add a shortcut of the Trackpad Magic program to your startup folder.
If you are uncomfortable with how some of your keyboard keys are setup, you may want to rebind them using the Remapkey software. Remapkey is included with the Windows Server 2003 Resource Kit Tools. You can find it in the c:\Program Files\Windows Resource Kits\Tools directory called remapkey.exe respectively.

Well, that should cover it! Don’t forget to share this in stumbleupon to help those who are looking for a similar solution.