Saturday, December 15, 2012

Yellow Curry with Chickpeas and Potatoes


A modified version of this recipe, to respect the people who will be eating my food tomorrow.
Makes 6-8 servings

Ingredients

  • 2 14-ounce can of coconut milk
  • 3 tablespoons yellow curry paste
  • 1 29 oz can chickpeas
  • 1 cup water
  • 2 medium potatoes
  • 1/4 large onion
  • 1 14-ounce can of baby corn
  • 1 teaspoon soy sauce
  • 1 teaspoon sugar
  • 1 lime

Instructions

  1. Slice the onion and baby corn into bite-sized pieces.
  2. Peel, cut, and parboil the potatoes for ~5 minutes. Set aside.
  3. Open one can of coconut milk and scoop the top thicker cream part into a pan.
  4. Heat this cream over medium heat until the oil just starts to separate from the milk.
  5. Then add the yellow curry paste and saute with the cream until it becomes fragrant.
  6. Then add the remaining 1 1/2 cans of the coconut milk and water and bring to a boil.
  7. Let cook until the consistency of the curry is what you prefer. You can use less water if you want a shorter cooking time.
  8. Add the potatoes, onions, and baby corn and cook until just done, but still firm.
  9. Mash 1/2 a potato and add to thicken.
  10. Adjust seasonings with soy sauce and sugar to taste.
  11. Garnish with thinly sliced kaffir lime leaves and red peppers. Serve with jasmine rice.

Wednesday, May 2, 2012

Logging to syslogd from Python


On Unix there is a syslog service that handles centralized logging. Using it for logging from your daemons has the advantage of putting control of the logging options in the hands of the system administrator, without involving you, the developer. If they want certain log rotations, or there is a preferred directory, or if the logs are sent over the network to a central logging server, it has nothing to do with you, as long as you are logging to syslog.

First off, you need a config file something like this:

[loggers]
keys=mysyslogger_l


[handlers]
keys=mysyslogger_h


[formatters]
keys=mysyslogger_f



[logger_mysyslogger_l]
level=NOTSET
handlers=mysyslogger_h
propagate=0

[handler_mysyslogger_h]
# Add this line to syslog.conf
# local1.*         /var/log/distributor.log
level=NOTSET
formatter=mysyslogger_f
class=handlers.SysLogHandler
args=('/dev/log', handlers.SysLogHandler.LOG_LOCAL1)

[formatter_mysyslogger_f]
format=%(message)s

Then, you'll need to read that config file with your Python program:

import logging
import logging.config

logging.config.fileConfig("logging.conf")
log = logging.getLogger("mysyslogger_l")
log.info("This an info message.")
log.error("This is an error message.")

Then you'll probably need to configure your syslog to write the messages somewhere. Add this line to /etc/syslog.conf and run /etc/init.d/syslog restart:

local1.*         /var/log/mysyslog_file.log

Sunday, March 4, 2012

Graphing Gaussian Curves in Octave

I've been working my way through Prof. Sebastian Thrun's second AI course,CS 373 Programming a Robotic Car that he is offering through the new company, Udacity. In week two he covers Kalman filters as a method of estimating location given uncertainty in sensor data and uncertainty in movement.

In an effort to get a better understanding of how the variables affect the shape of the Gaussian distribution that represents the probable state of the variables being modelled, I fired up Octave. Octave is math software that allows the user to do a large variety of things, but in my case I just wanted to use it to graph a Gaussian distribution and see the effect of changing the variables.

Thanks to this helpful, and to the point, post, it was reasonably straight forward to start graphing curves in two dimensions.

x = [1:0.1:6]
sigma = 5

mu = 10
fx = (1/sqrt(2*pi*sigma^2)*exp(-(x-mu).^2/(2*sigma^2)))
plot(x, fx)

This is enough to get started.

Wednesday, January 25, 2012

Gluten Free Bechamel Sauce

2 cansevaporated milk
8 tbspcorn starch
4 Cwater
2beaten eggs
1/2 Cshredded pecorino cheese
1 tbspbutter
1 tspsalt
1 pinchgrated nutmeg
  1. Bring water to a boil.
  2. Add 1 can evaporated milk.
  3. Add corn starch, whisk.
  4. Lower heat to medium.
  5. Add 2nd can of milk.
  6. Add butter.
  7. Whisk lightly until sauce thickens.
  8. Add eggs in slow stream, whisking quickly so they don't cook in chunks.
  9. Add nutmeg.
  10. Take off heat.
  11. Add cheese and mix thoroughly.

Thursday, June 30, 2011

Customizing the Python Interpreter

I was working with a friend on debugging an odd pickling issue. In order to really play with it, we started a Python interpreter and ran through the list of imports and sys.path.appends necessary to set up active database and memcache connections, as well as load the project code.

My friend mentioned that he had a python session on his desktop that he never dared to close, since the setup had been so much trouble.

Thinking that it would be great to have this more frequently, and more easily, I created a python file which gets loaded every time I start my python interpreter, pyprompt.py.


import sys
import os

def getProjectDir(d=os.getcwd()):
projects = os.path.join(os.environ['HOME'], "projects")
if os.path.dirname(d) in ['/home', '/']:
return None
elif projects == os.path.dirname(d):
if os.path.exists(os.path.join(d, "src/pylons/proj")):
return d
else:
return None
else:
return getProjectDir(os.path.dirname(d))

pd = getProjectDir()
if pd:
print
print "Detected %s project. Setting up database." %(os.path.basename(pd))
print
sys.path.append(os.path.join(pd, "src/pylons/proj"))
import proj
from proj.lib.helpers import setup_db
factory = setup_db()
dbcon = factory.getConnection()


Now I want this file to run every time the python interpreter is started.


export PYTHONSTARTUP="/home/jsimpson/bin/pyprompt.py"


So, what happens is, when the python interpreter starts, it checks the PYTHONSTARTUP variable for a python file to run. That executes the getProjectDir() function, which tests if my current working directory is in a project. (Our workflow includes many branches of the main project.) If I am in a project, it will import the files from that project and setup my interpreter, ready for some interactive work.

Readline Interactions

I previously posted on how Emacs keys work for interaction on many different shells, bash, python, ruby, mysql, etc.

Recently I was trying to improve my python interaction experience when I stumbled across this:

http://www.linuxselfhelp.com/gnu/bash/html_chapter/bashref_8.html

This details some interesting key bindings in bash, as well as how to change the key bindings.

Thursday, May 5, 2011

Custom Tab Complete and Bash Functions

Everyone with even a little experience in Unix has their own special aliases. Maybe you have:

alias wcd="cd ~/workspace"

to take you to the directory where you have your projects. Maybe you have some really sophisticated aliases that change your bash configuration and path when you hit a certain directory.

One of the challenges I found when I moved off of csh to bash was csh aliases had parameters, so you could make niffty aliases that had some value in the middle:

alias fi 'find . -name \!:1 -exec vim {} \;'

(The first alias I ever used, from my friend William Hui). Using this alias, if you run:

fi mycode.c

It will search through the directory tree to find mycode.c and open it in vim. Bash doesn't seem to give you the same level of control over alias parameters. However, recently I've learned that you can create a bash function, and it will run like a command on the command line.

Since fi is a reserved word that closes an if statement in bash, we'll switch from fi to fim. Then create this in a file (functions.sh):

fim() {
test ! -z "$1" && find . -name $1 -exec vim {} \;
}

and source the file in your current environment:

source functions.sh

then this works in bash:

fim mycode.c

Since you are now using a bash function instead of an alias, you can squeeze any amount of bash code you want in there, format it nicely, even (possibly) comment it. Aliases can get pretty crazy sometimes but a bash function should be fairly readable.

So, that's cool, flexible bash functions instead of aliases. Which brings me to my next trick. Everyone loves tab completion. Okay, that may be a fairly sweeping statement, but watching people use the Unix command line, I think I can safely say most people love tab completion.

With newer versions of bash, you can build your own custom tab completion. Lets say you have a directory where you do a lot of your work, and you often want to go there to some project.

wcd() {
cd ~/workspace
}

That's cool, anywhere you are
wcd
takes you there. However, now that it's a bash function, it's really straight forward to augment it a little:

wcd() {
cd ~/workspace/$1
}

That's cool too. Now, assuming your working directory looks like this:

[jsimpson@jsimpson-lnx1 workspace]$ ls
bookcatalog/ mashup/ mywebsite/ out.html

you can:

wcd bookcatalog

and anywhere you are will take you to ~/workspace/bookcatalog. However, if your workspace looks like mine, it has many projects, some of which haven't been worked on in months or years. Sometimes I need a little help to remember where I'm going. Wouldn't a custom tab complete be great?

wcd() {
cd ~/workspace/$1
}

_wcd() {
local cur opts
cur="${COMP_WORDS[COMP_CWORD]}"
opts=$(cd ~/workspace ; ls -d */. | sed 's|/./||')
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
}
complete -F _wcd wcd

The first function we've seen before. Once you press enter on the command line, this is the function that will do the work of changing you to a new directory.

Last line first, complete is a utility that registers a function (-F for function) to be run every time you tab when wcd is the first command on the command line.

_wcd is the function that computes your list of possible completions.

local - sets up some local variables.

cur - gets the last element of the COMP_WORDS array, which is a special bash variable that holds the array of parameters to the command line you are pressing tab on.

opts - this line gets a string of space delimited words that are possible completions, something that will look like this "dir1 dir2 dir3".

COMPREPLY - this is a special bash variable that is an array of all the possible completions. So, if you are here:

wcd m

When you hit tab, the function will run and evaluate like this:

cur="m"
opts="bookcatalog mashup mywebsite"
COMPREPLY=(mashup mywebsite)

and on the command line you will see this:

[jsimpson@jsimpson-lnx1 workspace]$ wcd m
mashup mywebsite


Debian Administrator's Introduction to Bash Completion

Tuesday, March 22, 2011

Consolidated Java Jars

Sometimes I just want my little Java app to be simple. It's suppose to be a command line client, or some JMS utility, and I just want to move it around easily, call it easily and have it work.

But, it's got a bunch of files, and I used something for a network library, and a command line parsing library...

What I would like is a consolidated jar, one jar that has what is needed, it is configured so it can be run with java -jar myjar.jar, and it will work.


<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}"/>

<jar jarfile="${dist}/Util.jar" basedir="${build}">
<manifest>
<attribute name="Main-Class" value="Main"/>
</manifest>
<zipfileset src="lib/commons-cli-1.2.jar" includes="**/*.class"/>
</jar>
</target>


This ant target will create a jar, and include in the jar, all the class files from commons-cli-1.2.jar. Now, assuming no other dependencies, I should be able to ssh the Util.jar to any destination machine with Java and run it.

Monday, February 14, 2011

Managing Vim Plugins with Mercurial

I always felt a little as though I was risking something each time I installed a new vim plugin. I mean, the vim plugins provide me with awesome power of customization, and my vim setup helps me work, so messing it up would be bad, and each new plugin just throws a bunch of stuff into my vim directories.

I could have tried to organize it based on the plugin name, but that always seemed like too much work.

When I read Steve Yegge's post about his dot-emacs-file, that seems cool. All his configuration files controlled by svn. However, I don't have an offsite svn repo to use.

Then I read the Joel on Software post about distributed version control and Mercurial.

I had used Mercurial before a little, but Joel's post helped me realize that I was stuck thinking about Mercurial as if it was some sort of advanced svn. It's not. I always assumed I had to have some sort of Mercurial repo that served as the 'master' copy, much the way an svn server works.

However, Mercurial is different. You can make any directory into it's own repo. This is fantastic. Now I'm using Mercurial to version control basically any test project I work on, it's fantastic. Every directory is it's own repo. If I need to move it to another computer or give it away to someone, or take some of my test projects to work, no problem. Tar it up and the whole history is there.

The next obvious step was to version control my .vim dir. Now, every time I add a new plugin, it becomes it's own commit in Mercurial. I could go back in history at any time and look at the files that were part of any plugin, or revert any change I make.

To complete the process, I moved my ~/.vimrc file into ~/.vim and renamed it myvimrc. Now, my ~/.vimrc file has only one line:


source ~/.vim/myvimrc


and .vim/myvimrc is version controlled with Mercurial.

Monday, January 31, 2011

Bash, Readline and Emacs

I've known for a while that there are some good bash keyboard shortcuts.

Ctrl-A - cursor to the beginning of the line
Ctrl-E - cursor to the end of the line
Ctrl-R - reverse search for a historical command


Cool, those are great, but recently I realized that bash, by default, uses Emacs key mappings. (You can change it to vi with set -o vi, but this post is about Emacs keys). That opens up a whole new world. Whatever works in Emacs you can try in bash:

Alt-F - forward 1 word
Alt-B - backward 1 word
Alt-Backspace - delete 1 word backwards
Alt-d - delete 1 word forwards
Alt-8 Alt-B - move 8 words backwards


During a search (Ctrl-R), once you have a match, you can hit Ctrl-R to search backwards to the next match, Ctrl-S to search forward to the next match. Any navigation key will drop you out of the search and into editing the command line your search matched.

All of these are standard Emacs behaviors, and I'm sure there is more to be discovered.

Only in the last couple days have I realized that this awesome editing functionality is a product of the readline library from GNU, not a product of bash. Which means, you get all this stuff in any product that uses readline. For example, the mysql command line tool, the python interpreter, the ruby interpreter, the Octave interpreter, Postgresql interpreter. I'm sure there are many more as readline is widely used. Why I never made this connection before, I have no idea.

NOTE: Some keys get intercepted by your OS or terminal. For example, I use Gnome terminal, which, with a default configuration, has a menu bar, and Alt-1 - Alt-0 are configured as hot keys for selecting tab 1 - 10. I edited the keyboard shortcuts (Edit -> Keyboard Shortcuts) and removed the key mappings for selecting a tab with Alt-. Then I right clicked in the terminal and deactivated the Show Menubar setting. I would much rather have the hot keys than the menus that I never use.

Sunday, April 11, 2010

Listening Comprehension

Exercise I

Play your recorded dialog multiple times. Each time listen for something different.

1. list new words or phrases, and new constructions
2. list unusual figures of speech, colloquialisms
3. list technical terms.
4. list new proverbs or sayings.
5. play it 1 sentence at a time and transcribe it.

* exercise taken from "Study Skill for Language Students: A Practical Guide", by Sydney G. Donald and Pauline E. Kneale

Wednesday, August 12, 2009

Clarifying Question Idea

Hear a sentence in the L2, then, instead of translating or understanding the sentence, generate a clarifying question about the sentence. One observed trait of outstanding language learners is their ability to provoke more input.

Friday, August 7, 2009

Cantonese Learning Resources

http://cantostories.podbean.com/
- stories in Cantonese.

Thursday, August 6, 2009

New Thoughts on Self Teaching Language

I stumbled upon a couple of new sites:


http://www.anthonylauder.com/
- this gentleman is teaching the benefits of connectors as he calls them, those little pieces of dialog that keep a conversation flowing. He is learning Czech and he tracked down the Czech phrases on his list, learned them well and uses them to keep the conversation moving along. It sounds like a great idea to me. Those little phrases like, I think ..., for example ..., I've heard, and so many others fit very naturally into nearly any conversation.

http://www.fluentin3months.com/
- from someone who has taught himself several languages. He's just posting his ideas on learning.

Sunday, August 2, 2009

Shadowing

Suppose to assist development of a good accent and fluency.

Detailed here:

http://www.youtube.com/watch?v=130bOvRpt24

Demonstrated here:

http://www.youtube.com/watch?v=VdheWK7u11w


- walking swiftly, purposefully with good posture.

Steps of Shadowing. Each step is done several times, but really as many as you can, as long as it is still profitable.
- Blind Shadowing - no book, walking, listening, repeating.
- Reading & Shadowing - continue to shadow the material (listening, speaking L2), reading L1.
- Reading with your Thumbs - shadow and read with your thumb under the appropriate part of the L1 text, looking over to the L2 text whenever possible.
- now focused on the L2 text, flipping back to L1 text as you want for confirmation.
- Stay on the L2 text, even if uncertain. Now you are trying to keep your mind in the L2.
- Now, turn off audio, read and analyze the text.
- Read the text aloud.
- Writing the text.

Thursday, July 30, 2009

Listening/Learning Strategies

From Lessons from Good Language Learners edited by Carol Griffiths:

1 Cognitive strategies: these are activites which learners use to remember and develop language and to facilitate comprehension.
- predicting what a pice of listening will be about, or what language/information will come next;
- drawing inferences when information is not stated or has been missed;
- guessing meanings of unkown words;
- using intonation and pausing to segment words and phrases;
- other micro-strategies to do with processing language - identifying stressed words, listening for markers, listening for structures etc.;
- using schematic and contextual information (top-down) together with linguistic information (bottom-up) to arrive at meanings;
- visualizing the situation they are hearing about;
- piecing together meaning from words that have been heard.
2 Megacognitive strategies: these are activities which learners ue to organize, monitor and evaluate how well they are understanding.
- focusing attention, concentrating and clearing the mid before listening;
- applying an advance organizer before listening (I think the topic is going to be ..., so ...);
- going in with a plan (I'm going to listen for ... words I know/key words/cognates ...);
- getting used to speed and finding ways of coping with it;
- being aware when they are losing attention and refocusing concentration;
- deciding what the main purpose of listening is;
- checking how well they have understood;
- taking notes;
- paying attention to the main points;
- identifying listening problems and planning how to improve them.
3 Socio-affective strategies: these are activities in which learners interact with other people in order to help their comprehension and encourage themselves to continue listening.
- asking for clarification;
- checking that they have got the right idea;
- providing themselves with opportunities for listening;
- motivating themselves to listen;
- lowering anxiety about listening;
- providing a person response tot he i nformation or idea presented in the piece of listening;
- empathizing with the speaker and trying to understand the reason for a particular message.

Mandarin Chinese Learning Resources

http://chinese-characters.org/
- a resource that discusses the etymology of the characters.

http://www.chineseetymology.org/
- a technical, dictionary like resource that describes the etymology of characters.

http://zdt.sourceforge.net/
- character flashcard program.

Monday, July 27, 2009

Language Learning Games

What to do to practice language input/output.

1. Have someone read the numbers in the L2 and then write them in numerical form. This is specifically aimed at over coming the trouble many people have negotiating in a market because the numbers don't come quickly enough.
2. 4/3/2 - documented by Paul Nation. Prepare a talk, then give the talk to 3 listeners. 1st listener for 4 minutes. No notes, no written queue cards. Just talk. This is not a vocabulary development exercise, this is a fluency exercise. After the talk, move to the next listener. Repeat the talk for 3 minutes. Move to the next listener. Repeat the talk in two minutes.
3. Circumlocution - or something like that. Basically talk around a word. Something like Taboo. This is a normal part of learning to speak a second language, you must be able to explain something when you don't know the exact word that covers it.

Comprehensible Input

I think it was Stephen Krashen who made the point that one effective strategy for language learning is to develope techniques for soliciting comprehensible input. For example, if you can ask for something you don't understand to be repeated, more slowly. Question statements by rephrasing. Provoke conversation.

With this in mind, make sure you take the time to learn phrases that allow you to respond when you don't understand, to ask for clarification.

Wednesday, July 22, 2009

No Critical Period?

http://www.gse.harvard.edu/news/features/snow10012002.html