Advertisements

Category Archives: Tips & Tricks

#MacOsX : Terminal Cheat Sheet

If you are a *nix geek like me you can’t but love the command prompt.
One of the best tool to improve the plain old terminal is an utility called tmux. You can install through Homebrew.
Now, there are many commands to remember to play nicely with the terminal, and sometimes a little remind might be useful, that’s why cheat sheets exist.
Here is mine, enjoy.

Advertisements

#MacOsX : SSH SOCKS Proxy (SSH Tunnel Web Traffic)

After PRISM scandal you may feel the need to secure your connection and protect your privacy. Then it is a good idea to tunnel web traffic through a secure encrypted connection. This allows your traffic to traverse a local network without being visible to snoopers, even when visiting unencrypted web sites.

What you need:

  • a modern browser like Firefox, Chrome or Safari (they support SOCKS4 protocol)
  • ssh client (already installed in Mac Os X)
  • a shell account (with ssh access)

If you don’t have a shell account, you can find a free one HERE, or HERE, or HERE, or HERE.

To start the local proxy type:

ssh -D PORT user@host

where PORT is a local port between 1024 and 65535 (they do not require super user privileges), user is the username at the remote machine, and host is the identifier of the remote host.

That’s not enough, you need to configure the system to use the proxy. Go to System Preferences > Network > [select active interface] > Advanced... > Proxies and check SOCKS Proxy.
Then modify SOCKS Proxy Server info to use the PORT you chose before.

That’s it! From now on all connections on the active network interface will be tunneled through the proxy. 😎

NOTE1: you may want use proxy browser settings instead of system wide proxy settings, so you can tunnel only part of the traffic (e.g. the most sensitive one). This is easy, but the procedure slightly change between different browsers.

NOTE2: you may need to add the option -p HOST_PORT if the remote host doesn’t use the standard ssh port 22, e.g.:

ssh -D PORT user@host -p 666

#MacOsX : Show Hidden Files and Folders

In *NIX systems file and folders beginning with a dot (e.g., .name) are not visible in the Finder (also known as file browser). Since Mac Os X it’s a certified UNIX that’s also the case. If you use the terminal you can use the command:

ls -a

However, most people will use regular Finder. To enable view of hidden files in the Finder use this command:

defaults write com.apple.finder AppleShowAllFiles -bool TRUE

and then restart the finder with the following command:

killall Finder

To revert the changes use the same command, but replace TRUE with FALSE.

#AmazonStudent : Save Money

If you are a student, you can save some bucks if you join Amazon Student, the beautiful thing is that it is absolutely free!!!
That’s not all, you can earn 5$ every time someone join thank to you!
Why don’t you take the time to offer me a free beer clicking the following link and registering? Thx you 😎

#MacOsX : vimrc

If you are looking to configure Vim you find the default configuration file in:

/usr/share/vim/vimrc

Copy and rename it in your home directory:

cp /usr/share/vim/vimrc ~/.vimrc

However it is bare minimal so it is better if you personalize it a bit. One very simple example is the following:

" Configuration file for vim
set modelines=0 " CVE-2007-2438

" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
" Use Vim defaults instead of 100% vi compatibility
set nocompatible

" more powerful backspacing
set backspace=2

" Display line numbers on the left
set number

" Allow intelligent auto-indenting for each filetype
" and for "plugins that are filetype specific.
filetype indent plugin on

" Fallback when no filetype-specific indenting is enabled
set autoindent

" Enable syntax highlighting
syntax on

" Display the cursor position
set ruler

" Don't write backup file if vim is being called by "crontab -e"
au BufWrite /private/tmp/crontab.* set nowritebackup
" Don't write backup file if vim is being called by "chpass"
au BufWrite /private/etc/pw.* set nowritebackup

#UNIX : Send Messages to Logged Users

If you are used to play with multi users servers and you feel bored you can start a random chat with a logged user sending him a message (ok, actually it can be much more useful 😛 ) with the following command:

write username tty

where username and tty can be found using who command.
Then you can write the message and end it pressing Ctrl+D.

#MacOsX : Fix Mountain Lion Slow Shutdown

Ok, actually there are many good reasons to wait a bit of time before send a SIGKILL to processes (like giving them time to write things on disk or finish an upload on the iCloud), however the “slow” shutdown could be annoying, so try this:

sudo launchctl unload /System/Library/LaunchDaemons/com.apple.coreservices.appleevents.plist

sudo defaults write /System/Library/LaunchDaemons/com.apple.coreservices.appleevents ExitTimeOut -int 2

sudo launchctl load /System/Library/LaunchDaemons/com.apple.coreservices.appleevents.plist

This set the shutdown timeout to 2 sec instead of the default value (20).

#VMware Fusion: Script to Easily Install VMware Tools [OUTDATED]

If you run a linux guest VM, every time you update the kernel you need to reinstall VMwareTools for optimal performances.
After selecting Virtual Machine > Install VMware Tools you need to untar the archive and then run a script that ask you many question, etc.
This can be very tedious, so this is a little script that minimize typing:

#!/bin/bash
tar xzf /media/VMware\ Tools/VMwareTools-*.tar.gz -C /tmp
umount /media/VMware\ Tools
sudo /tmp/vmware-tools-distrib/vmware-install.pl -d
mkdir -pv ~/Desktop/VMwareShared
rm -v ~/Desktop/VMwareShared/*
if [ -d /mnt/hgfs ]
then
ln -sv /mnt/hgfs/* ~/Desktop/VMwareShared/
fi
vmware-user

VMware now recommends to use the open-vm-tools-desktop provided by the Linux distribution of your choice.

NOTE: -d option implies default answers to install script (most of the time they are ok)
NOTE2: the script create a directory on Desktop with all directories shared by the host system with the VM
NOTE3: this script has been tested only on Ubuntu 12.04 LTS
NOTE4: this script install native VMware Tools, if you want you can install open tools instead, but you can’t install both at the same time!

#MacOsX : Enable Quicklook Text Selection

Quicklook is a beautiful and powerful feature of Mac Os X (take a look here to know what is capable of) but it is somewhat weird that it doesn’t allow text selection.

To enable text selection in Quicklook:

defaults write com.apple.finder QLEnableTextSelection -boolean YES

killall Finder

 

#MacOsX : Show Remote Disks

There are Macs without disk drives. You can access CD/DVDs from another Mac over the network allowing remote disk.

This option allows you to always see remote drives within Finder:

defaults write com.apple.finder EnableODiskBrowsing -boolean YES

killall Finder

#Firefox : URL Keyword for Search Engines

Most browsers allow search to default search engine in address bar, but what if you want a different engine? You can switch on the right box, choose one and then start the search.

That’s suck!

So you can try this:

  • click the little arrow in the search engine box to open the drop down menu.
    Screen Shot 2013-02-24 at 6.30.14 PM
  • select Manage Search Engines…
    Screen Shot 2013-02-24 at 6.30.35 PM
  • select an engine and then click on Edit Keyword…
  • add the keyword you prefer and then click OK

From now on, if you want make a search with the engine in the URL bar, construct your research like:
keyword query
Examples:
wiki power law distribution
answer AAPL growth
twitter Barack Obama

NOTE: if your keyword doesn’t work and your query is answered by the default search engine, try to change it! I have noticed that if you use the name of the service (e.g., Wikipedia, Yhaoo) most of the time the keyword doesn’t work. 😦

#Firefox & #Chrome : Fast Email Composer

If you are a pro, you know, you use the keyboard to do most of the work, right?

Then why click to open the mail client or a new compose window when you can do it in less then 10 character:

type

mailto:

in the address bar of your browser and let’s the magic happen! 😎

#MacOsX : How Cut & Paste Works in Mac OS X

Yep, Mac world is only about Drag & Drop but if you feel nostalgic of PC’s world you can move files the old way, just do this:

  • selct file/files and hit

    Command + C

  • move to another location an hit

    Command + Option + V

#MacOsX : Reset NVRAM, PRAM and SMC

Sometimes after a software (system) or hardware upgrade even Macs can have some problems; if you have tried every solution without success you could try this.

Every Mac stores certain settings in a special memory area even if it is turned off. On Intel-based Macs, this is stored in memory known as NVRAM; on PowerPC-based Macs, this is stored in memory known as PRAM.

Resetting NVRAM and PRAM may solve lot of problems and could be required if you upgrade SSD or Mac firmware (more tips on SSDs here).

Another step to try is Resetting the System Management Controller (SMC). An SMC reset should only be attempted after all other standard troubleshooting has been performed.

 

 

#MacOsX : Disable Auto-Save and Versions in Mac OS X

Auto-Save and Versions are excellent features in Mac OS X, but some advanced users are annoyed by  them as they often don’t want to save intermediate versions of their work.
Moreover some apps write lots of data on disk (e.g. iMovie and iBooks Author) and this can shorten the life of SSD (look here for more tuning for SSDs).
If you know the name of the app plist you want to disable auto-save and Versions for, you can just plug the name into the defaults write command:

defaults write app-plist ApplePersistence -bool no

If you don’t know it then you can find it with the following command:

osascript -e 'id of application "NAME OF APP"'

Now if you enter the Versions window, auto-save list will be empty and there are no versions to restore to. You’ll probably want turn off File Locking too.

NOTE: some sandboxed apps require another command in addition:

defaults write app-plist AutosavingDelay -int 0

This is expecially true for TextEdit as it is the only Apple app that uses “old-style” autosaving and this causes issues with the sandbox in Lion/Mountain Lion.

NOTE2: It seems that the preference can be set globally but it may cause the login process to become very slow and possibly cause other unexpected behaviour:

defaults write -g ApplePersistence -bool no

#MacOsX : Turn Off File Locking

Mac OS X Lion has introduced automatic file locking for files that hasn’t been edited recently.

To Disable File Locking:

  • open System Preferences > Time Machine
  • click on Options
  • uncheck the box next to “Lock documents [2 weeks] after last edit” or modify the value as preferred
  • done 🙂

#IMEI : Secret Code

If you wanna find IMEI of your phone, just type:

*#06#

NOTE: it works for any phones of any era. 😉

#VMware Fusion : Fix Ubuntu Linux “Host SMBus controller not enabled!” [UPDATED]

Ubuntu guest instances in VMware sometimes come up with the boot error message:

piix4_smbus 0000:00:007.3: Host SMBus controller not enabled!

This error is being caused because VMware doesn’t actually provide that level interface for CPU access, but Ubuntu try to load the kernel module anyway.

How to fix it:

  • sudo nano /etc/modprobe.d/blacklist.conf
  • add the line:
    blacklist i2c-piix4
  • reboot

NOTE: for older versions use blacklist i2c_piix4 instead.
NOTE: it works both in VMWare Fusion 5 and 6, and Ubuntu LTS 12.04 and 14.04

#WP7 : LG Optimus 7 Unlock + Interop Unlock + Root Tools

If you want install XAP files without a developer account you can do it by modifying some registry keys:

  1. First go to MFG and follow the path 7.Engineer Menu > 6.Other Settings > Edit Registry
  2. Set the following fields:
    • Select ROOT_PATH: HKEY_LOCAL_MACHINE
    • Input SUB_PATH: Comm\Security\LVMod
    • Input KEY and Select data type:  DeveloperUnlockState   DWORD
    • Input data: 1
  3. Click Set button

To avoid Zune undo to default settings:

  1. Go to MFG and follow the path 7.Engineer Menu > 6.Other Settings > Edit Registry
  2. Set the following fields:
    • Select ROOT_PATH: HKEY_LOCAL_MACHINE
    • Input SUB_PATH: Software\Microsoft\DeviceReg
    • Input KEY and Select data type: PortalUrlProd   DWORD
    • Input data: leave this field empty
  3. Click Set button
  1. Go to MFG and follow the path 7.Engineer Menu > 6.Other Settings > Edit Registry
  2. Set the following fields:
    • Select ROOT_PATH: HKEY_LOCAL_MACHINE
    • Input SUB_PATH: Software\Microsoft\DeviceReg
    • Input KEY and Select data type: PortalUrlInt   DWORD
    • Input data: leave this field empty
  3. Click Set button

From now on your device is unlocked in developer mode, but you cannot install homebrew apps that modify registry keys. You need Interop Unlock:

  1. Go to MFG and follow the path 7.Engineer Menu > 6.Other Settings > Edit Registry
  2. Set the following fields:
    • Select ROOT_PATH: HKEY_LOCAL_MACHINE
    • Input SUB_PATH: Software\Microsoft\DeviceReg\Install
    • Input KEY and Select data type: MaxUnsignedApp   DWORD
    • Input data: 300
  3. Click Set button

NOTE1: if you want install very nasty apps then you need WP7 Root Tools.

NOTE2: Unlock & Interop Unlock works on WP7 Tango too.

NOTE3: to lock device again set DeveloperUnlockState to 0 (zero).

#MacOSX : Make your Mac a Wireless Network Bridge

Sometimes you need to extend wireless field; you can do it transforming your Mac as a Wireless Network Bridge.

Why  your Mac? Maybe a new shining Mac Book Pro? Well, let’s say your city has been hit by a big earthquake, so you had to leave your house, but your wireless network still works. Mobile Network won’t  work due to excessive overhead but you can still access internet to contact your friends and family. Sharing your internet connection give this chance also to many other people (this has been happened to me recently).

First you need a Switch or a Router or a Wireless Access Point and Ethernet cables.

Then:

  • Connect your mac to your wireless network
  • Connect Switch / Router / Wireless Access Point to Mac Ethernet port
  • Go to System Preferences -> Sharing
  • Check Internet Sharing
    • Share your connection from: Wi-Fi
    • To computers using: Ethernet and Bluetooth PAN
  • Let DHCP enabled

NOTE: this way you can connect to internet while you can maintain a secure distance from damaged buildings.

%d bloggers like this: