piyo's computer tips
2006/04/05
256 colors on your terminal emacs and screen
color, terminal, command-line, Emacs, Screen, Windows

I got tired of ANSI colors on my Putty sessions to my Colinux Linux instances. I started researching if I could get more colors and the answer now is yes, 256 colors is possible. How do I get Emacs to take advantage of this and be just darn more colorful?

Screen settings:

On Debian sarge v3.1, you need to recompile screen so that it has --enable-256colors in the ./configure. This blog has the details on how to do it. Gentoo has this automatically.

Then add the following to your ${HOME}/.screenrc file, which was taken from "The 256 color mode of xterm" page. Really useful.
# erase background with current bg color
defbce "on"
# do not use 'screen-bce'
term xterm-256color
Putty settings:

For putty 0.58 on Windows, add the terminal name "xterm-256color" in the Data panel before starting a session. This Data panel is not customizable after you start a session.

Emacs settings:

GNU Emacs 21.x doesn't support this xterm-256color directly, but you can define the colors yourself. You could try this script where the colors are defined by number, or you can try my script which defines the colors to the nearest color in the rgb.txt.

(defmacro tty-color-define-1 (n c r g b)
`(tty-color-define ,n ,c (list (* 257 ,r) (* 257 ,g) (* 257 ,b))))
(defun tty-color-closest-to-rgb-txt ()
(tty-color-define-1 "grey22" 16 55 55 55)
(tty-color-define-1 "DarkSlateGrey" 17 55 55 95)
(tty-color-define-1 "SlateBlue4" 18 55 55 135)
(tty-color-define-1 "SlateBlue4" 19 55 55 175)
(tty-color-define-1 "RoyalBlue3" 20 55 55 215)
(tty-color-define-1 "RoyalBlue2" 21 55 55 255)
(tty-color-define-1 "DarkSlateGrey" 22 55 95 55)
(tty-color-define-1 "DarkSlateGrey" 23 55 95 95)
(tty-color-define-1 "SteelBlue4" 24 55 95 135)
(tty-color-define-1 "RoyalBlue3" 25 55 95 175)
(tty-color-define-1 "RoyalBlue3" 26 55 95 215)
(tty-color-define-1 "RoyalBlue2" 27 55 95 255)
(tty-color-define-1 "ForestGreen" 28 55 135 55)
(tty-color-define-1 "SeaGreen4" 29 55 135 95)
(tty-color-define-1 "aquamarine4" 30 55 135 135)
(tty-color-define-1 "SteelBlue" 31 55 135 175)
(tty-color-define-1 "SteelBlue3" 32 55 135 215)
(tty-color-define-1 "RoyalBlue1" 33 55 135 255)
(tty-color-define-1 "LimeGreen" 34 55 175 55)
(tty-color-define-1 "MediumSeaGreen" 35 55 175 95)
(tty-color-define-1 "MediumSeaGreen" 36 55 175 135)
(tty-color-define-1 "LightSeaGreen" 37 55 175 175)
(tty-color-define-1 "SteelBlue3" 38 55 175 215)
(tty-color-define-1 "DodgerBlue1" 39 55 175 255)
(tty-color-define-1 "LimeGreen" 40 55 215 55)
(tty-color-define-1 "SeaGreen3" 41 55 215 95)
(tty-color-define-1 "SeaGreen3" 42 55 215 135)
(tty-color-define-1 "MediumTurquoise" 43 55 215 175)
(tty-color-define-1 "turquoise" 44 55 215 215)
(tty-color-define-1 "turquoise" 45 55 215 255)
(tty-color-define-1 "LimeGreen" 46 55 255 55)
(tty-color-define-1 "SeaGreen2" 47 55 255 95)
(tty-color-define-1 "SeaGreen2" 48 55 255 135)
(tty-color-define-1 "SeaGreen1" 49 55 255 175)
(tty-color-define-1 "turquoise" 50 55 255 215)
(tty-color-define-1 "cyan1" 51 55 255 255)
(tty-color-define-1 "grey27" 52 95 55 55)
(tty-color-define-1 "grey32" 53 95 55 95)
(tty-color-define-1 "MediumPurple4" 54 95 55 135)
(tty-color-define-1 "MediumPurple4" 55 95 55 175)
(tty-color-define-1 "purple3" 56 95 55 215)
(tty-color-define-1 "BlueViolet" 57 95 55 255)
(tty-color-define-1 "DarkOliveGreen" 58 95 95 55)
(tty-color-define-1 "grey37" 59 95 95 95)
(tty-color-define-1 "MediumPurple4" 60 95 95 135)
(tty-color-define-1 "SlateBlue3" 61 95 95 175)
(tty-color-define-1 "SlateBlue3" 62 95 95 215)
(tty-color-define-1 "RoyalBlue1" 63 95 95 255)
(tty-color-define-1 "DarkOliveGreen4" 64 95 135 55)
(tty-color-define-1 "DarkSeaGreen4" 65 95 135 95)
(tty-color-define-1 "PaleTurquoise4" 66 95 135 135)
(tty-color-define-1 "SteelBlue" 67 95 135 175)
(tty-color-define-1 "SteelBlue3" 68 95 135 215)
(tty-color-define-1 "CornflowerBlue" 69 95 135 255)
(tty-color-define-1 "DarkOliveGreen4" 70 95 175 55)
(tty-color-define-1 "DarkSeaGreen4" 71 95 175 95)
(tty-color-define-1 "CadetBlue" 72 95 175 135)
(tty-color-define-1 "CadetBlue" 73 95 175 175)
(tty-color-define-1 "SkyBlue3" 74 95 175 215)
(tty-color-define-1 "SteelBlue1" 75 95 175 255)
(tty-color-define-1 "LimeGreen" 76 95 215 55)
(tty-color-define-1 "PaleGreen3" 77 95 215 95)
(tty-color-define-1 "SeaGreen3" 78 95 215 135)
(tty-color-define-1 "aquamarine3" 79 95 215 175)
(tty-color-define-1 "MediumTurquoise" 80 95 215 215)
(tty-color-define-1 "SteelBlue1" 81 95 215 255)
(tty-color-define-1 "chartreuse2" 82 95 255 55)
(tty-color-define-1 "SeaGreen2" 83 95 255 95)
(tty-color-define-1 "SeaGreen1" 84 95 255 135)
(tty-color-define-1 "SeaGreen1" 85 95 255 175)
(tty-color-define-1 "aquamarine1" 86 95 255 215)
(tty-color-define-1 "DarkSlateGray2" 87 95 255 255)
(tty-color-define-1 "IndianRed4" 88 135 55 55)
(tty-color-define-1 "HotPink4" 89 135 55 95)
(tty-color-define-1 "MediumOrchid4" 90 135 55 135)
(tty-color-define-1 "DarkOrchid" 91 135 55 175)
(tty-color-define-1 "BlueViolet" 92 135 55 215)
(tty-color-define-1 "purple1" 93 135 55 255)
(tty-color-define-1 "tan4" 94 135 95 55)
(tty-color-define-1 "LightPink4" 95 135 95 95)
(tty-color-define-1 "plum4" 96 135 95 135)
(tty-color-define-1 "MediumPurple3" 97 135 95 175)
(tty-color-define-1 "MediumPurple3" 98 135 95 215)
(tty-color-define-1 "SlateBlue1" 99 135 95 255)
(tty-color-define-1 "LightGoldenrod4" 100 135 135 55)
(tty-color-define-1 "wheat4" 101 135 135 95)
(tty-color-define-1 "grey53" 102 135 135 135)
(tty-color-define-1 "LightSlateGrey" 103 135 135 175)
(tty-color-define-1 "MediumPurple" 104 135 135 215)
(tty-color-define-1 "LightSlateBlue" 105 135 135 255)
(tty-color-define-1 "OliveDrab3" 106 135 175 55)
(tty-color-define-1 "DarkOliveGreen3" 107 135 175 95)
(tty-color-define-1 "DarkSeaGreen" 108 135 175 135)
(tty-color-define-1 "LightSkyBlue3" 109 135 175 175)
(tty-color-define-1 "LightSkyBlue3" 110 135 175 215)
(tty-color-define-1 "SkyBlue2" 111 135 175 255)
(tty-color-define-1 "OliveDrab3" 112 135 215 55)
(tty-color-define-1 "DarkOliveGreen3" 113 135 215 95)
(tty-color-define-1 "PaleGreen3" 114 135 215 135)
(tty-color-define-1 "DarkSeaGreen3" 115 135 215 175)
(tty-color-define-1 "DarkSlateGray3" 116 135 215 215)
(tty-color-define-1 "SkyBlue1" 117 135 215 255)
(tty-color-define-1 "GreenYellow" 118 135 255 55)
(tty-color-define-1 "LightGreen" 119 135 255 95)
(tty-color-define-1 "LightGreen" 120 135 255 135)
(tty-color-define-1 "PaleGreen1" 121 135 255 175)
(tty-color-define-1 "aquamarine1" 122 135 255 215)
(tty-color-define-1 "DarkSlateGray1" 123 135 255 255)
(tty-color-define-1 "brown" 124 175 55 55)
(tty-color-define-1 "maroon" 125 175 55 95)
(tty-color-define-1 "VioletRed3" 126 175 55 135)
(tty-color-define-1 "DarkOrchid" 127 175 55 175)
(tty-color-define-1 "DarkOrchid2" 128 175 55 215)
(tty-color-define-1 "DarkOrchid1" 129 175 55 255)
(tty-color-define-1 "sienna" 130 175 95 55)
(tty-color-define-1 "IndianRed" 131 175 95 95)
(tty-color-define-1 "HotPink3" 132 175 95 135)
(tty-color-define-1 "MediumOrchid3" 133 175 95 175)
(tty-color-define-1 "MediumOrchid" 134 175 95 215)
(tty-color-define-1 "MediumPurple2" 135 175 95 255)
(tty-color-define-1 "tan3" 136 175 135 55)
(tty-color-define-1 "LightSalmon3" 137 175 135 95)
(tty-color-define-1 "RosyBrown" 138 175 135 135)
(tty-color-define-1 "grey63" 139 175 135 175)
(tty-color-define-1 "MediumPurple2" 140 175 135 215)
(tty-color-define-1 "MediumPurple1" 141 175 135 255)
(tty-color-define-1 "OliveDrab3" 142 175 175 55)
(tty-color-define-1 "DarkKhaki" 143 175 175 95)
(tty-color-define-1 "NavajoWhite3" 144 175 175 135)
(tty-color-define-1 "grey69" 145 175 175 175)
(tty-color-define-1 "LightSteelBlue3" 146 175 175 215)
(tty-color-define-1 "LightSteelBlue" 147 175 175 255)
(tty-color-define-1 "OliveDrab2" 148 175 215 55)
(tty-color-define-1 "DarkOliveGreen3" 149 175 215 95)
(tty-color-define-1 "DarkSeaGreen3" 150 175 215 135)
(tty-color-define-1 "DarkSeaGreen2" 151 175 215 175)
(tty-color-define-1 "LightCyan3" 152 175 215 215)
(tty-color-define-1 "LightSkyBlue1" 153 175 215 255)
(tty-color-define-1 "GreenYellow" 154 175 255 55)
(tty-color-define-1 "DarkOliveGreen2" 155 175 255 95)
(tty-color-define-1 "PaleGreen1" 156 175 255 135)
(tty-color-define-1 "DarkSeaGreen2" 157 175 255 175)
(tty-color-define-1 "DarkSeaGreen1" 158 175 255 215)
(tty-color-define-1 "PaleTurquoise1" 159 175 255 255)
(tty-color-define-1 "brown3" 160 215 55 55)
(tty-color-define-1 "VioletRed3" 161 215 55 95)
(tty-color-define-1 "VioletRed3" 162 215 55 135)
(tty-color-define-1 "maroon2" 163 215 55 175)
(tty-color-define-1 "MediumOrchid" 164 215 55 215)
(tty-color-define-1 "DarkOrchid1" 165 215 55 255)
(tty-color-define-1 "sienna3" 166 215 95 55)
(tty-color-define-1 "IndianRed" 167 215 95 95)
(tty-color-define-1 "HotPink3" 168 215 95 135)
(tty-color-define-1 "HotPink2" 169 215 95 175)
(tty-color-define-1 "orchid" 170 215 95 215)
(tty-color-define-1 "MediumOrchid1" 171 215 95 255)
(tty-color-define-1 "tan3" 172 215 135 55)
(tty-color-define-1 "LightSalmon3" 173 215 135 95)
(tty-color-define-1 "LightPink3" 174 215 135 135)
(tty-color-define-1 "pink3" 175 215 135 175)
(tty-color-define-1 "plum3" 176 215 135 215)
(tty-color-define-1 "violet" 177 215 135 255)
(tty-color-define-1 "goldenrod" 178 215 175 55)
(tty-color-define-1 "LightGoldenrod3" 179 215 175 95)
(tty-color-define-1 "tan" 180 215 175 135)
(tty-color-define-1 "MistyRose3" 181 215 175 175)
(tty-color-define-1 "thistle3" 182 215 175 215)
(tty-color-define-1 "plum2" 183 215 175 255)
(tty-color-define-1 "OliveDrab2" 184 215 215 55)
(tty-color-define-1 "khaki3" 185 215 215 95)
(tty-color-define-1 "LightGoldenrod2" 186 215 215 135)
(tty-color-define-1 "LightYellow3" 187 215 215 175)
(tty-color-define-1 "grey84" 188 215 215 215)
(tty-color-define-1 "LightSteelBlue1" 189 215 215 255)
(tty-color-define-1 "OliveDrab1" 190 215 255 55)
(tty-color-define-1 "DarkOliveGreen1" 191 215 255 95)
(tty-color-define-1 "DarkOliveGreen1" 192 215 255 135)
(tty-color-define-1 "DarkSeaGreen1" 193 215 255 175)
(tty-color-define-1 "honeydew2" 194 215 255 215)
(tty-color-define-1 "LightCyan1" 195 215 255 255)
(tty-color-define-1 "firebrick1" 196 255 55 55)
(tty-color-define-1 "brown1" 197 255 55 95)
(tty-color-define-1 "VioletRed1" 198 255 55 135)
(tty-color-define-1 "maroon1" 199 255 55 175)
(tty-color-define-1 "maroon1" 200 255 55 215)
(tty-color-define-1 "magenta1" 201 255 55 255)
(tty-color-define-1 "tomato1" 202 255 95 55)
(tty-color-define-1 "IndianRed1" 203 255 95 95)
(tty-color-define-1 "IndianRed1" 204 255 95 135)
(tty-color-define-1 "HotPink" 205 255 95 175)
(tty-color-define-1 "HotPink" 206 255 95 215)
(tty-color-define-1 "MediumOrchid1" 207 255 95 255)
(tty-color-define-1 "sienna1" 208 255 135 55)
(tty-color-define-1 "salmon1" 209 255 135 95)
(tty-color-define-1 "LightCoral" 210 255 135 135)
(tty-color-define-1 "PaleVioletRed1" 211 255 135 175)
(tty-color-define-1 "orchid2" 212 255 135 215)
(tty-color-define-1 "orchid1" 213 255 135 255)
(tty-color-define-1 "goldenrod1" 214 255 175 55)
(tty-color-define-1 "SandyBrown" 215 255 175 95)
(tty-color-define-1 "LightSalmon1" 216 255 175 135)
(tty-color-define-1 "LightPink1" 217 255 175 175)
(tty-color-define-1 "pink1" 218 255 175 215)
(tty-color-define-1 "plum1" 219 255 175 255)
(tty-color-define-1 "goldenrod1" 220 255 215 55)
(tty-color-define-1 "LightGoldenrod2" 221 255 215 95)
(tty-color-define-1 "LightGoldenrod2" 222 255 215 135)
(tty-color-define-1 "NavajoWhite1" 223 255 215 175)
(tty-color-define-1 "MistyRose1" 224 255 215 215)
(tty-color-define-1 "thistle1" 225 255 215 255)
(tty-color-define-1 "yellow1" 226 255 255 55)
(tty-color-define-1 "LightGoldenrod1" 227 255 255 95)
(tty-color-define-1 "khaki1" 228 255 255 135)
(tty-color-define-1 "wheat1" 229 255 255 175)
(tty-color-define-1 "cornsilk1" 230 255 255 215)
(tty-color-define-1 "grey100" 231 255 255 255)
(tty-color-define-1 "grey3" 232 8 8 8)
(tty-color-define-1 "grey7" 233 18 18 18)
(tty-color-define-1 "grey11" 234 28 28 28)
(tty-color-define-1 "grey15" 235 38 38 38)
(tty-color-define-1 "grey19" 236 48 48 48)
(tty-color-define-1 "grey23" 237 58 58 58)
(tty-color-define-1 "grey27" 238 68 68 68)
(tty-color-define-1 "grey31" 239 78 78 78)
(tty-color-define-1 "grey35" 240 88 88 88)
(tty-color-define-1 "grey39" 241 98 98 98)
(tty-color-define-1 "grey42" 242 108 108 108)
(tty-color-define-1 "grey46" 243 118 118 118)
(tty-color-define-1 "grey50" 244 128 128 128)
(tty-color-define-1 "grey54" 245 138 138 138)
(tty-color-define-1 "grey58" 246 148 148 148)
(tty-color-define-1 "grey62" 247 158 158 158)
(tty-color-define-1 "grey66" 248 168 168 168)
(tty-color-define-1 "grey70" 249 178 178 178)
(tty-color-define-1 "grey74" 250 188 188 188)
(tty-color-define-1 "grey78" 251 198 198 198)
(tty-color-define-1 "grey82" 252 208 208 208)
(tty-color-define-1 "grey86" 253 218 218 218)
(tty-color-define-1 "grey90" 254 228 228 228)
(tty-color-define-1 "grey93" 255 238 238 238)
)
 
2006/03/04
How do you comment on the meaning of your tags?
Del.icio.us

I had a thought (probably not original) of using del.icio.us itself to comment on the meaning of a tag. Okay, one's own idea of the meaning of a tag. Why? Suppose I want to remember why I chose that tag's name or a group of tags for a particular concept. Where would I want to store those notes? Online, of course!

Here's my process:
  1. Log into your del.icio.us page, etc, and go to "your bookmarks".
  2. Type in the tags search box "define+tag" and start the search. "define" will be your meta-tag for identifying posts, and "tag" is the tag you want to define. I suppose you can put more tags at the same time: "define+tag1+tag2"
  3. You will get an empty page.
  4. Post/bookmark this page to del.icio.us: First type "define" and "tag" in the "tags" field. Then, type your description in the "notes" field. Save your bookmark.

Then when you go to your own "define" tag page, you'll get a listing of all the tags that you commented. For example:

del.icio.us/example/define+forum+mine
my comments to posts on other people's forums
to define forum mine ... on 1970-01-01 ... edit / delete

Of course, there's not much benefit in defining every tag or group of tags, but maybe its a useful cheat sheet for remembering and at a later time, sorting and maintenance. Plus the notes are saved with your links when you export/backup.

Do you use a similar system? Are there others that have fleshed out this idea?
 
2006/03/01
Counting duplicate lines and printing them out
Ruby

Perfect for those times when you want to count which duplicate TFTP ACKs are occurring.

a = Hash.new
$stdin.each_line do |ln|
ln.chomp!
a[ln] = (a.key?(ln)) ? (a[ln] + 1) : 1
end

puts "count: #{a.size}"
a.each { |k,v| puts "#{k}: #{v}" if v > 1 }
 
2006/02/27
starting syslog on Cygwin
Cygwin

Lots of software use syslog, I think... Like tftpd! To get started with syslog, run the syslogd-config command when you have installed inetutils-1.3.2. Then run net start syslog!
 
2006/02/26
Devfs in Gentoo, fighting Subversion on Colinux 0.6.1
Gentoo, Subversion, Colinux

What I want to do is to be able to use Subversion without those stupid hangs for /dev/random input. Usually you can workaround this by linking /dev/random to /dev/urandom. However, the current gentoo uses devfs, and I can't figure how to do exactly that.

Edit:
Gentoo can be configured to use either devfs, udev, or a static /dev. Set RC_DEVICES="static" in the /etc/conf.d/rc file. This is drastic, right?
 
curl & cookies
curl, webdev

curl allows you to automate the registration of web forms and cookies. A quick example with bloglines:

Create a cookie jar file of a bloglines login
curl http://www.bloglines.com/login --form "email=${email}"     --form "password=${password}" --cookie-jar ${cookieJarFile}

Then use that cookie jar file to export your subscription
curl http://www.bloglines.com/login?r=/export     --data "email=${email}&password=${password}&r=/export&Sign%20In=Log%20In"     --cookie-jar ${cookieJarFile} --location > ${outputSubscriptionFile}
 
2006/02/24
%q & %w
Ruby

%q gives you the quotes:
irb(main):001:0> p %q( a b c )
" a b c "
=> nil

While %w gives you the list.
irb(main):002:0> p %w( a b c )
["a", "b", "c"]
=> nil

Lispy!
 
2006/02/13
Where is mq_send explained?
manpages, Debian

mq_send man page is located in the manpages-posix or manpages-posix-dev .deb package.
 
2006/02/02
Convert Unix timestamps to human-readable format
Unix, Timekeeping, Excel, Ruby

If you get a time as a number from the Unix epoch (for example, you're looking at your generated Internet Explorer cookie file and you see "1149920545" == "2006/06/10 06:22:25") you'll probably want to convert it to be able to read it.

In Excel, it's as easy as writing in this formula:
=DATE(1970,1,1)+F1/86400 in a cell and formatting the results as "yyyy/mm/dd hh:mm:ss".

You could also try at the command line:
ruby -e "puts Time.at(1149920545).strftime('%Y/%m/%d %H:%M:%S')"

(For some reason, Time#iso8601 isn't available...)

Update 2006/02/13:
For Time#iso8601, you need to use require "time" to be able to use Time#iso8601.
 
2006/01/26
touching the date
Command Line, File Maintenance

The unix flavor command touch has both -d and -t options to set the time of the update to a file, but use -d because it respects you.

touch -d "2006/01/26 18:45" myfile

works as expected but

touch -t "2006/01/26 18:45" myfile

just errors out.
 
No scrollbar in IE @ BlogSpot?
Browser

I can't figure out why the scroll bar doesn't show up in Internet Explorer on this blog. It's strange.
 
2005/12/13
Ignoring Visual Studio 6 C++ files
Windows,Programming,Version Control

You may safely ignore *.ncb, *.opt, *.plg. Try this:

echo "*.ncb" > svn_ignore.txt
echo "*.opt" >> svn_ignore.txt
echo "*.plg" >> svn_ignore.txt
svn propset -R svn:ignore . -F svn_ignore.txt
 
2005/12/08
Revamping keyboard shortcuts, gmail... all around optimization
Windows,keyboard,Gmail

Made a keymap excel sheet and added it to AppPrefs

Windows Keys settings:

PureText:

TaskSwitcherXP:

Sizer:

Google Mail:
 
2005/09/25
Move your taskbar buttons around in Windows XP (hackish)
Windows XP, Keyboard

If you install the excellent freeware/open-source TaskSwitchXP, you're not only getting an Alt-Tab key enhancement, you're also getting a taskbar button re-ordering tool, albeit not directly. There is an option "Minimize windows to tray by right-click on Minimize button" in the General Settings. Activate this feature. Then, when you want to re-order some or all of the windows, right click on the window's Minimize button and then go to your tray notification area and reopen your windows in the order you want them assembled.
 
2005/09/23
Using Blogger for Word
Using Blogger for Word

Just go to the download page and work it.
 
How I keep remembering new ways of using computers. My (computer-centric) new-optimization learning blog.

Name:
Location: Kobe, Hyogo, Japan
September 2003 / October 2003 / December 2003 / March 2004 / April 2004 / May 2004 / June 2004 / July 2004 / August 2004 / September 2004 / February 2005 / March 2005 / April 2005 / May 2005 / June 2005 / July 2005 / August 2005 / September 2005 / December 2005 / January 2006 / February 2006 / March 2006 / April 2006 /


Powered by Blogger