The Lumber Room

"Consign them to dust and damp by way of preserving them"

Posts Tagged ‘commandline

Flashing the screen on Mac OS X

leave a comment »

Here’s one way. There’s a C program to adjust the screen’s brightness written by Nicholas Riley, also available from this blog post by Matt (Danger) West. Get it. The rest is obvious. For instance, here’s a Python script, which should have probably been written in Perl:

import os, re, time

s = os.popen('./brightness -l').read()
ob = re.findall('brightness (\d.\d+)', s)[0]

w = 0.2
for i in range(10):
    os.system('./brightness 0'); time.sleep(w)
    os.system('./brightness 1'); time.sleep(w)
    if(i==4): os.system("say beep")

os.system('./brightness ' + ob)

Tune parameters to avoid epileptic seizures.

Read the rest of this entry »

Written by S

Mon, 2009-08-17 at 16:07:05 +05:30

Posted in compknow

Tagged with , , , ,

Restarting Airport from the command line

leave a comment »

Something is wrong with the network in my dorm; DHCP negotiation sometimes fails (or takes a long time). So the usual thing to do is to turn Airport off and on, and hope it works this time.

To do this from the commandline, here’s a simple trick I found:
Go to System PreferencesNetwork, then in Location choose a New Location and create one called “Airport-Off” (or anything you like). In the Show menu choose Network Port Configurations and turn off Airport.

After this, you can do scselect Airport-Off to turn it off, and scselect 0 (for Automatic — or choose whatever other location you want) to turn it on.

Edit [2011-10-03]: You can also do this:

sudo networksetup -setairportpower "Airport" off
sudo networksetup -setairportpower "Airport" on

Written by S

Mon, 2007-10-08 at 01:51:44 +05:30

Posted in compknow

Tagged with , , , , , ,

Using Gmail with mutt, the minimal way (IMAP update)

with 64 comments

As Gmail has IMAP access, it is fairly trivial to get it working with mutt. First, if you’re on Ubuntu/Debian, run sudo apt-get install openssl mutt to get mutt if you don’t already have it. Then, just put the following lines into your ~/.muttrc:

set imap_user = "username@gmail.com"
set imap_pass = "password"

set smtp_url = "smtp://username@smtp.gmail.com:587/"
set smtp_pass = "password"
set from = "username@gmail.com"
set realname = "Your Real Name"

set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set postponed="+[Gmail]/Drafts"

set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates

set move = no

Make sure your ~/.muttrc isn’t world-readable; it contains your password. (Alternatively, you can leave them out and mutt will prompt you for the password each time.) Also, if you copy-paste from the above, make sure that you have only “normal” quotes, not “smart quotes” which WordPress might have inserted here into this post.

[Other things I have:

set sort = 'threads'
set sort_aux = 'last-date-received'
set imap_check_subscribed

ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc

I did not include above to justify the "minimal" :)]

Things work perfectly as you would expect them.
One thing to note is that the full headers will still contain the hostname of the computer you send messages from. I have not figured a way of hiding this, and perhaps it shouldn’t be possible.

The End

If for some reason you want to use POP, read on. And tell me why you would want to use POP. The rest of the post is an old version, which i had written before Gmail supported IMAP.

Old Stuff
There is a guide here, which is the first Google result on searching for the keywords Gmail, mutt and Ubuntu in any order, but I would advise against it: it does too much unnecessary stuff using too many unnecessary programs (okay if you don’t care), and involves putting your username and password in a world-readable file (not okay).

There is a guide here, but that site seems down, and so I guess it’s likely to be down again (a DynDNS domain; could be someone’s house), so putting a (fuller) guide here:

First, run sudo apt-get install openssl mutt

Next, in /etc/ssmtp/ssmtp.conf, put
mailhub=smtp.gmail.com:465
UseTLS=YES

Everything else seems to be optional.

Next, create a shell script with the contents
#!/bin/sh
/usr/sbin/ssmtp -au "gmail-address" -ap "password" $@
and put it somewhere in your path (~/bin/gmailout, say) and make it executable (chmod u+x ~/bin/gmailout, I mean) and make sure only you can read it! (chmod og-r ~/bin/gmailout).

Now in ~/.muttrc, put
set pop_host="pops://username:password@pop.gmail.com:995"
set pop_last
unset pop_delete #Just makes mutt not ask, GMail uses config option
set sendmail="~/bin/gmailout"
set write_bcc=no #Important; sSMTP makes bcc non-blind otherwise

and you’re set (remember to make this world-unreadable too: chmod og-rw ~/.muttrc)

You can start mutt, and hit “G” (uppercase G) whenever you want to fetch mail. Can also put exec fetch-mail in ~/.muttrc to have it happen whenever you start mutt, but I find that irritating.

Problems with POP: Not that everything is perfect. I can’t have other mail-transport-agents like sendmail or postfix installed alongside ssmtp. I can’t figure out how to get my crontab reports sent to root, but they do go into ~/dead.letter :D
Also, with mutt I had the habit of adding a my_hdr bcc: my-email-address so that the mail I send is threaded along with the mail I receive (yaay, like Gmail), but somehow there seems to be simply no way of getting Gmail to give me, through POP, those messages I send using an external client. It’s a quirk [bug!] in the way Gmail implements POP. This I’ve fixed by setting mutt’s fcc to /var/mail/my-username, my mail folder. (Of course, if I were in the habit of moving mail to my mbox, I could fcc to mbox too.)
Apart from that, it works fine!

Written by S

Tue, 2007-07-31 at 02:16:03 +05:30

Collaborative work with LaTeX

with 5 comments

All things considered (after trawling through more than a dozen pages of Google results, that is), I’ve arrived at the conclusion that the best way [as of 2006-10-11] to work on LaTeX documents collaboratively is to use a CVS or Subversion repository, and let everyone commit changes to it.

There seems to be a MediaWiki plugin for collaborative LaTeX, but it needs some attention to security issues…

Someone asked around, and put up an extremely useful summary.

There’s a very short CVS tutorial here.

Update[2007-11-25]: For some reason, the PracTeX journal had three articles about LaTeX+Subversion in 2007-08: LaTeX Document Management with Subversion, Version Control of LaTeX Documents with svn-multi, and Subversion and TextMate: Making collaboration easier for LaTeX users. It’s a good idea to pick the simplest solution that works for you. I haven’t read those articles, but we did use LaTeX in a (somewhat) collaborative way (we weren’t sharing the work much, so it’s not clear the others saw any good in it) for two of our courses, here and here. The websvn interface is a bit crufty; we were using the commandline interface.

The work cycle was as below: (in case you’ve never used version control and don’t know what it is, this will show you that it’s simple after all!)

[Don't use these URLs; they won't work for you, of course.]

How to use the algcomp-notes subversion repository.

==Initial setup (only once)==
    svn checkout http://svn.cmi.ac.in/algcomp-notes/ working-dir	

==Work cycle (each time)==
    svn update     # to get the latest version from the repository
Now work with your files as you usually would. After you're done, do:
    svn diff          #optional: to see what you have changed
    svn commit -m "some message, for the history"

Extra files you create in the directory are ignored. To add a new file, use:
    svn add [filename]

That’s all there is to it (apart from setting up — or getting someone to set up — the repository and access to it in the first place. Ask your sysadmin :-)

Update[2008-02-05]: Gobby is a collaborative text editor, and can be used with LaTeX, as this screenshot shows. Someone even wants to use Darcs’s Theory of Patches, and give it proper Undo etc… and at that point we are back to the version control solution, but with a good version-control system and a simple GUI for doing things.

Update[2008-03-25]: Here is a post by an actual mathematician using version control.

I do think it would be a great idea for someone to provide a version-control service for collaborative LaTeX documents over the internet. They could go further and make it easy to edit LaTeX in a browser, and we would have something along the lines of Google Docs.

Update [2009-10-03]: Some other things worth a mention: online LaTeX editors like MonkeyTex (but no one really likes editing in anything other than their familiar environment), a page at Wikibooks based on one of the PracTeX articles mentioned above, and, coming Real Soon Now, support for LaTeX in Google Wave.(link.)

Update [2010-05-11]: Some more things to mention: ScribTeX (see comments below), and LaTeX-lab, a plugin for Google Docs.

Update [2010-06-23]: Also see this Mathoverflow thread called Tools for Collaborative Paper Writing.

Written by S

Wed, 2006-10-11 at 20:50:53 +05:30

ssh-keygen as another user

with 4 comments

To set up an ssh-key usually, type
ssh-keygen -t rsa, hit [Enter] a few times, type
cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys, and add entries from other places where you might have created a key, to the same authorized_keys.

To set it up so you can log in as another user (called, say, user2)
ssh-keygen -t rsa
Enter a different file to save (id_for_user2, say), and blank passphrase.
Now add the contents of the file id_for_user2.pub to user2‘s ~/.ssh/authorized_keys file.

Oh, and when you want to login as that user, you will have to specify that you want to use that file, like
ssh -i ~/.ssh/id_for_user2 user2@hostname. For long commands like this, it’s best to make an alias (put alias sshasuser2='ssh -i ~/.ssh/id_for_user2 user2@localhost' in your ~/.bashrc if all you want is a password-less replacement for su - user2). You can also give the id_for_user2 file to others, and they can also login as user2 without a password simply by typing the command above.

Got it from this linux.debian.user newsgroup post.

Written by S

Thu, 2005-11-17 at 13:01:00 +05:30

Follow

Get every new post delivered to your Inbox.

Join 71 other followers