BruceBlog

Thursday, December 10, 2009

Emailing an alert before an event scheduled in Emacs org system.

My goal is to get emacs to send me a text message before an appointment, but I only want one text message, not a message every two minutes. I cobbled together this "check-sent-messages" function that returns true if a message has not been sent before and false (nil) otherwise.

The first time a message is checked, this function looks for a matching message in a list of previously checked messages. If it doesn't find the message, it adds this one to the list and returns true (t). If it finds the message, it returns false. The list only lasts as long as emacs (or the emacs server) is running, which is long enough for my needs.

(defun check-sent-messages (mesg)
(interactive)
(setq ; I tried using "let" but I was having trouble with it
listlen_var_bk (length sent-message-list))
(add-to-list 'sent-message-list mesg)
(cond ((equal listlen_var_bk (length sent-message-list)) nil)
(t t)
)
)


This function sends a message prior to an event scheduled in Emacs' org mode. It only sends the message if it hasn't been sent before (it uses the check-sent-messages function to figure out if it's been sent). I'm sending it to a canned, fixed address because I always want the messages to go to the same place and I'm not that concerned about making this function more general purpose. I can send the messages to my phone's text message address and get a message anywhere, which is what I need.

;; This is the function to call to send mail when an appointment is due: appt-disp-window-function.

(defun appt-email-send (min-to-app new-time appt-msg)
"Send an appointment reminder email due in MIN-TO-APP (a string) minutes.
NEW-TIME is a string giving the date and time of the appointment (or any other string)."
(setq email_body
(format " Appointment %s. Time: %s."
(if (string-equal "0" min-to-app) "now"
(format "in %s minute%s" min-to-app
(if (string-equal "1" min-to-app) "" "s")))
new-time))
(if (check-sent-messages appt-msg) (my-message-mail-fn "recipient@email.com" appt-msg email_body))
)

Sunday, November 29, 2009

Emacs and elisp - sending mail

Here's an elisp function that takes the recipient's address, the subject, and
the body of the message as parameters. There's a sample call below it.

;; This function sends a mail message
(defun my-message-mail-fn (addr subj body)
"Send a message in an email"
(interactive)
(let ((orig-buffer (current-buffer)))
(message-mail addr subj)
(message-goto-body)
(insert body)
(message-send-and-exit)))

;; Here's how to test it (or call it):

(my-message-mail-fn "yahoo@yahoo.com" "trial subject" "here's the body")


Simple function for sending a mail message using emacs and elisp

Simple function for sending a mail message using emacs and elisp

Here's a function that sends an email message using elisp. This is about
the simplest implementation of a function, and it should serve as a good example.
;; This function sends a mail message
(defun my-message-mail-region ()
"Send a canned message in an email"
(interactive)
(let ((orig-buffer (current-buffer)))
(message-mail "user@userdomain.com" "message subject")
(message-goto-body)
(insert "Here's the message body")
(message-send-and-exit)))

Sending mail with Emacs - take 2

Sending mail with Emacs - take 2

My post yesterday describes how to setup Emacs to send mail using the
Gnus mail facility. I've simplified that setup somewhat, and it works
with the message-mail function.

I got rid of the .gnus.el file (since I won't be starting gnus anymore)
and put these lines in my .emacs file:

;;;; Start mail setup lines
(setq message-send-mail-function 'message-send-mail-with-sendmail)
;; we substitute sendmail with msmtp
(setq sendmail-program "C:/Program Files/gnu/msmtp/msmtp.exe")
;;need to tell msmtp which account we're using
(setq message-sendmail-extra-arguments '("-a" "user"))
;; you might want to set the following too
(setq mail-host-address "gmail.com")
(setq user-full-name "My Name")
(setq user-mail-address "user@gmail.com")
(setq sendmail-program "C:/Program Files/gnu/msmtp/msmtp.exe")
;;;; End mail setup lines

You need to substitute appropriately for your email account. It should
work with SMTP servers other than gmail's, also.

Refer to yesterday's post to see how to setup the msmtp program, and
where to find it.

Saturday, November 28, 2009

Sending Mail using Gnus and Emacs
(This turned out to be the first post in a series, so read the next few posts if you find this info helpful.)

Well, this post won't look like much, but I'm sending it from emacs using gnus from MS Windows XP. I've spent too much time getting this process to work, with hopes of making it part of an org-based reminder system.

Superficially, here's how I'm sending the email from emacs:

1) Use the command gnus-msg-mail
2) Fill in the To:, Subject:, and the body of this post
3) Hit Ctl-c, Ctl-c to send.

When I send the message, it is going to route through an msmtp SMTP mail client (see http://sourceforge.net/projects/msmtp/). The msmtp program will send it to gmail SMTP server (there's nothing magic about using gmail - it's the one I got to work first). Then the gmail SMTP server sends it on to my blogger account address, where it will automatically
post.

The hard part is getting the internal configuration right. I went down one, maybe two dead ends before discovering this setup. The deadends I got stuck on used the emacs message-mail (a mail mode that comes with Gnus) and mail-compose (an emacs mail system). I tried configuring
smtpmail in emacs to interface to GMail with SMTP and tls authentication and failed several different ways. Finally, I discovered the msmtp process, which I'll outline here.

Here's how to set things up:

1) Download msmtp, unpack it, and put it somewhere (I put it in C:\Program Files\gnu\msmtp).

2) Create a .gnus.el file in your emacs home directory (where .emacs is), with these contents, making appropriate substitutions for account details:

(The following is based on this post on the EmacsWiki.)

;;;;; Start File Contents

;; with Emacs 23.1, you have to set this explicitly (in MS Windows)
;; otherwise it tries to send through OS associated mail client
(setq message-send-mail-function 'message-send-mail-with-sendmail)
;; we substitute sendmail with msmtp
(setq sendmail-program "C:/Program Files/gnu/msmtp/msmtp.exe")
;;need to tell msmtp which account we're using. If your email is
;; user@gmail.com, then the following line works:
(setq message-sendmail-extra-arguments '("-a" "user"))
;; you might want to set the following too
(setq mail-host-address "gmail.com")
(setq user-full-name "Your Name")
(setq user-mail-address "user@gmail.com")

;;;;; End File Contents

3) Gnus is supposed to load the .gnus.el file when it starts up, but it
hasn't for me, so add this line to .emacs:

(load-file ".gnus.el")

4) Create an msmtprc.txt file to configure msmtrp. The file goes in your HOME folder, which is where the .emacs file is. The contents of this file should be as follows (substituting your username and password appropriately):

######## Start File Contents

########################
account default
host smtp.gmail.com
tls on
tls_certcheck off
auth on
user yourname@gmail.com
password yourpassword
port 587
from your_return@address

logfile ~/msmtplog.txt

######## End File Contents

The logfile may not be needed - it shows what mail has been sent. I'm happy to say I don't know what it holds if sending mail fails.

5) Once all the files have been created and saved, exit and restart emacs to make sure everything loads properly. Then use gnus-msg-mail to send a test message. Good luck!

Note: I suspect I can configure Emacs mail to use the msmtprc program without using the Gnus mail system, which is a touch of extra overhead. Maybe I'll try that, but right now I'm happy things work.

Later - it works, so see my next post for how to skip the Gnus mail system.


Saturday, October 18, 2008

Ploticus

I've been looking for a plotting package that I can drive from C++ and can plot data my software generates. I want something I don't need to spend a lot of time figuring out and that I don't need to link into my software. I'm trying Ploticus (downloaded from here). I'm running Windows.

I unzipped and placed the files into a directory structure. There doesn't seem to be any formal installation needed.

I ran the "run_test_script.bat" script to try it out. It reminded me to put pl.exe in my path, which I did, and then the script ran fine (with some warnings unrelated to drawing the plots).

I ran the "run_prefabs_test" script. After changing the path for the environment variable in the batch file, it ran fine also.

From the batch file, I figured out that the command line: pl -gif stock2.htm runs the stock2.htm script.

Now I'm changing the stock2.htm file to see if I can get things to work with my data. I'm ignoring documentation for now. My file looks like (the first few rows are below):

Date,Open,High,Low,Close,Volume,Adj Close
2001-11-26,52.37,52.37,52.37,52.37,000,47.07
2001-11-27,52.43,52.43,52.43,52.43,100,47.12
2001-11-28,52.43,52.43,52.43,52.43,000,47.12
2001-11-29,52.43,52.43,52.43,52.43,000,47.12

I had to change the date ranges (from the scrip file):

//xscaletype: date dd-mmm-yy // Original line
xscaletype: date yyyy-mm-dd // new line
xrange: 2001-11-26 2008-10-03

//stubformat: Mmmdd // Original line
stubformat: yyyy-mm-dd // new line
stubrange: 2001-11-26

The script ran, but the scales are way off.

I am resorting to the documentation. Just using Google and the term I'm looking for gets me to helpful information quickly. For example searching for "ploticus tincrement" let me pull up the appropriate documentation quickly.


Well, it worked out. I put symbols on the graph and figured out how to use command line options. Maybe I'll put more info on this blog when I have a bit more time.

Saturday, August 02, 2008

Purchasing Meat at the San Mateo County Fair


Meat from 1/4 of a 1300 lb Steer

Purchasing Meat at the San Mateo County Fair

The auction starts at 10 AM on the second Saturday of Fair

You do n
ot have to be present at the auction to purchase. Proxie bidders can be arranged easily. 
 
Meat from one Lamb


Meat from one Pig

For nearly a century, the San Mateo County Fair has hosted the Youth Livestock Auction for young people to sell their top quality animals. These youth have selected, fed, cared for and groomed these animals in preparation for qualification at the livestock competition and show prior to the auction. Very specific guidelines and criteria for slaughter must be met before the animal can be accepted into the auction.

Here's the amount of meat one gets from each breed of animal (animals vary in weight, so the actual amount will differ from that below):

1000 lb Steer: 460 lb meat
100 lb Goat: 33 lb meat
200 lb Hog: 140 lb meat
100 lb Lamb: 50 lb meat

Animals are sold live, and the buyer pays for processing fees. The process for choosing a custom cut and wrap house is seamless - the buyer fills out a form at the fair to specify a processing house. A few weeks after the fair, you will receive a phone call asking how you want the meat processed (size of chops, what types of cuts, perhaps you'd like spicy sausage or smoked ham). You'll be told when the meat is ready and when you may pick it up.

Chickens and turkeys are also sold at auction. The 4Her's put a lot of work into raising each bird, and prices reflect the work - not market value. Chickens usually sell for $100 and up, and buyers think of the price as a reward for the dedication the 4H'ers take when the raise animals. Poultry will all be processed together at a licensed facility and delivered to you once processing is completed.



County Fair Website: http://www.sanmateocountyfair.com/

San Carlos Eaton Hills 4H Club Web Site


Saturday, December 08, 2007

Emacs and Python

I've been using Emacs with Python on Windows. I found that when I run Python programs from within emacs, and the Python program used a windowing package, then the program would not exit properly and allow it to be run again.

If I go into the task manager and kill the python process, then I could run the program again. I found the solution is to add a call to os.exit() at the end of the program, so it kills the Python process on the way out.

I just started using Emacs version 22.1, and I am a complete neophyte at Python. I've found that Python mode in Emacs is pretty potent. It runs the code in the active buffer just by pressing ^C twice. I also found I could only run the Python code once, until discovering the solution I mention above.

Sunday, July 23, 2006

Checkride


I arrived at 9 AM for a 10 AM checkride, feeling more nervous than I should have. That first hour allowed time to finish filling out the standard 8710 form and to preflight the plane. The plane had been ramped overnight for an oil change (which didn't happen due to rain) and it had been pushed back into the water before I arrived, a fact that would figure into the first 10 minutes of the test.

The wind had changed direction completely and was about 10 knots out of the north rather than 5 knots from the south as it had been for all my lessons. That meant we'd have a long taxi down the lake and then point back toward town and takeoff, leaving it to me to judge when we had enough distance to leave the water and clear the town. I discussed the distance with my instructor and resolved to be plenty conservative. We could talk sports or something while traveling downwind.

The examiner arrived right on time. We got through the paperwork, spoke a bit, and then hopped in the plane. The plane was docked pilot-side-to, so I got in last. I put the water-rudders down, fired it up, and we set off. We started a tight, right 360 and I discovered, to my dismay, that I couldn't push the left rudder pedal down to straighten out. The pedal was stuck as if there was a control lock on it. I pushed as hard as I could, but couldn't move it. By then we were pointing back at the dock, so I shut the engine down.

My instructor came down to see what was happening. "Is there a control lock on this thing?" I yelled, feeling a bit foolish. "No, apply some power!"

I started back up again and when we were pointing away from the dock applied power. The water pushed the rudders back to their straight positioin and everything was normal. Afterwards, I learned that when they'd pushed the plane back into the water from the ramp, the rudders had been pushed to a 90 degree position and the only way to straighten them out was with power. The rudder cables wouldn't do it.

That was not a great way to start a checkride, but I calmed myself down a bit and looked forward to a long taxi downwind. After a few minutes, the examiner suggested a step-taxi (which is part of the exam, anway.) I pulled the water-rudders up (finally, I figured those things out.) I got it up on the step and the plane immediately turned to the left - a combination of P-factor and weathervaning (and maybe not enough right-rudder, but who knows.) Anyway, the easy way to get things back under control is to kill the power, so I did that, the plane settled down, I put the water-rudders back down, and we continued to slow-taxi downwind.

After about five minutes (maybe ten) we turned around and looked at the town in the distance. I took off and was at about 500' over the town, so I guess I'd left plenty of room. The closer one gets to town, the more likely it is that boats will pop out of coves, so the extra space is a safety advantage for that reason too.

We climbed to 3100' and did a stall and steep turns. The right-turn wasn't all that great (it could have used more rudder), but I acknowledged that and we continued on.

We came back for a smooth-water landing, although the water was pretty rough. On that landing, I managed to skip the plane off the surface like a kid skips a stone and was back up to about 15' when I decided I didn't know what the plane was going to do next and I didn't want to find out, so I went around.

Now I was wondering what I'd been thinking when I decided to get this rating, but I resolved to stick it out. I knew I could land the thing; I just hoped I'd land it on the next try. Well, the next landing (smooth-water again) was fine, and the attitude was pretty good too. Then I took off again and came back for a normal landing.

Finally, we were almost done. I step-taxiied back, docked (which almost required a second attempt due to an off-dock wind and optomistically cutting the power early.) That was it. I passed!

Cemetery Approach


In Rangeley, they sometimes use an approach called the "cemetery Approach" (so named due to flight over a cemetery on final). The goal is to touch down in a cove with no risk of running in to the opposite shore. There's maybe a half mile of water, so landing there isn't particularly tight, but I don't know that there is enough water to take off in that distance.

This approach is useful when the wind is from the east. I did the approach and landing once, passing near a boat and touching down just after it. I was a bit concerned about landing with plenty of room to spare, but I setup the approach to pass just above the trees at the water's edge and the subsequent landing was no problem.

Sailing


Sometimes, it's just too windy to turn a float plane away from the wind to approach a dock or beach. In that case, just put it in reverse or travel sideways. Floatplanes naturally weathervane into the wind, and are so willing to do so that it can be hard to stop them from turning. In a strong wind, one uses weathervaning to advantage by pointing the plane into the wind, reducing power to idle, and then letting the plane be blown backwards. Speed up the process by holding the doors open, or steer by opening one door or the other or by using the water rudders. The keels on the floats help control direction so you can go backwards in one direction or another.

The plane can be induced to go sideways by using the engine to hold it in one spot against the wind and then by using a door or the rudders to angle the plane off wind. It will then travel sideways under engine power, but it won't go forward or backward if the throttle power matched the wind power.

We did a bit of sailing in a fairly light wind, but it was enough to get the idea.

After sailing, we docked twice. Once on my side and once on the passenger's side. When docking alone or on the pilot's side, the pilot has to be ready to get out of the plane, down on the float, and onto the dock without letting the plane blow away (especially if the plane is full of passengers). When docking on the passenger's side, it's a lot harder to see when the pontoon is going to touch and the passenger has to be capable of helping.

My dockings were generally good. Today, during docking practice, I hit the dock moderately hard and the plane bounced off the protective tires on the dock(my instructor snickered.) We had to wait a bit for the plane to blow back to the dock, but an on-shore wind helped a lot (otherwise, I'd have had to restart the engine.)