Ruby Create Dictionary.html from double colon files

This takes a text file of the form below and creates an html dictionary version with a TOC :


Ambiguous Genitalia

Overview:: Four major defects can cause gender confusion in the neonate: 1) female pseudohermaphroditism or adrenogentital syndrome, 2) male pseudohermaphroditism, 3) true hermaphroditism, and 4) mixed gonadal dysgenesis. A physical examination and a chromosome analysis can make the correct diagnosis with approximately 90% accuracy. Gonadal symmetry is sought for - if there is symmetry in the gonadal findings, then the diagnosis is most likely a causative agent applied equally to both sides, such as an androgenized genetic female (=female pseudohermaphroditism) or an incompletely virilized genetic male (= male pseudohermaphroditism). Asymmetry refers to position of one gonad to the other, relative to the external inguinal ring. A buccal smear is felt by some to be useful in that Barr or Chromatin bodies (indicative of the presence of the second female X chromosome) may be found. Therefore: 1) Chromatin Positive, Symmetry = Fem pseudoherm; 2) Chromatin Positive, Asymmetry = True herm; 3) Chromatin Negative,Symmetry = Male pseudoherm; 5) Chromatin Negative, Asymmetry = Mixed gonad dysgen.

Caveats:: Genetic females recognized in the neonatal period historically were raised as female no matter how virilized. This is not currently the case. In genetic males the gender assignment was traditionally based on the phallus size - anyone with an 'inadequate' phallus is raised as a female. What constitutes an inadequate phallus ? Absolute values are impossible, but the measurements are made from the dorsum to the tip of the stretched glans. The following are 'inadequate': < 2.5 cm in the term infant; < 2.0 cm in the 34 week premie; < 1.5 cm in the 30 week preemie. Additionally, a thin (< 1 to 1.5 cm diameter) phallus is of concern. An elevated or normal MIS levels signifies a functioning testis.

Clinical:: The following work-up of the child with AG (ambiguous genitalia) may be indicated:H & P, HCG stimulation and enzyme ratios, Family pedigree, Genitogram, Maternal drug history, Cystoscopy, Buccal smear with Y fluorescence, Laparoscopy, Urinary steroids, Gonadal biopsy (longitudinal), Electrolytes,Androgen receptors (genital skin).

Female pseudohermaphroditism - Description:: (approximately 1/3 of all patients). This refers to 46, XX karyotype patients with severe masculinization secondary to exposure in utero to either endogenous or exogenous androgens.

Female pseudohermaphroditism - Etiology::The most common cause is the adrenogenital syndrome (CAH). CAH is the only cause of ambiguous genitalia that is life-threatening in the newborn period. 95% of these patients will have a 21-hydroxlyase deficiency. The gene for 21 hydroxylase has 2 alleles coded for in the Class II MHComplex, and there is therefore an A and B form of 21 OHase deficiency - the common form is the B variant. Mutations in the A genes result in milder, later onset forms of the disease. 21 hydroxylase deficiency results in aldosterone (mineralocorticoid) and cortisol (glucocorticoid) deficiencies, resulting in salt-wasting, hypotension, and adrenal crises. Other etiologies include 3 beta and 11 hydroxylase deficiencies. The 21, 3, and 11 are all forms of congenital adrenal hyperplasia (CAH). 11Beta OHase deficiency results in mild virilism (in affected females) and hypertension. In this variant, both mineralocorticoid and steroid replacement should be provided, since steroids alone may suppress the mineralocorticoid.

Female pseudohermaphroditism - Evaluation::The prenatal diagnosis of CAH can be made from DNA analysis of CVS (chorionic villous sampling) or amniotic fluid hormone levels during or after the 2nd trimester. The best way to test for CAH is to look for elevated precursors: {Deficiency,Elevated Precursor,Frequency} = [21 Hydroxylase; 17 hydroxyprogesterone; 95% cases] and [3BetaSteroid dehydrogenase; 17 hydroxypregnenolone: < 5% cases] and [11 Beta hydroxylase; 11 deoxycortisol; rare]. Clinically, prompt identification of patients with CAH is critical. Virilization is present in the female, and in the male only barely identifiable hyperpigmentation of the scrotum may be present. The history of an early or unexplained death in a sibling should alert one to the possibility. A filter-paper test for the most common defect (test is for 17 hydroxyprogesterone) is available. ECG findings of peaked T waves or arrhythmia's may be the first sign. Internal structures are normal, and only the external structures are affected (this is true because the adrenal develops after the 11th week of gestation when the internal structures are already formed). All genetically female patients have the potential to be fertile and should be raised as females. The phenotype is variable from very male appearing to milder forms. The life-threatening electrolyte abnormalities (hyperkalemia, hyponatremia) may not occur until 3 - 5 days after birth, and the adrenal crisis may not occur until 1-2 weeks of age.

Female pseudohermaphroditism - Treatment:: Can even be preventative, if CAH is identified prenatally - dexamethasone is given (1 - 1.5 mg, daily in 2 divided doses) to the mother, starting at the 6 - 7th week of gestation (before sexual differentiation). CVS is used to assess therapy - if the fetus is genetically male, Tx is stopped, if the fetus is female, Tx is continued until amniocentesis during 2nd trimester to confirm the Dx. Fetoscopy has been used to evaluate the external genitalia. Medical management of CAH consists of provision of glucocorticoid (hydrocortisone, 12.5 -15 mg/M2 q 8 hrs, provision of mineralocorticoid (Fludrocortisone 0.1mg q am), hydration, correction of Na, K+ abnormalities. All patients with female pseudohermaphroditism should be raised as females. Surgically, clitoral recession is done in the early neonatal period, and a cutback or flap vaginoplasty is usually done at 3 - 6 months of age. A pull-through vaginoplasty is usually delayed until about 2 years of age. Which of these is required depends on the level of entry of the vagina into the urogenital sinus.

Male Pseudohermaphroditism - General:: Accounts for approximately 1/3 of all patients. These patients have a 46 X,Y karyotype but deficient masculinization of the external genitalia. The effects of androgens on sexual differentiation are via receptors in the nucleus.

etc.......

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
p "Enter a title"
title  = gets.chomp
dict = {}
IO.foreach(title + ".txt") do
|x| 
if
y = /::/.match(x)
y = y.pre_match
z=/::/.match(x)
z = z.post_match
dict[y] = z
end
end
File::open(title + '.htm', 'w') do |f|
	f.puts "<HTML>\n<link href='Level3_3.css' rel='stylesheet' type='text/css'><HEAD><TITLE>" + title + "</TITLE></HEAD>"
	f.puts "<CENTER><A NAME=\"page_top\"><H1>" + title + "</H1></A>"	
  	f.puts "by Charles L. Snyder, MD<BR>\n"
	f.puts "</CENTER>\n<HR>\n"
	dict.keys.sort.each {|s| f.puts "<br>#{s}</br>"}
	f.puts "</CENTER>\n<HR>\n"
  i=0
  while i < (dict.length)
  f.puts "<A NAME=\"$anchor\"><H2>" + dict.keys.sort[i] + "</H2></A>" + dict.values[i] + "<BR>"
	f.puts "<CENTER><A HREF=\'javascript:window.history.back()\'>Back</A>&nbsp"
  f.puts "</CENTER>\n<HR>\n"
  i = i + 1
  end
end

Python Google Stock Quotes

import urllib
import re

def get_quote(symbol):
    base_url = 'http://finance.google.com/finance?q='
    content = urllib.urlopen(base_url + symbol).read()
    m = re.search('class="pr".*?>(.*?)<', content)
    if m:
        quote = m.group(1)
        print symbol + "   " + quote
    else:
        quote = 'no quote available for: ' + symbol
    return quote

items = ["AAPL","GOOG","ININ","EWH","IAU"]
for n in items:
    get_quote(n)
raw_input( )

Linux: Concatenate Files

How to join multiple .avi or .mpg files
This will most likely work on just about any linux distro that includes the ability to install mplayer/mencoder. First, let’s get the right programs.

sudo apt-get install mencoder mplayer

Now that the hard part is out of the way, we’re going to make use of the wonderful cat command. I’d renamed each Bloodspell video as b1.avi – b7.avi. Now to string them all end to end.

cat b1.avi b2.avi b3.avi b4.avi b5.avi b6.avi b7.avi > bloodspell.avi

Now we’re 2/3 of the way there! Stringing together .avi files can cause a breakdown in the sync between video and sound. So, we’ll use mencoder to sort things out.

mencoder -forceidx -oac copy -ovc copy bloodspell.avi.avi -o bloodspell_final.avi

Emacs: Writing a Macro

To start defining a macro, press F3 or C-x (.[2] The abbreviation Def appears on the mode line, showing that you are in macro definition mode. In this mode, Emacs records all the keystrokes that you type, whether they are commands or literal text, so that you can replay them later. To end the macro, press F4 or C-x ); you leave macro definition mode, and Emacs stops recording your keystrokes. Emacs also stops recording your keystrokes automatically if an error occurs or if you press C-g.

[2] Mac OS X users may have bound F3 and F4, used in defining and executing macros, to another key. These users should press Option-F3 and Option-F4 to get the same functionality.

While you’re defining a macro, Emacs acts on your keystrokes as well as recording them: that is, anything you type while in macro definition mode is treated as a regular command and executed. While you’re defining a macro, you’re doing completely normal editing. That way you can see that the macro does exactly what you want it to, and you can cancel it (with C-g) if you notice that the macro isn’t really quite what you want.

To execute your macro, press F4 or C-x e. Emacs then replays your keystrokes exactly. (You can see that F4 has two different functions relating to macros: to end a macro definition and, after it’s defined, to execute the macro.)

This macro is referred to as the “last” keyboard macro, with last here meaning most recent. Only one macro is the last keyboard macro. A macro ring, much like the kill ring, allows you to access a number of macros during an Emacs session.

Table 6-1 shows the steps required to define and execute a macro. This macro takes a list of names in the ordinary First Name Last Name order and changes it to the frequently needed Last Name, First Name order.

Keystrokes Action
F3 or C-x ( Start the macro; Def appears on the mode line.
C-a Move to the beginning of the current line.
M-f Move forward a word.
, Type a comma.
M-t Transpose first and last.
C-n Move to the next line.
F4 or C-x ) End the macro definition.

Emacs: Interact with User

Q: In emacs, how can one get input from the user after a prompt? (modified from Xah Lee site)
A: “Interactive” turns a function into a command:

1
2
3
4
5
6
(defun irc-join (chan) 
  "join an IRC channel" 
  (interactive "sChannel to join: ") 
  (save-excursion 
    (setq irc-channel chan) 
    (irc-send-server (concat "JOIN " chan))))

Define a function via ‘defun’. ‘irc-join’, is the name
of the function. ‘chan’ is a local variable / parameter. Next is the description.
The string: “sChannel to join: ” –> The first character ‘s’ specifies
a string as the first variable of the parameter
list. The character ‘s’ means “string”. If you
wanted more parameters, it would be something like:

1
2
3
(defun function-name (stringparam numberparam) 
  (interactive "sPrompt here: \nnAnother prompt: ") 
        etc...

Note that each prompt string is separated by a newline character “\n”.
Also, ‘n’ means you want to get a number from the user.