Linux: How To Mount A Drive Or Device

How to mount a basic device or drive:

mount [device] [destination path]

For example:

mount /dev/sdb1 /mnt/disk2

Edit your /etc/fstab to make it automount at boot:

/etc/fstab:
[device] [destination path] auto default 0 0

For example:

/dev/sdb1 /mnt/disk2 ext3 defaults 0 0
Posted in Everything Else | Leave a comment

VIM: How To Show Control Characters

How to show all control characters in VIM:

:set list

And to disable:

:set nolist
Posted in Editors, VIM | Leave a comment

Unix: How to Install BerkeleyDB From Source

This documentation is buried in the source as HTML, so I’m posting it here for convenience.

Building for UNIX/POSIX

The Berkeley DB distribution builds up to four separate libraries: the base C API Berkeley DB library and the optional C++, Java, and Tcl API libraries. For portability reasons, each library is standalone and contains the full Berkeley DB support necessary to build applications; that is, the C++ API Berkeley DB library does not require any other Berkeley DB libraries to build and run C++ applications.

Building for Linux, Mac OS X and the QNX Neutrino release is the same as building for a conventional UNIX platform.

The Berkeley DB distribution uses the Free Software Foundation’s autoconf and libtool tools to build on UNIX platforms. In general, the standard configuration and installation options for these tools apply to the Berkeley DB distribution.

To perform a standard UNIX build of Berkeley DB, change to the build_unix directory and then enter the following two commands:

../dist/configure
make

This will build the Berkeley DB library.

To install the Berkeley DB library, enter the following command:

make install

To rebuild Berkeley DB, enter:

make clean
make

If you change your mind about how Berkeley DB is to be configured, you must start from scratch by entering the following command:

make realclean
../dist/configure
make

To uninstall Berkeley DB, enter:

make uninstall

To build multiple UNIX versions of Berkeley DB in the same source tree, create a new directory at the same level as the build_unix directory, and then configure and build in that directory as described previously.

Source: db-5.0.26.tar.gz

Posted in BerkeleyDB, Databases, Linux, Ubuntu | Leave a comment

CSS: How To Always Show Vertical Scrollbar

To avoid webpage shifting, you can always have the vertical scrollbar visible by doing this:

html { overflow-y: scroll; }

Note: This only seems to work in Firefox and Internet Explorer.

Posted in CSS, Firefox, Internet Explorer | Leave a comment

Ubuntu: Flushing IpTables Causes Loss of Internet Connection

If you are trying to disable the firewall, but lose Internet connection in the process, use this script:

iptables -F
iptables -X
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT

Source: https://help.ubuntu.com/community/IptablesHowTo#Disabling%20the%20firewall

Posted in Firewall, IpTables, Linux, Ubuntu | Leave a comment

Linux: How To Edit resolv.conf Using dhclient.conf

So, you’re trying to get here:

/etc/resolv.conf:
nameserver 192.168.1.1
domain aaa.com
search aaa.com bbb.com

You need to edit dhclient.conf like this:

/etc/dhcp3/dhclient.conf:
supersede domain-name-servers 192.168.1.1;
supersede domain-name "aaa.com";
append domain-name " bbb.com";

There must be a space before the bbb.com

Then run dhclient:

# /sbin/dhclient
Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0/00:1b:78:a9:4a:a4
Sending on   LPF/eth0/00:1b:78:a9:4a:a4
Sending on   Socket/fallback
DHCPREQUEST of 192.168.1.19 on eth0 to 255.255.255.255 port 67
DHCPACK of 192.168.1.19 from 192.168.1.1
bound to 192.168.1.19 -- renewal in 42626 seconds.

Then look at your new resolv.conf.

Posted in Linux, Ubuntu | Leave a comment

Windows: Kill All Chrome Processes At Once

Run this on the command line:

taskkill /F /IM chrome.exe /T
/F = force kill
/IM = image name
/T = kill all child processes as well

To create a shortcut, right-click the desktop, then New -> Shortcut.

For location, type the following:

taskkill.exe /F /IM chrome.exe /T

Then, give your shortcut a name like “Kill Chrome”, and you’re done.

Posted in Browsers, Chrome, Windows, Windows Vista | Leave a comment

Ubuntu: How To Enable Sound

HP xw6400 Workstation: How to fix your machine if your speakers don’t work.

Determine your sound card model:

cat /proc/asound/card0/codec#* | grep Codec

Look up the model in this list:
http://www.kernel.org/doc/Documentation/sound/alsa/HD-Audio-Models.txt

Edit your ALSA (Advanced Linux Sound Architecture) conf file:

/etc/modprobe.d/alsa-base.conf:
options snd-hda-intel model=hp-bpc

In general:

options snd-hda-intel model=MODEL

Reboot.

Source: https://help.ubuntu.com/community/HdaIntelSoundHowto

Posted in Ubuntu | Leave a comment

Ubuntu: How to Determine Motherboard Type

lshw – list hardware

sudo lshw

lspci – list all PCI devices

sudo lspci
Posted in Ubuntu | Leave a comment

Ubuntu: APT and DPKG

How to display the files of a package installed?

To list all the files provided by the installed package foo execute the command

dpkg --listfiles foo

Note that the files created by the installation scripts aren’t displayed.

http://www.debian.org/doc/FAQ/ch-pkgtools.en.html

Posted in Linux, Ubuntu | Leave a comment

Windows Vista: How To Enable Telnet

By default, Vista installs without telnet available.

Here is how to enable telnet in Vista:

1. Open ‘Control Panel’
2. Select ‘Programs and Features’
3. In the left column, select ‘Turn Windows features on or off’ (get ready for the annoying UAC prompt)
4. Check the box next to telnet (and any other obscure services you may want enabled), and wait while Vista thinks for a while.

Source: http://www.arsgeek.com/2007/03/20/enable-telnet-in-windows-vista/

Posted in Windows, Windows Vista | Leave a comment

Fedora: How To Flush DNS Cache

nscd -i hosts
Posted in DNS, Fedora, Linux | Leave a comment

Windows: Open Task Manager Minimized On Startup

Windows’ Task Manager lets you easily shut down hidden or troubled apps, check which programs are hogging RAM, and analyze CPU usage. You may be a Task Manager aficionado, but you may not know the fastest ways to reach the utility.

In Windows 2000, you can launch Task Manager by pressing Ctrl- Alt- Delete to display the Windows Security dialog box, and then clicking the Task Manager button.

In Windows XP, Ctrl- Alt- Delete brings up the Task Manager immediately without any intervening dialog box. Another fast way to get to Task Manager–without using the three-finger salute: Simply right-click an empty spot on the taskbar and choose Task Manager.

And here’s a trick to make Task Manager even handier: Reader Timothy J. Luoma of Gainesville, Florida, points out that when Task Manager is running, it displays a tiny animated CPU-usage icon in the system tray (located in the lower-right corner of the screen). You can also hold your pointer over the icon for a moment to see the CPU-usage percentage displayed in a tool tip. If you like this feature, why not make Task Manager run all the time by placing a shortcut to it in your Startup folder?

Right-click the Start button and choose Open. Double-click Programs, then double-click Startup. Choose Start, Search, For Files or Folder, type taskmgr.exe in the top box, enter your start-up drive in the ‘Look in’ box (for most people it will be c:\), and click Search Now. When you see the Task Manager program file listed in the Search Results window, right-drag it to your open Startup folder. When you release the mouse button, choose Create Shortcut(s) Here. Now right-click the new shortcut and choose Properties. Select the Shortcut tab and choose Minimized from the Run drop-down list. Click OK. To keep Task Manager out of your way when you don’t need it, double-click the shortcut to launch it, and in the menu bar at the top of the Task Manager window, choose Options, Hide When Minimized.

Task Manager will now start invisibly, but you’ll be able to open its window anytime by double-clicking the CPU-usage icon in the system tray.

Source: http://www.pcworld.com/article/68776-2/windows_tips_take_charge_of_windows_audio_controls.html

Posted in Windows Vista | Leave a comment

Ubuntu: Show Dynamic Title in Terminal

A quick solution to this problem is to make sure that /etc/bash.bashrc file has a line uncommented.

vim /etc/bash.bashrc

Then, look for this line and make sure it is NOT commented out:

PROMPT_COMMAND='echo -ne "\033]0;{USER}@${HOSTNAME}: ${PWD}\007"'
Posted in Ubuntu | Leave a comment

How To Assign Local IP Addresses Based on MAC Address

Assigning IP addresses based on MAC addresses prevents the router from occasionally giving new IP addresses to your local machines.

On a Netgear Router:

  • go to LAN Setup.

Instructions From the Netgear Router LAN Setup screen:

Address Reservation

When you specify a reserved IP address for a PC on the LAN, that PC will always receive the same IP address each time it accesses the DHCP server. Reserved IP addresses should be assigned to servers that require permanent IP settings.

To Reserve An IP Address:

  • Click the Add button.
  • Select the radio button of the Computer you wish to add from the Address Reservation Table.
  • If the Computer is not on the Address Reservation Table, enter the IP Address, MAC Address, and Device Name of the computer you wish to add.
  • Click the Add button when finished.
Posted in Netgear, Routers | Leave a comment

Ubuntu: Workplace Switcher Labels

By default, you can’t add labels in the workplace switcher in Ubuntu.

To enable them, go to System > Preferences > Appearance.

Click the Visual Effects tab.

Then, click None, to disable all effects.

Now, you should be able to right-click your workplace switcher, click Preferences, and add labels to each workspace.

Posted in Linux, Ubuntu | Leave a comment

How to Edit resolv.conf Permanently

Edit this file:

# vim /etc/dhcp3/dhclient.conf

To append a search domain, add this to the file:

append domain-name " mycrazydomain.com";

…which will allow your machine to search *.mycrazydomain.com.

Note the initial space within the double quotes.

Then run:

# /sbin/dhclient

Your /etc/resolv.conf file should now look like this:

search [whatever else was previously here] mycrazydomain.com
Posted in Linux, Ubuntu | Leave a comment

PHP: How To Get A Time Difference in Human Readable Format

A simple function to return the time since a given timestamp in the past.

function time_since($timestamp) {

  // Init
  $hash = array();
  $now = time();

  // Breakdown the time diff
  $diff = $now - $timestamp;
  $hash['day'] = floor($diff / 86400);
  $diff = $diff % 86400;
  $hash['hour'] = floor($diff / 3600);
  $diff = $diff % 3600;
  $hash['minute'] = floor($diff / 60);
  $hash['second'] = $diff % 60;

  // Build the return string
  $string = '';
  foreach ($hash as $unit => $amount) {
    if ($amount > 0) {
      if ($amount > 1) $unit .= 's';
      $string .= "$amount $unit ";
    }
  }
  $string .= 'ago';

  return $string;
}

Example:

$stat = stat($filename);
$mtime = $stat[9];
$string = time_since($mtime)
echo $string;
// prints "12 days 11 hours 10 minutes 9 seconds ago"
Posted in PHP | Tagged , , , | 1 Comment

PHP: Pass By Reference vs. Pass By Value

By default, PHP is pass by value.

<?
function pass_by_value($param) {
  push_array($param, 4, 5);
}

$ar = array(1,2,3);

pass_by_value($ar);

foreach ($ar as $elem) {
  print "<br>$elem";
}
?>

The code above prints 1, 2, 3. This is because the array is passed as value.

<?
function pass_by_reference(&$param) {
  push_array($param, 4, 5);
}

$ar = array(1,2,3);

pass_by_reference($ar);

foreach ($ar as $elem) {
  print "<br>$elem";
}
?>

The code above prints 1, 2, 3, 4, 5. This is because the array is passed as reference, meaning that the function (pass_by_reference) doesn’t manipulate a copy of the variable passed, but the actual variable itself.
In order to make a variable be passed by reference, it must be declared with a preceeding ampersand (&) in the function’s declaration.

Source: http://www.adp-gmbh.ch/php/pass_by_reference.html

Posted in PHP | Leave a comment

Unusual Paragraph Problem

This is a most unusual paragraph. How quickly can you find out what is so unusual about it? It looks so ordinary that you would think that nothing is wrong with it at all, and, in fact, nothing is. But it is unusual. Why? If you study it and think about it, you may find out, but I am not going to assist you in any way. You must do it without any hints or coaching. No doubt, if you work at it for a bit, it will dawn on you. Who knows? Go to work and try your skill. Good luck!

What is unusual about the above paragraph?

Posted in Cool Problems | 1 Comment