Showing posts with label power user. Show all posts
Showing posts with label power user. Show all posts

Saturday, March 10, 2012

fix mp3 replay gain (AKA normalize) quick and easy

Some things are SO much easier on Linux than Windoze. Don't need an audio editor, even an open-source one like audacity to perform this routine task on Ubuntu.

sudo apt-get install mp3gain

dir=/music/EckhartTolle-StillnessSpeaks
 
# fix replay gain for all songs in $dir
for i in `ls -1 $dir`; do mp3gain -r -k $i; done


where:
-r: radio mode: apply track gain automatically
-k: prevent audio clipping


Thursday, August 25, 2011

linux: vnstat rocks!

vnstat is a superb tool to monitor monthly bandwidth usage.

I get notified by my ISP when I hit my monthly download quota (25 GB) that my speed will now be reduced to 256 kbps. Sometimes I'm left wondering how the heck I hit 25 gigs of downloading. So I started looking for a tool on Ubuntu that would monitor my bandwidth usage and show me daily/weekly/monthly download totals.

Requirements: It should work silently and unobtrusively in the background, and it should start automatically on reboot like a daemon. It would be nice to have it display graphical graphs. Also nice to have it display realtime stats (e.g. current rx and tx speeds).

There are quite a few tools that I found: bandwidthd, bwmon, bwbar etc (complete list here: http://www.ubuntugeek.com/bandwidth-monitoring-tools-for-ubuntu-users.html).

I didn't try all of them, but the most popular (or the one that appears at the top of the google search results for "bandwidth monitor tool ubuntu") is bandwidthd, and I just didn't have the patience to get it to work. There's no user manual, no real how-to and I gave up quickly on it.

vnstat saved the day. It exactly meets my requirements. You don't need to install it from the tarball either (in fact, that didn't work too well for me, I kept getting post-install configuration errors), and if you're on ubuntu, vnstat is in the standard apt repositories.

vnStat is a console-based network traffic monitor for Linux and BSD that keeps a log of network traffic for the selected interface(s). It uses the network interface statistics provided by the kernel as information source. This means that vnStat won't actually be sniffing any traffic and also ensures light use of system resources.

 

[08:17:59] ~ $ vnstat -d

eth1 / daily
     day         rx      |     tx      |    total    |   avg. rate
------------------------+-------------+-------------+---------------
08/24/11 134.81 MiB | 7.24 MiB | 142.05 MiB | 13.47 kbit/s
08/25/11 84.21 MiB | 5.63 MiB | 89.85 MiB | 24.82 kbit/s
------------------------+-------------+-------------+---------------
estimated 244 MiB | 14 MiB | 258 MiB |

[08:18:04] ~ $ vnstat -s

                  rx      /      tx      /     total    /   estimated

eth1:
Aug '11 219.02 MiB / 12.88 MiB / 231.90 MiB / 293.00 MiB
yesterday 134.81 MiB / 7.24 MiB / 142.05 MiB
today 84.21 MiB / 5.63 MiB / 89.85 MiB / 258 MiB

 

Tuesday, December 28, 2010

windows: setting environment variables from the command line

The standard route is rather slow and painful, even on Win7:
“MyComputer | Properties | Advanced System Settings | Environment Variables”… that’s a lot of clicks just to get to the point where you can add/edit an environment variable.

Thankfully, there’s a much easier alternative via the command line.

But first, did you know where the environment variables are stored on the file system? Until now I thought they were in some system config file, but it turns out they're actually stored in the registry itself (which technically is a system config file).
  • The logged-in user’s env variables go here:
    HKEY_CURRENT_USER\Environment
  • The machine-wide env variables go here:
    HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment
The setx utility lets you change env variables for either the user or machine. The good old set command let’s you add/edit env variables too, but there are a few major differences from setx:
  • setx will permanently change the value of an env variable. The changes made by set last only for the current session.
  • Changes made by setx are not immediately visible – that is, they are not available to the current session. However, set’s changes are immediately visible.
  • You can’t delete env variables with setx, like you can with set. For example:
    set someVar=
    will delete the environment variable ‘someVar’ for the current session, but you can’t do something like this with setx.

    Instead, you have to use the “reg” utility to delete environment variables (that may or may not have been created with setx):
    REG delete HKCU\Environment /V someVar
Okay, so do you create a permanent environment variable via setx? It’s pretty straightforward:
  • To set an env variable for the current user:
    SETX <Variable> <Value>
  • To set an env variable for the machine (i.e. globally):
    SETX <Variable> <Value> -m
Example:
setx  CLASSPATH  C:\Users\ambars\.m2\repository\com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;.

source: http://ss64.com/nt/setx.html

Friday, September 24, 2010

favorite shell prompt in BASH

 

Here’s my typical prompt in mintty/cygwin:

[ambars@mintty 11:54:28 ~] $

 

And here’s the code: simply append to ~/.bashrc:

export PS1="[\u@mintty \e[0;33m\t\e[m \w] \$ "

Source:
Bash Shell PS1: 10 Examples to Make Your Linux Prompt like Angelina Jolie

Thursday, September 23, 2010

windows: powertools that replace the plain old netstat command

  • currports: powerful, easy-to-use and free! Can filter processes. A perfect replacement for port explorer.
  • tcpview (sysinternals)
  • procmon (sysinternals)
  • port explorer (Trialware, old favorite. Development has long stopped since the parent company seems to be dead. Also redundant now, thanks to the above free options)

Friday, April 30, 2010

linux: how to see which packages are taking the most disk space

Here's a little scriptfoo that's very useful when you're running out of disk space. When you need to reclaim hard drive real estate urgently by removing those useless "Engineering and Scientific" packages, run diskhoggers. Of course, it only works on RPM-based systems, so it's useless on Ubuntu/Debian etc, but there should be equivalents (e.g. using dpkg and/or synaptic apt-get) on those systems too.

alias diskhoggers='rpm -qa --qf "%10{SIZE}\t%{NAME}\n" | sort -n' 


Here's an example run on my system:

[root@noumPC ~]# diskhoggers | tail -n 30
15370931 bcel
15585349 gutenprint
15615584 gnome-applets
16021416 gcc
16574947 webkitgtk
16742780 nautilus
17773959 vim-common
18113087 firefox
18147692 libgweather
19693980 libicu
20174285 python
20250203 ghostscript
22082141 fedora-release-notes
22312309 kernel-devel
22371021 python-lxml
24697430 xulrunner
25032963 foomatic-db-ppds
25455524 libpurple
26376798 eclipse-jdt
29624088 perl
32984533 eclipse-platform
46820396 qt-x11
49233851 google-chrome-beta
49484310 valgrind
50371329 libgcj
80240654 kernel
84381565 kernel
85572888 java-1.6.0-openjdk
111799012 glibc-common
246952321 java-1.5.0-gcj-javadoc

Sunday, April 11, 2010

linux: how to safely add an ssh-agent with default key upon login

# safely add key to ssh-agent on login

test=`ps -ef | grep ssh-agent | grep -v grep | awk '{print $2}' | xargs`

if [ "$test" = "" ]
then
# there is no agent running
if [ -e "$HOME/agent.sh" ]
then
# remove the old file
rm -f $HOME/agent.sh
fi
# start a new agent
ssh-agent | grep -v echo &> $HOME/agent.sh
ssh-add /root/.ssh/id_rsa
fi

test -e $HOME/agent.sh && source $HOME/agent.sh



Adapted from: http://drupal.star.bnl.gov/STAR/blog-entry/jeromel/2009/feb/06/how-safely-start-ssh-agent-bashrc

Friday, April 9, 2010

linux: mutt is so much better than mail

Here's how to send a email from the linux command line, attach files to it, and have it sent to multiple recipients! Much better than having to paste the contents of a config file or text file into the body of an email and then use the plain old "mail" command.

echo | mutt  -s interesting_logs_please_check  -a syslogs.tar.gz admin@domain.org, user1@domain.org, user2@domain.org


references:

http://www.shelldorado.com/articles/mailattachments.html
(excellent)

"Multiple recipients may also be specified by separating each address with the , delimiter"
(tested this and it works)
http://www.freebsd.org/doc/handbook/mail-agents.html

Thursday, October 29, 2009

windows: installing the recovery console on xp

To install the Recovery Console in Windows XP, follow these steps:


1.    Insert the Windows XP CD into the CD-ROM drive.
2.    Click Start, and then click Run.
3.    In the Open box, type d:\i386\winnt32.exe /cmdcons where d is the drive letter for the CD-ROM drive. In the case of 'Microsoft Windows XP Professional x64 Edition, type d:\amd64\winnt32.exe /cmdcons where d is the drive letter for the CD-ROM drive.
4.    A Windows Setup Dialog Box appears. The Windows Setup Dialog Box describes the Recovery Console option. To confirm the installation, click Yes.
5.    Restart the computer. The next time that you start your computer, "Microsoft Windows Recovery Console" appears on the startup menu.

Tuesday, October 20, 2009

windows: how to schedule a high-frequency task

Task Scheduler doesn't let you schedule tasks with fine-grained frequencies. For example, you can't schedule a task to execute every minute, or every few hours. The maximum frequency that can be given to a task is "daily" which sucks because you need to run some programs more often than that (linux's cron is still the king!)

Here's the solution. It involves using the rather powerful "schtasks" windows command:

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/schtasks.mspx?mfr=true

Here's what I used:
schtasks /create /sc hourly /mo 2 /tn "autoupdatesourcecode" /tr c:\tools\autoupdatesourcecode.bat


And this is my super-simple autoupdatesourcecode.bat:
cd d:\Codebase\trunk\pi\
d:
svn up

Tuesday, October 6, 2009

batch file to fix WMI errors

There's a lot to learn about batch file scripting from this example!
source

net stop winmgmt

pause

c:

cd c:\windows\system32\wbem

rd /S /Q repository

regsvr32 /s %systemroot%\system32\scecli.dll

regsvr32 /s %systemroot%\system32\userenv.dll

mofcomp cimwin32.mof

mofcomp cimwin32.mfl

mofcomp rsop.mof

mofcomp rsop.mfl

for /f %%s in ('dir /b /s *.dll') do regsvr32 /s %%s

for /f %%s in ('dir /b *.mof') do mofcomp %%s

for /f %%s in ('dir /b *.mfl') do mofcomp %%s

mofcomp exwmi.mof

mofcomp -n:root\cimv2\applications\exchange wbemcons.mof

mofcomp -n:root\cimv2\applications\exchange smtpcons.mof

mofcomp exmgmt.mof

Monday, October 5, 2009

linux: adding swap space on-the-fly to your system

You might find that the swap partition you specified at install-time just isn't enough anymore. Maybe you've added more RAM to your machine and need to increase the swap partition accordingly. Or maybe you're upgrading your system to a version that uses more swap in relation to physical RAM. Perhaps you're running Oracle. In case your machine is swapping like mad and you just can't take it down right now to add more RAM, you can add more swap space on the fly using the following procedure. As an example, to keep the machine from running out of memory entirely and freezing up, we'll add 128 MB more swap space by creating a swap file. First we check out the memory usage:

[root@domain /root]# free -m
total used free shared buffers cached
Mem: 251 242 8 22 11 32
-/+ buffers/cache: 198 52
Swap: 133 133 0

Make sure we have 128 MB laying around somewhere:

[root@domain /root]# df
Filesystem 1k-blocks Used Available Use% Mounted on
/dev/hda9 132207 33429 91952 27% /
/dev/hda1 15522 2537 12184 17% /boot
/dev/hda6 6143236 739000 5092176 13% /opt
/dev/hda7 1035660 836204 146848 85% /usr
/dev/hda5 2071384 344048 1622112 17% /usr/local
/dev/hda8 303344 14439 273244 5% /var

OK, we're going to make a swap file in /opt by using dd to create a file 128 MB in size.

[root@domain /opt]# dd if=/dev/zero of=swapfile bs=1024 count=132207
132207+0 records in
132207+0 records out
[root@domain /opt]# ls -l
total 132364
drwxr-xr-x 20 usr-3 users 4096 May 22 10:46 usr-3
drwxr-xr-x 2 root root 16384 Feb 21 07:04 lost+found
-rw-r--r-- 1 root root 135379968 May 29 11:52 swapfile

Let's not make it world-readable...

[root@domain /opt]# chmod 600 swapfile
[root@domain /opt]# ls -l
total 132364
drwxr-xr-x 20 usr-3 users 4096 May 22 10:46 usr-3
drwxr-xr-x 2 root root 16384 Feb 21 07:04 lost+found
-rw------- 1 root root 135379968 May 29 11:52 swapfile

Now we set up the swap area and enable it.

[root@domain /opt]# mkswap swapfile
Setting up swapspace version 1, size = 135372800 bytes
[root@domain /opt]# swapon swapfile

And voila! Twice as much swap as before.

[root@domain /opt]# free
total used free shared buffers cached
Mem: 257632 254632 3000 2512 36172 15096
-/+ buffers/cache: 203364 54268
Swap: 268708 136512 132196

You can append a line like this to /etc/fstab to enable your swap file automatically at boot time:

/opt/swapfile swap swap defaults 0 0


source

Tuesday, September 15, 2009

how to enable tap zones on dell mouse drivers

To unlock the native touchpad features which are masked by Dell's touchpad software:

1. Go to control panel and select MOUSE to see what options are available (very few) and close that all up.

2. Next click on the Windows Start icon and type regedit in the search box.
Windows Registry will open.

Navigate to HKEY_LOCALMACHINE\SOFTWARE\Alps\Apoint and look for the key UseCustomGUI (it's the 2nd to last entry on the list)

Change the value from 1 to 0 and click on OK

3. Next minimize the registry (don't close it yet).
Goto Control Panel and select MOUSE.
Now all the ALPs settings are unlocked and appear here.

For example the GESTURES feature is now showing.
Select GESTURES tab and check ON the box for
Use Back/Forward Buttons.
Then click APPLY and OK.
Close the Mouse settings and close the Control panel.

4. Now go back to your registry setting and change
UseCustomGUI back to it's original value of 1 and close it and the reg editor.

Everything is back exactly as it was but the feature remains enabled.

All done....now when your surfing just swipe your finger along the top edge of the touch pad to go back and forward.


source

Monday, September 14, 2009

vbscript: create system restore points with no fuss

Here's how to create a simple VBscript that will create a restore point when you double-click it:

1. Save the code below to, say, c:\system_restore.vbs:

Set SRP = GetObject( "winmgmts:\\.\root\default:Systemrestore" )
CSRP = SRP.CreateRestorePoint( "Before Changes", 0, 100 )

2. Double-click the script file you just created, any time you want to create a fresh System Restore Point.

It only takes a few seconds to do this. And no dialogues are shown to confirm that a Restore Point was created. If you want to double-check you can click "Start | All Programs | Accessories | System Tools | System Restore" and click "Restore My Computer To An Earlier Time."

You'll see the restore point you just created (called "Before Changes") right there. Now be sure to cancel out of System Restore.

source

Monday, August 3, 2009

linux: rename multiple files with one command

We're going to do this simple task with a simple regex find+replace in sed:

for i in *.avi
do
    j=`echo $i | sed 's/mymovies/myflicks/g'`
    mv "$i" "$j"
done

Can also be written on a single line as:
for i in *.avi; do j=`echo $i | sed 's/find/replace/g'`; mv "$i" "$j"; done

source

Friday, October 31, 2008

windows: removing the welcome/login screen in xp for single user logon

To log in automatically, type this command (it's a shortcut to 'User Accounts'):

control userpasswords2


Click the desired user's logon name, then click OK and enter the password when prompted (which is probably a blank).


To set the password for the current user to a blank, get to a cmd prompt and run this command:
net user "%UserName%" ""{Enter}



source

Monday, March 10, 2008

windows: the TcpTimedWaitDelay registry setting

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters

The TcpTimedWaitDelay key in the Windows registry determines the time that must elapse before TCP can release a closed connection and reuse its resources. This interval between closure and release is known as the TIME_WAIT state or 2MSL state. During this time, the connection can be reopened at much less cost to the client and server than establishing a new connection.

Reducing the value of this entry allows TCP to release closed connections faster, providing more resources for new connections. However, if the value is too low, TCP might release connection resources before the connection is complete, requiring the server to use additional resources to reestablish the connection.

Tuesday, May 22, 2007

excel: locate duplicates by using conditional formatting

Set up the first conditional formatting formula



I'll start by setting up a conditional format for the first data cell.

Later, I'll copy that conditional format for the whole range.



In my example, cell A1 contains

a

column heading (Invoice), so I will select cell A2, and then click Conditional Formatting

on the Format

menu. The Conditional Formatting dialog box opens.

The first box contains the text,

Cell Value Is. If you click the arrow next to this box, you can choose Formula Is.



Example





After you click

Formula Is, the dialog box changes appearance. Instead of boxes for between x and y,

there is now a single formula box. This formula box is incredibly

powerful. You can use it to enter any formula that you can dream up, as

long as that formula will evaluate to TRUE or FALSE.





In this case, we need to use a COUNTIF formula. The formula to type in the box is:





=COUNTIF(A:A,A2)&gt;1


This formula says: Look through the entire

range of column A. Count how many cells in that range have the same

value as cell A2. Then, compare to see if that count is greater than 1.



When there are no duplicates, the count will always be 1; because

cell A2 is in the range, we should find exactly one cell in column A

that contains the same value as A2.



Note&nbsp; In this formula, A2 represents the current

cell — that is, the cell for which you are setting up the conditional

format. So, if your data is in column E and you are setting up the

first conditional format in cell E5, the formula would be =COUNTIF(E:E,E5)&gt;1.





Choose a color to highlight duplicated entries







Now it is time to select an obnoxious (that is, obvious) format to identify any duplicates that are found. In the Conditional Formatting dialog box, click the Format button.



Example



Click the Patterns tab and click a bright color swatch, like red or yellow. Then click OK to close the Format Cells dialog box.



Example





You will see the selected format in the preview box. Click OK to close the Conditional Formatting dialog box, and…



Example



Nothing happens. Wow. If this is your first time setting up

conditional formatting, it would be really nice to get some feedback

here that it worked. But, unless you are lucky enough that the data in

cell A2 is a duplicate of the data in some other cell, the condition is

FALSE and no formatting is applied.



Copy the conditional formatting to the rest of the cells



You need to copy the conditional formatting from cell A2 down to the

other cells in your range. With the cursor sill in A2, click Copy on the Edit menu. Press CTRL+Spacebar to select the entire column. Then click

Paste Special on the Edit menu. In the Paste Special dialog, click Formats, and then click OK.



Example





This will copy the conditional formatting to all cells in the column.

Now&nbsp;— finally&nbsp;— you may see some cells with the colored fill

formatting, indicating that you have a duplicate.





It is informative to go to cell A3 and look at the conditional formula

(after you've copied it from A2). Select cell A3 and click

Conditional Formatting

on the Format menu. The formula in the Formula Is box has changed to count how many times the data in cell A3 appears in column A.



Example



You can have up to 65536 cells with conditional formatting, each

cell comparing the current cell to 65535 other cells. Technically, the

formula in the first step could have been =COUNTIF($A$2:$A$1751,A2)&gt;1.





Also, when copying the conditional format to the entire column, you could have selected just the cells

that contained data before using the Paste Special command.

Source