Tuesday, December 30, 2014

How to define a keyboard macro in Emacs

Link.


Here is how to define a keyboard macro: 
  • `C-x (’ or <f3>– start defining a keyboard macro
  • `C-x )’ or <f4>– stop defining the keyboard macro
And here is how to execute a keyboard macro you’ve defined: 
  • ‘C-x e’ or <f4> – execute the keyboard macro
Here’s how to execute the macro 37 times (you use ‘C-u’ to provide the 37): 
  • ‘C-u 37 C-x e’
Example:
You want to add the text “– foobar was here” at the end of each of the lines in a file. 
  1. Place the TextCursor at the beginning of the first line.
  2. `C-x (’ to start recording a keyboard macro.
  3. ‘C-e’ (or ‘M-x end-of-line’) to move the cursor to the end of the line.
  4. Type “-- foobar was here
  5. ‘C-a’ (or ‘M-x beginning-of-line’) to move the cursor to the beginning of the line.
  6. ‘C-n’ (or ‘M-x next-line’) to move the cursor to the beginning of the next line.
  7. `C-x )’ to stop recording the keyboard macro.
  8. ‘C-u 0 C-x e’ to execute the macro an infinite number of times until the end of the file is reached (See InfiniteArgument).
What’s important here is to stop defining the macro at a similar position to where you started it – so that you are in a position to execute it again, after it executes. This is a general rule that you will often follow when defining keyboard macros: try to make them executable N times in a row.
Actually, although it’s good to learn this general rule, there is a shortcut for just applying the last-defined keyboard macro to each of the lines of a region: 
  • ‘M-x apply-macro-to-region-lines’
Or to be more precise (from the documentation of the command):
  For each complete line between point and mark, move to the beginning
  of the line, and run the last keyboard macro.
You can name the last-defined keyboard macro, so that you can then execute it by name: 
  • ‘M-x name-last-kbd-macro’ – Name the last-defined keyboard macro.
Why do that? One reason is that it lets you have more than one macro defined at the same time. Once you have named this macro, say, ‘my-macro’, you can define another one that does something else. Then, you can execute the second macro using ‘C-x e’ and execute ‘my-macro’ as if it were a standard Emacs command: ‘M-x my-macro’. If you also name the second macro, then you can define a third one…
Keyboard macros are only defined for your current Emacs session. If you want to be able to reuse a macro in a future session, then save it in your initialization file (.emacs or _emacs). Open the file, then insert the macro definition using this command: 
  • ‘M-x insert-kbd-macro’ – Insert a named keyboard macro into your initialization file.
Now you can use ‘M-x’ to execute the named keyboard macro in future sessions – just as if it were a standard Emacs command of the same name. If you want to bind it to a key, you can add code like the following to your initialization file:
    (global-set-key (kbd "C-c a") 'my-macro)
This binds the key sequence ‘C-c a’ to the macro ‘my-macro’.
If you want to edit the macro in future sessions, you need to let the kmacro library know that the symbol is indeed a macro by putting the kmacro property on the symbol.
  (put 'my-macro 'kmacro t)
Read more ...

Wednesday, December 10, 2014

Re-install DirectX

Link.


  1. Run Regedit by pressing Win key+R to get the Run Box and type Regedit, then press enter.
  2. Locate the following registry key: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\DirectX (You should then see a value called “Version” with a data value of 4.09.00.0904).
  3. Simply double click on Version and change the number from 4.09.00.0904 to 4.08.00.0904. Then close the registry editor.
  4. Download and run the DirectX installer, and it should re-install.
Read more ...

Wednesday, November 19, 2014

Getting MacPorts to Work Behind a Firewall

Link.


MacPorts is an extremely useful command line utility for managing open-source software (ports) on your Mac. It makes it a breeze to to find, download, compile and install open-source software on your machine, as well as upgrade to the latest versions without wasting a lot of time.

Unfortunately those of us behind corporate firewalls are usually prevented from using the tool due to network security restrictions of the rsyncd protocol.

I hope this post helps you solve some of the most common issues encountered when running MacPorts selfupdate or sync commands behind a corporate firewall.

What you will need
  • A recent copy of MacPorts installed. If you have not done this yet, please head over to MacPorts to get the latest version 
  • Your corporate proxy server name, port and proxy user credentials if necessary. 
  • The ability to (sudo) temporarily increase your account privileges to those of an administrator on your Mac. 
Step 1: Switch MacPorts to use HTTP

MacPorts is configured to synchronize its list of ports via rsync. We will change it so it uses HTTP instead.

Open a terminal window and edit the MacPorts source configuration file. Enter the superuser password when prompted.
sudo vim /opt/local/etc/macports/sources.conf
Comment out the line at the bottom of the file and add a new one that uses the HTTP address. When you are done, it should look something like this:
#rsync://rsync.macports.org/release/ports/ [default]
http://distfiles.macports.org/ports.tar.gz [default]
Save the file and exit the editor.

Step 2: Setup your Proxies

Edit your profile script, this could be in the form ~/.profile, ~/.bash_profile, etc.
vim ~/.profile

Add the following to the bottom of the file:
################################### CORP PROXY ###################################
PROXY_SERVER=corporate-proxy-server-here
PROXY_PORT=8888
PROXY_USERNAME=proxy_account
PROXY_PASSWORD=proxy_password
PROXY=$PROXY_USERNAME:$PROXY_PASSWORD@$PROXY_SERVER:$PROXY_PORT
# HTTP and HTTPS
export http_proxy=http://$PROXY
export HTTP_PROXY=http://$PROXY
export https_proxy=http://$PROXY
export HTTPS_PROXY=http://$PROXY
# RSYNC
export rsync_proxy=$PROXY
export RSYNC_PROXY=$PROXY
##################################################################################

Save the file and exit the editor.

Step 3: Edit the sudoers file

This is required to forward your proxies to the superuser account every time you run sudo port commands.
sudo visudo

Append the following to the end of the list of Defaults:
Defaults env_keep += "http_proxy rsync_proxy HTTP_PROXY RSYNC_PROXY"

Save the file and exit the editor.

Restart the Shell

Exit the terminal shell and start a new session to load the new settings.

Test your new proxy environment variables are now available:
env | grep http
You should see something like this:
$ env | grep http
http_proxy=http://proxy_account:proxy_password@corporate-proxy-server-here:8888
HTTP_PROXY=http://proxy_account:proxy_password@corporate-proxy-server-here:8888

Update your Ports

You should now be able to load the latest ports using the http proxy. Test this by typing the following command. Note that the -d switch invokes the command in debug mode. We do this so you can see what is happening behind the scenes.
sudo port -d sync

You should see a long list of ports being downloaded.
Read more ...

Tuesday, October 28, 2014

pdftk in Mac OS X with tips

Download pdftk for Mac.

tips:

1. Split multi-page PDFs into single page PDFs
$ pdftk my_multi_page.pdf burst
$ pdftk my_multi_page.pdf burst output my_directory/page_%02d.pdf

2. Pull some pages out of a PDF but keep the rest
$ pdftk my.pdf cat 1-5 13-21 24-end output my_edited.pdf

3. Concatenate (that’s join!) multiple pdfs into one big pdf
$ pdftk part0.pdf part1.pdf cat output the_whole_book.pdf

4. Get all of the images and other attachments out of a PDF and put them in a folder
$ pdftk my.pdf unpack_files output ~/attachments_from_my_pdf/

5. Print stats and metadata about a PDF
$ pdftk my.pdf dump_data

6. Add a background watermark (or a foreground overlay) to a pdf

- For a background
$ pdftk my.pdf background bg.pdf output my_watermarked.pdf

- For an overlay
$ pdftk my.pdf stamp overlay.pdf output my_overlayed.pdf
Read more ...

Wednesday, October 22, 2014

Copy file or folder path to the clipboard in Mac OS X

Link.


  1. Launch Automator
  2. Double-click the Service icon
  3. Toward the top of the right column, you’ll see this line of text: “Service receives selected _____ in _____”. Choose “Files or Folders” from the first menu and “Finder” from the second.
  4. Click on Utilities in the Actions library on the left side. Double-click “Copy to Clipboard” in the middle column.
  5. Go to File > Save in the menu bar and name your service Copy File Path.
  6. Launch System Preferences and go to the Keyboard pane. Click on the Keyboard Shortcuts tab.
  7. Select “Application Shortcuts” from the list on the left. Next, click on the + button at the bottom of the list.
  8. A small window will come up with a few options that need to be set. Select “Finder” from the Application menu, type Copy File Path as the Menu Title, and create your own Keyboard Shortcut. If you don’t know what to put here, you can just press Shift+Command+C on your keyboard. Click Add and we’re done!


If you’re not keen on keyboard shortcuts, the service you created is also accessible when you right-click on an item in Finder and select Services > Copy File Path from the contextual menu. The actual file we created for this service is located in: ~/Library/Services in case you ever want to delete it or copy it to put on another Mac.
Read more ...

Tuesday, October 14, 2014

Terminal command to check used memory in OS X

top -l 1 | head -n 10 | grep PhysMem
Read more ...

Tuesday, September 23, 2014

How to disable Adobe Reader in Safari?

Link.


Go to the "Help" menu in Safari and select "Installed Plug-ins". This will open a new tab displaying information about all of the currently installed plug-ins. Find the entry for Adobe Acrobat. Below it will be a line that reads something like:
Adobe® Acrobat® Plug-in for Web Browsers — from file “AdobePDFViewer.plugin”.
Note the name of the file from that line.
On your hard drive you will find a Library folder. In that folder will be another folder called Internet Plug-Ins. Inside that folder you should find the file that was shown in the "Installed Plug-ins" tab. The full path should be /Library/Internet Plug-Ins/AdobePDFViewer.plugin. That file needs to be deleted. Dragging it to the trash will do the trick.
If you are not sure you want to delete the file, you can move it to another location. For instance, you could create a new folder named "Disabled Plug-Ins" in the "Installed Plug-Ins" folder, and move the file to the new folder.
Then quit & relaunch Safari.
Adobe acknowledges this is a "known issue" and recommends this procedure.
Read more ...

Monday, September 15, 2014

Friday, August 29, 2014

Split and merge pdf’s with pdftk in linux

Link.


Pdf Tolkit (pdftk) is a tool to split and merge the pdf’s.

First you need to install the pdftk with following command.
$ sudo apt-get install pdftk

An example to merge pdf’s
$ pdftk input1.pdf input2.pdf cat output merge-output.pdf

Above example is to merge input1.pdf and input2.pdf and create new output file with name merge-output.pdf

An example to split pdf(split from page 10 to 20)
$ pdftk A=input1.pdf cat A10-20 outpout split-output.pdf

Above example is to get only page number 10 to 20 from input1.pdf to split-output.pdf
Read more ...

Monday, August 18, 2014

Converting mp4 to mp3 in Linux

Link.


To convert Upd_Sanity.mp4 to Upd_Sanity.mp3

$ sudo apt-get install ffmpeg && sudo apt-get install libavcodec-extra-53

$ ffmpeg -i Upd_Sanity.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 Upd_Sanity.mp3
OR (as ffmpeg is deprecated)
$ avconv -i Upd_Sanity.mp4 -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 Upd_Sanity.mp3

Description

   -i        input file name
   -vn       disable video recording
   -acodec   force audio codec to libmp3lame
   -ac       set the number of audio channels
   -ar       set the audio sampling frequency

If you need to use it frequently,

STEP 1 : Create a bash function that performs conversion
## utilities.sh
convertMP4toMP3(){
echo -n "Enter source mp4 file : "
read sourceFile

echo -n "Enter destination mp3 file : "
read destFile

avconv -i $sourceFile -vn -acodec libmp3lame -ac 2 -ab 160k -ar 48000 $destFile
}
STEP 2 : source that bash file
 $ source utilities.sh
STEP 3 : start conversion calling above function convertMP4toMP3
 $ convertMP4toMP3
 Enter source mp4 file : Upd_Sanity.mp4
 Enter destination mp3 file : UPd_sanity.mp3
Read more ...

How to be a Google power user


Read more ...

Thursday, July 31, 2014

Install matplotlib for python3

you have to install python3-pip bu using apt-get (e.g. in debian)

then run:

pip install matplotlib

If got the error

(Currently using distribute 0.6.24dev-r0 (/usr/lib/python3.2/dist-packages))
    Complete output from command python setup.py egg_info:
    The required version of distribute (>=0.6.28) is not available,

and can't be installed while this script is running. Please

install a more recent version first, using

'easy_install -U distribute'.

Try:

sudo apt-get install python3-setuptools
easy_install3 -U distribute

If still does not work
Try:

export PYTHONHOME=/usr/local/lib/python3.2/

Read more ...