Friday, November 15, 2013

Bootstrap CSS

Bootstrap provides a Sleek, intuitive, and powerful mobile first front-end framework for faster and easier web development.

Check it out at http://getbootstrap.com/

Sunday, November 10, 2013

Good explanation of python decorators

By Simeon Franklin

http://simeonfranklin.com/blog/2012/jul/1/python-decorators-in-12-steps/

Thursday, November 7, 2013

Installing python-ldap in Ubuntu

$ sudo apt-get install python-dev libldap2-dev libsasl2-dev libssl-dev 
$ pip install python-ldap

Wednesday, November 6, 2013

Where are books stored in iBooks in Mavericks

At the following path.

~/Library/Containers/com.apple.BKAgentService/Data/Documents/iBooks/Books

Checking the PYTHONPATH interactively

You can see the value of your Python path using the Python interactive interpreter and tying this:

>>> import sys 
>>> print sys.path

Thursday, October 3, 2013

Computer powers on itself after shutdown.

I used to run into a problem in which my newly built computer would power on itself after being shutdown. Most of the online posts talked about Windows Scheduled Tasks. However, these come into play only when the computer is in 'Sleep' mode not in shutdown.

Finally, I found the solution. The problem was a default setting on Asus motherboard (Z87 Pro) which kept the Wireless adaptor powered on even though the computer was shutdown. This would cause the box to boot up anywhere between 2 and 20 mins after shutdown.

The solution was to enable "ErP Ready" under the APM Configuration in the BIOS. When the machine shuts down with the Wifi adapter enabled, the Wifi LED will go off (instead of staying on like before). The ErP mode setting will disable the Wifi wakeup at the BIOS level. The setting description says, "This item allows user to switch off some power at S5 to get the system ready for ErP requirement."

S5 state is the shutdown/OFF state. So it makes sense when it says it switches off power at the S5 state; it switches off power to the Wifi module, essentially disabling it and not allowing it to turn the machine on.

Tuesday, September 17, 2013

Formatting JSON files

Oftentimes you have JSON files which need to be formatted and checked for validity. You can use the following ways of going about it.

1. Using Python
cat file.json | python -mjson.tool > newfile.json

2. Uing jsonlint
Install jsonlint using 'sudo apt-get install  python-demjson'

Then use the command 

jsonlint -fv file.json > newfile.json 

Tuesday, April 16, 2013

Best uninstaller for mac

Uninstalling mac apps is easy. Just drag them to the Thrash. But you are often left with files in the ~/Library folder created by the app. To completely get rid of these files, its always a good idea to use an  uninstaller.

The best uninstaller for Mac is free and is called AppCleaner. Download it from http://www.freemacsoft.net/appcleaner/

Sunday, March 31, 2013

Repairing a time chaine volume

http://www.garth.org/archives/2011,08,27,169,fix-time-machine-sparsebundle-nas-based-backup-errors.html

Tuesday, January 29, 2013

How to manually uninstall the Altiris Agent for Mac

See details at http://www.symantec.com/business/support/index?page=content&id=HOWTO59038

Tuesday, September 11, 2012

Installing a SSL on a synology DS

I assume you are running OSX or Linux and have openssl installed.

Follow the steps below to create and install the SSL

1. Open a terminal and type the following commands. The first command will ask for a paraphrase. The same paraphrase will be required by the other commands.

  • openssl genrsa -des3 -out my.key 2048
  • openssl rsa -in my.key -out final.key
  • openssl req -nodes -new -key my.key -out request.csr
  • openssl x509 -req -in request.csr -signkey my.key -out certificate.crt -days 3650

2. The above commands will create the key and the certificate. They will be stored in my.key and certificate.crt respectively.

3. Login to the DSM GUI, go to the control panel, DSM Settings, HTTP Service and click the button marked Import Certificate.

4. For the private key select my.key and for the certificate select certificate.crt. Reboot the NAS.

Syno Community

Good source of synology packages

http://www.synocommunity.com/repository

Disable notifications for a service in nagios

Assuming you are running nagios on a UBuntu box and want to disable notification emails for a particular service, you would follow the steps below.

1. Locate the service configuration file. In my case it happened to be located at /etc/nagios3/conf.d/localhost_nagios2.cfg

2. Edit the file and find the service definition for the service you are interested in. The service definitions all start with 'define service'

3. Add the following configuration inside the service definition

notifications_enabled 0

4. Restart nagios - /etc/init.d/nagios3 restart

Notification would now be disabled for this service.

Sunday, September 9, 2012

Postfix configuration to use SMTP relay, re-write from email address and name

What is postfix?

Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail. It is intended as a fast, easier-to-administer, and secure alternative to the widely used Sendmail MTA.

The postfix configuration file usually resides at /etc/postfix/main.cf and uses the following format for configuration parameters.

parameter = value

Aliases

You should set up a postmaster alias in the aliases table that directs mail to a human person. The postmaster address is required to exist, so that people can report mail delivery problems. While you're updating the aliases table, be sure to direct mail for the super-user to a human person too.

The aliases file is /etc/aliases. A sample configuration is shown below. In this configuration, the postmaster and root emails are delivered to the user john.

postmaster: john
root: john

Execute the command "newaliases" after changing the aliases file. Instead of /etc/aliases, your alias file may be located elsewhere. Use the command "postconf alias_maps" to find out.

Using an external SMTP server as a relay

By default, postfix directly delivers emails to the final email server. For example, if you send an email to user@example.com, postfix will try to lookup the MX record for example.com and directly connect to its mail server to deliver the email.

This can be a problem if your host cannot reach other email servers on the internet or your organization requires all emails to be sent via a SMTP gateway.

The parameter relayhost in the postfix configuration file is used for this purpose. Below is a sample configuration.

relayhost  = smtp.example.com

Restart postfix using '/etc/init.d/postfix restart' for changes to take effect.

Re-writing the from-email address

If you want to re-write the email address from which emails are sent out from, postfix offers generic mapping for smtp. Create a file called '/etc/postfix/generic' and add in a line similar to the following one to rewrite the from address.

root@example.com john@example.com

Modify the main configuration file to add the 'smtp_generic_maps' parameter as follows,

smtp_generic_maps = hash:/etc/postfix/generic

Then build the map generic db file using the command 'postmap /etc/postfix/generic'

Restart postfix using '/etc/init.d/postfix restart' for changes to take effect.

For any errors, check the log files located at /var/log/mail*

Re-writing the from name when sending an email

Although, the from email address is re-written using the process above, the name of the person in the email sent by postfix will still be shown as the local username. For e.g, if you re-write the email address from root@example.com to john@example.com and then you look at the raw headers in the sent email, the following may be seen.

From: root

To fix this, you need to use smtp_header_checks. This parameter allows you to have a regex replace the name used in the email header with the name of your choice. Follow the steps below to get this fixed.

1. Create a file called '/etc/postfix/smtp_header_checks'.
2. Add a regex in the file with the format and save the file.
          /^From:root/ REPLACE From: John
3. Add the following parameter to your mail configuration file.
         smtp_header_checks = regexp:/etc/postfix/smtp_header_checks
4. Check and compile your regex with a sample message using the command.
        postmap -q - regexp:/etc/postfix/smtp_header_checks < /tmp/raw-header-file
5. Restart postfix for changes to take effect.

More info

For more details and updated information, visit the postfix website at http://www.postfix.org/

Thursday, August 30, 2012

Change update frequency of software updates in OSX

sudo defaults write /Library/Preferences/com.apple.SoftwareUpdate ScheduleFrequency

Friday, August 24, 2012

Advanced Linux File Permissions


Advanced File Permissions in Linux


Here we will discuss about the 3 special attributes other than the common read/write/execute.
Example:
drwxrwxrwt - Sticky Bits - chmod 1777
drwsrwxrwx - SUID set - chmod 4777
drwxrwsrwx - SGID set - chmod 2777


Sticky bit


Sticky bits are mainly set on directories. If the sticky bit is set for a directory, only the owner of that directory or the owner of a file can delete or rename a file within that directory.

Example:
Consider you have a directory " test ". chmod it to " 777 ". This gives permissions for all the users to read, write and execute.

# chmod +t test

# ls -al
drwxrwxrwt 2 a1 a1 4096 Jun 13 2008 .
-rw-rw-r-- 1 a1 a1 0 Jun 11 17:30 1.txt
-rw-rw-r-- 1 b2 b2 0 Jun 11 22:52 2.txt

From the above example a1 is the owner of the test directory. 
a1 can delete or rename the files 1.txt and 2.txt.
b2 can delete or rename the file 2.txt only.

SUID - [ Set User ID ]


SUID bit is set for files ( mainly for scripts ). The SUID permission makes a script to run as the user who is the owner of the script, rather than the user who started it.

Example:
If a1 is the owner of the script and b2 tries to run the same script, the script runs with the ownership of a1.
If the root user wants to give permissions for some scripts to run by different users, he can set the SUID bit for that particular script.
So if any user on the system starts that script, it will run under the root ownership.
Note:
root user much be very careful with this.

SGID - [ Set Group ID ]


If a file is SGID, it will run with the privileges of the files group owner, instead of the privileges of the person running the program. This permission set also can make a similar impact. Here the script runs under the groups ownership. You can also set SGID for directories.

Consider you have given 2777 permission for a directory. Any files created by any users under this directory will come as follows.
Example:
-rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
In the above example you can see that the owner of the file 1.txt is b2 and the group owner is a1.
So both b2 and a1 will have access to the file 1.txt.
Now lets make this more interesting and complicated.

Create a directory "test". Chmod it to 2777. Add sticky bit to it.

Example:
mkdir test
# chmod 2777 test
# chmod +t test
# ls -al test
drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 test

From the above permission set you can understand that SGID and sticky bit is set for the folder "test".
Now any user can create files under the test directory.
Example:
drwxrwsrwt 2 a1 a1 4096 Jun 13 2008 .
-rw-rw-r-- 1 b2 a1 0 Jun 11 17:30 1.txt
-rw-rw-r-- 1 c3 a1 0 Jun 11 17:30 2.txt
-rw-rw-r-- 1 d4 a1 0 Jun 11 17:30 3.txt
So all the a1 user has access to all the files under the test directory. He can edit, rename or remove the file.
b2 user has access to 1.txt only, c3 has access to 2.txt only...
If sticky bit was not set for the test directory, any user can delete any files from the test directory, since the test directory has 777 permissions.
But now it not possible.
Example:
If d4 tries to remove 1.txt
rm -f 1.txt
rm: cannot remove `1.txt': Operation not permitted

Tuesday, August 7, 2012

Mac Software I use

Here's a list of software I use on the Mac. I'll try to keep the list updated as I start/stop using applications.

Freeware

  • KeepassX
  • Transmission
  • Google Chrome
  • Google Drive
  • Google Notifier
  • Google Earth
  • Picasa
  • Evernote
  • TextWrangler
  • Transmission
  • Cyberduck
  • Adium
  • Cisco Jabber
  • AppCleaner
  • Better Touch Tool
  • CloudApp
  • Dropbox
  • Eclipse
  • Mint Quickview
  • Plex
  • Skype
  • smcFanControl
  • Spotify
  • The Unarchiver
  • InsomniaX
  • Twitter
  • UnrarX
  • VLC
  • XBMC

Paid Software

  • Microsoft Office
  • Omnifocus
  • Carbon Copy Cloner
  • iGetter
  • Vmware Fusion

Apple Apps

  • iPhoto
  • iMovie
  • Safari
  • Mail
  • iCal
  • iTunes
  • Messages
  • Reminders
  • Notes
  • Terminal
  • Facetime

Wednesday, June 27, 2012

Changing default quit key for apps on macos

The following command will change the default key to Command+Shift+Q for Mail and Safari.

defaults write NSGlobalDomain NSUserKeyEquivalents '{"Quit Safari" = "@$Q"; "Quit Mail" = "@$Q";}'


The odd characters before the 'Q' in the previous command, specify the modifiers:
  • @ = Command 
  • $ = Shift 
  • ~ = Option 
  • ^ = Control

Tuesday, June 26, 2012

Copy only the email address in Apple Mail

Use the following command to only copy the email address from Apple Mail.

defaults write com.apple.mail AddressesIncludeNameOnPasteboard -boolean No

To undo this action, use

defaults write com.apple.mail AddressesIncludeNameOnPasteboard -boolean Yes

Saturday, June 23, 2012

Cisco Jabber Saving Chat History

1. Create a folder in Documents called 'CiscoJabber-ChatTranscripts'
2. Quite the Jabber Client
3. Run the following commands
cp ~/Library/Preferences/com.cisco.Jabber.plist ~/Library/Preferences/com.cisco.Jabber.plist.backup
defaults read com.cisco.Jabber ARXUserDefaultsChatTranscriptsDirectory
defaults write com.cisco.Jabber ARXUserDefaultsChatTranscriptsDirectory "~/Documents/CiscoJabber-ChatTranscripts"
defaults read com.cisco.Jabber ARXUserDefaultsDeveloperChatArchivePolicyKey
defaults write com.cisco.Jabber ARXUserDefaultsDeveloperChatArchivePolicyKey -int 1
defaults read com.cisco.Jabber ARXUserDefaultsShouldSaveChatTranscriptsKey
defaults write com.cisco.Jabber ARXUserDefaultsShouldSaveChatTranscriptsKey -bool true
defaults read com.cisco.Jabber ARXUserDefaultsShowCommHistoryInSeparateTabsKey
defaults write com.cisco.Jabber ARXUserDefaultsShowCommHistoryInSeparateTabsKey -bool true

4. Start the Jabber Client