Hot Stuff

With Donald Trump officially announcing the US withdrawal from the Paris Climate Agreement, I feel compelled to write a post about climate change. I do find it amusing that the earliest possible effective date of the US withdrawal is a day after the 2020 election, but Donald Trump (presumably) will be president until 20 January 2021.

Anyway, brass tacks.

Anthropogenic Global Warming Is Real

I know few who deny anymore that global warming is happening (people like this guy are obvious exceptions). The possibility was raised in 1824. Humans were producing, in 1896, as much CO2 as natural sources (e.g. volcanoes), but the same scientist who calculated this concluded that humans were, through the burning of coal, a major contributor to climate change, and in the global warming direction.

Numerous scientists began to postulate as to why the temperature of the globe seemed to be increasing, even early in the 20th century. Sunspot cycles were proposed in the 20s, but rejected by most scientists by the 30s. Milanković proposed changes in the Earth’s orbit, but these cycles were determined to be far too slow to be the major contributor to what was observed at the time.

I will note that it wasn’t until the late 50s that a majority of scientists in the field were concerned about potentially “radical” effects on the climate. While in 1968, some remained unsure whether moderate cooling effects of particulate pollution (smog) or the warming effects of CO2 emissions would dominate, a mere seven out of 51 articles published around that time predicted global cooling—the rest sided with the warming hypothesis.

1981 seems to mark the turning point where an overwhelming majority of scientists agreed with the idea that, not only was the globe warming, but that humans were the primary cause of that warming.

ExxonMobil has a nice list of documents and publications from the 70s and 80s indicating that they were/are aware of the warming impact of CO2 release. And here’s 104 more publications they contributed to. Every last one of them says increasing atmospheric carbon dioxide is causing global warming, and that humans burning fossil fuels are causing the increase in atmospheric carbon dioxide (to be fully honest, I have only read a few of these, but it gives me some confidence that I’m not entirely mischaracterizing the tenor of these papers).

I was going to make a nice long essay out of this, but I’ll just stick to saying this: It’s happening, people! Do something about it!

Word Crimes

Microsoft Word has many, many, many failings, but there are usually ways to tame it. Most of them require code. And, as is usual with writing computer programs or scripts, one piece of the puzzle is usually rather picky about one thing or another. In this case, it’s spelling, but I’ll give it a pass for that, and there are some simple workarounds which I’ll leave to the user to figure out.

Today’s conundrum: how to create a sequence, then programmatically create hyperlinked references to that sequence. Let’s pretend you want a sequence that progresses like this (and we’ll keep it simple for now):

  • Foo 00001
  • Foo 00002
  • Foo 00003
  • (etc)

Problem number 1 is creating this in the first place. If you aren’t familiar with the Sequence field code, this will be a basic primer.

In your document, press Ctrl+F9. You’ll see a pair of curly braces and your cursor will be in the middle. Note: you cannot type these curly braces! That won’t work! You must insert them with the Ctrl+F9 hotkey! Next, type  SEQ Bar \# "'Foo '00000"

You’ll see something like this:

{ SEQ Bar \# “‘Foo ‘00000” }

If you press Shift+F9, hopefully you’ll see your first number! We’re calling this sequence “Bar”. This is important—more important than the number formatting.

To get the next number in the sequence, there are a few options. The simplest is to copy this text and paste it elsewhere. When you do so, it’ll still say “Bob 00001”; just press F9 to update it, and it’ll refresh to the appropriate number. A second option is to use the Ctrl+F9 hotkey and retype that whole thing again. If you just use

{ SEQ Bar }

You’ll end up with “5” or whatever the sequence number happens to be at that point in the document.

But! We’re not to a programming stage. This is all well and good, and may be sufficient for many applications, but what happens when you want to reference Foo 00532 at some arbitrary location in the document? The standard answer is, create a Bookmark reference for each and every one of these Foo number sequences, each called, say, “Foo 00001”. This gets tedious really fast. When you’re creating hundreds of these, it’s not at all practical.

What you would like to be able to do, step one, is be able to insert a cross reference to this as a numbered item.

If you insert a cross reference (References tab, Captions group, Cross-reference button; Insert, Reference, Cross-reference… for Word versions prior to 2007), though, you won’t find Foo or Bar anywhere! This is a problem!

If you don’t want to do any coding, you can use the “Insert Caption” button (References tab, Caption group; or Insert, Reference, Caption… prior to 2007). In the dialog that appears, Click “New Label…” and enter “Bar”. Then click close. You don’t need to do anything more here. Now go to insert a cross reference (see previous paragraph), and, voila, “Bar” is in the Reference Type drop-down! And all sequence numbers are in the list below!

But we want to make this easy on everyone, so now we must turn to the blessing and bane of every Word expert’s existence: VBA. Step 1: add the caption label. This turns out to be simple:

And, also, nicely enough, if it already exists, it won’t nag you or call you nasty names. Though, if you want to do it right, you might use one of the following methods:

I prefer the first because it doesn’t rely on VBA’s terrible methods of handling errors.

Anyway, next step! How does one programmatically insert the next item in a sequence into the document? Again, it turns out to be fairly simple:

First, I “collapse” the selection to the beginning. This step is optional; if a bunch of text is selected before running this code, this forces the cursor to go to the beginning of that selection instead, so whatever text is selected doesn’t get overwritten. Second, note that in VBA, doubling up the quotation marks actually inserts them into the field. Third, we don’t have to enter “SEQ”, because wdFieldSequence  does that for us.

 

One last step, to make our macro suite complete. Cross references! But we don’t want to have to go through that whole rigamarole of References tab, Captions group, Cross-reference button every time, especially when the cross reference dialog contains hundreds of the things! Type it out! Type “Foo 00532”, highlight it, and run the following macro:

Be sure to update the appropriate sections (lines 6 and 8, specifically) when you create your named sequence.

I’m sure that this whole thing can be made more generic, but that’s not something I’m up to doing right now, so I’ll leave that as an exercise to the reader.

Some resources to help you out:

Also (and as a separate note), for those interested in making a custom ribbon, you’ll want a reference that shows you what the imageMso values actually look like, and since Microsoft isn’t nice enough to provide one, I finally found someone who is, here.

Box Set

In Python for now, eventually in VBA, I’m trying to come up with a way to test whether or not a particular quantity is appropriately specified with valid units and tolerances. It turns out to be slightly simpler to be (semi-)lenient than extremely strict, so here’s what I have so far:

This will handle quantities with symmetric and asymmetric tolerances are specified, as well as inequalities with units. It doesn’t enforce asymmetric tolerances (the numbers could, theoretically, be the same), and the separators are lazy for now.

The goal is actually to highlight non-conforming quantities so that they can be corrected. I suspect that will be more than a minor challenge.

mysql to mysqli conversion

If you used an older version of PHP and switched to PHP7, and now all your  msyql  commands are failing, you should be able to use the following to fix it. You’ll have to run it in every directory where you have php files, of course.

 

vim cheatsheet

As always, this is for my own reference, but hopefully it proves useful to someone out there!

All commands are listed as if they are typed from normal mode; commands that begin with “:” work in ex mode.

commanddescription
:wqsave and quit
:wsave
:qquit (unless there are unsaved changes)
:q!quit without saving
:wasave all
:xasave all and quit
:qaquit all (unless there are unsaved changes)
:qa!quit all without saving
:w {file.txt}save as {file.txt}
/searchfind "search" in current file
:%s/foo/bar/gfind all occurrences of "foo" (in current file) and replace with "bar"
:s/foo/bar/gIfind all occurrences of "foo" (in current line) and replace with "bar", case sensitive
:5,12s/foo/bar/gcfind all occurrences of "foo" (in lines 5-12) and replace with "bar", but ask for confirmation
:s/foo/bar/find first occurrence of "foo" (in current line) and replace with "bar"
:s/foo\c/bar/gfind all occurrences of "foo" (in current line) and replace with "bar", case insensitive
:s/foo\C/bar/gfind all occurrences of "foo" (in current line) and replace with "bar", case sensitive
:%s/Copyright \zs2009\ze J\. Classen/2017/gfind all occurrences of "Copyright 2009 J. Classen" (in current file) and replace only "2009" with "2017"
*find next occurrence of word under cursor
#find previous occurence of word under cursor
%find matching bracket to one under cursor
uundo
<C-R>redo
iinsert at current location
ainsert after current location
Iinsert at start of current line
Ainsert after end of current line
oinsert line below current line and enter insert mode
Oinsert line above current line and enter insert mode
sdelete current character and enter insert mode
Sdelete current line and enter insert mode
cwdelete current word and enter insert mode
ccdelete current line and enter insert mode
Cdelete from cursor to end of line and enter insert mode
.repeat previous operation made in normal mode
rxreplace current character with "x" (do not enter insert mode)
c3bchange previous three words
d4wdelete next four words
dddelete current line
yyyank current line
5dddelete five lines from cursor
5yyyank five lines from cursor
ggmove to first line
Gmove to last line
23Gmove to line 23
zzcenter line vertically in window
hmove left
lmove right
jmove down
kmove up
wmove one word forward
bmove one word backward
8hmove eight lines left
d3kdelete four lines up (three plus current line)
fxfind next "x" in line
Fxfind previous "x" in line
txfind next "x" in line
Txfind after next "x" in line
@:repeat previous operation made in ex mode
Jjoin next line to current line
Ycopy current line
ppaste after current line
Ppaste before current line
Vvisually select current line
v3wvisually select three words
:sp {file.txt}horizontal split with {file.txt}
:vs {file.txt}vertical split with {file.txt}
<C-W>ssplit horizontally (same file in both splits)
<C-W>vsplit vertically (same file in both splits)
<C-W>wswitch to next window
<C-W>Wswitch to previous window
<C-W>nnew window
<C-W>qclose current window
<C-W>oclose all other windows
<C-W>rrotate windows
<C-W>xswap windows
<C-W>Tmove window to new tab
<C-W><decrease window width
<C-W>>increase window width
<C-W>+increase window height
<C-W>-decrease window height
:drop {file.txt}edit {file.txt} in current window; if file is already open, switch to that window instead
:tab drop {file.txt}edit {file.txt} in new tab; if file is already open, switch to that window instead
:tabe {file.txt}edit {file.txt} in new tab
gtgo to next tab
gTgo to previous tab
:tab splitcopy current window to new tab
:tab ballshow all windows in own tab
:cd %:p:hchange to directory of currently open file
maset mark "a" to current line and column (lowercase letters are file-specific, uppercase letters are global)
'amove to line of mark "a"
`amove to line and column of mark "a"
`0jump to position in last file edited

Guelah Papyrus

If you plot

\(\Huge{\frac{1}{2}<\left\lfloor{{\rm mod}\left({\left\lfloor\frac{y}{17}\right\rfloor2^{-17\lfloor{x}\rfloor-\left({\rm mod}(\lfloor{y}\rfloor,17\right)}},2\right)}\right\rfloor}\),

you get

where

\(\LARGE{\begin{alignat}{1} k = 4\ & 858\ 450\ 636\ 189\ 713\ 423\ 582\ 095\ 962\ 494\ 202\\
& 044\ 581\ 400\ 587\ 983\ 244\ 549\ 483\ 093\ 085\ 061\\
& 934\ 704\ 708\ 809\ 928\ 450\ 644\ 769\ 865\ 524\ 364\\
& 849\ 997\ 247\ 024\ 915\ 119\ 110\ 411\ 605\ 739\ 177\\
& 407\ 856\ 919\ 754\ 326\ 571\ 855\ 442\ 057\ 210\ 445\\
& 735\ 883\ 681\ 829\ 823\ 754\ 139\ 634\ 338\ 225\ 199\\
& 452\ 191\ 651\ 284\ 348\ 332\ 905\ 131\ 193\ 199\ 953\\
& 502\ 413\ 758\ 765\ 239\ 264\ 874\ 613\ 394\ 906\ 870\\
& 130\ 562\ 295\ 813\ 219\ 481\ 113\ 685\ 339\ 535\ 565\\
& 290\ 850\ 023\ 875\ 092\ 856\ 892\ 694\ 555\ 974\ 281\\
& 546\ 386\ 510\ 730\ 049\ 106\ 723\ 058\ 933\ 586\ 052\\
& 544\ 096\ 664\ 351\ 265\ 349\ 363\ 643\ 957\ 125\ 565\\
& 695\ 936\ 815\ 184\ 334\ 857\ 605\ 266\ 940\ 161\ 251\\
& 266\ 951\ 421\ 550\ 539\ 554\ 519\ 153\ 785\ 457\ 525\\
& 756\ 590\ 740\ 540\ 157\ 929\ 001\ 765\ 967\ 965\ 480\\
& 064\ 427\ 829\ 131\ 488\ 548\ 259\ 914\ 721\ 248\ 506\\
& 352\ 686\ 630\ 476\ 300\end{alignat}}\)

Also,

\(\Huge{e\approx\left(1+9^{-4^{6\times7}}\right)^{3^{2^{85}}}}\)

It’s accurate to \(\LARGE{\left\lfloor\log_{10}\left(3^{2^{85}}\right)+1\right\rfloor=18\ 457\ 734\ 525\ 360\ 901\ 453\ 873\ 570}\) digits!

Lastly (though I have mentioned this before),

$$\Huge{\sum_{n=1}^{\infty}{n}=1+2+3+4+\cdots=-\frac{1}{12}}$$

as explained here and here and here.

Custard Pie

Happy π Day!

 

Statistics

So I don’t lose it, here it is again. In this guy’s communications class 10 or so years ago (don’t remember if it was Comm 1 or Comm 2), one of our homework problems was, essentially, to find a formula to calculate the probability of rolling a total \(\LARGE{t}\) on \(\LARGE{n}\) \(\LARGE{s}\)-sided dice. The homework wasn’t quite so generic, but I nearly had it back then. I’ve derived the formula a couple of times since, but I can’t reliably find it on the internets, so here it is:

$$\Huge{p(t)=\frac{\sum\limits_{k=0}^{\lfloor{\frac{t-n}{s}}\rfloor}(-1)^{k}{n \choose k}{{t-sk-1}\choose{n-1}}}{s^n}}$$

The more dice one has, the more this looks like a Gaussian distribution

$$\Huge{f(x\ |\ \mu,\sigma^2)={\frac{1}{\sqrt{2\sigma^2\pi}}}e^{-\frac{(x-\mu)^2}{2\sigma^2}}}$$

where

$$\Huge{\mu=\frac{n(s+1)}{2}}$$

and

$$\Huge{\sigma=\frac{1}{\sqrt{2\pi}p(\lfloor\mu\rfloor)}}$$

The tails are slightly flatter, so it might be some other “bell”-shaped PDF, but this is a good approximation.

Back Talk

Syntactically Awesome Style Sheets. Bootstrap 3.3.7 (latest as of this writing) uses Less and/or Sass, but it appears that Bootstrap 4 is switching to Sass exclusively.

Anyway, because of this transition, I decided to learn Sass. I found Emmet at the same time, but I won’t be covering that much here.

Installation

Installation was not as straightforward as I had expected. I initially was using a Sass framework, Compass, but that hasn’t been updated in more than two years. Unfortunately, uninstalling it broke what I was working on. Anyway, here’s what’s needed:

  • Ruby
  • RubyGems (normally after installing ruby you can run  gem update --system, but this doesn’t necessarily work on Windows)
  • Sass (run gem install sass)

Configuration

A lot of this will come down to personal preference, but configuration of Sass can be an important, or merely incidental, detail of your project. If possible, I don’t like passing options in at the command line, but Sass doesn’t have a way to use a SCSS document to define these either. To do so, you have to know a bit of Ruby, or at least be willing to create/edit a Ruby file.

This file is $RUBYDIR/lib/ruby/gems/$RUBYVERSION/gems/sass-$SASSVERSION/lib/sass/environment.rb  (replace with appropriate values). Under module Sass, I have no idea what one is supposed to do.

From the command line, though, you can use the following, at least for the options I prefer for development:

Getting Started

The thing I like to play with most is fonts, so I decided I’d create a _fonts.scss  file. The underscore at the beginning prevents it from being compiled by itself, but is unnecessary when importing. Let’s just start with its contents:

I’m fairly certain I can improve the @each  loop, but I was in a hurry.

Then, in my main.scss  file, the following:

All this results in a file main.css  that contains the following:

A few things are off about this. One, the font-family is the same for each of the headers, so defining the face for each of these is, well, silly. Also, the line height is based on $base-line-height, but should be scaled for each of the headers as well.

Here’s my updated _fonts.scss:

There’s a lot added here.

  1. I added some fonts I like from Google Fonts.
  2. Sass does math, but not powers, so I created @function intpower, as I wanted to scale my headings based on the level. (There may be a better way to do this).
  3. Sass documentation says that there is a distinction between to  and through  in the @for  construct, but doesn’t describe that difference. through  includes both endpoints, so if you’re expecting C/JavaScript/Python/etc.-like behavior, you need to use to  instead.
  4. Finally, the %my-headings  pseudoclass/pseudoselector and the @extend  keyword. This allows me to add the same options to each element I’m looping through, but will “compress” the CSS so the font-weight, font-family, and margin aren’t repeated in every element.

This results in the new CSS file:

The one thing Sass doesn’t do for me, and neither does Emmet (correctly), is the creation of vendor prefixes. There are mixins that can help with this, but there’s a lot of finickyness for each property, function, etc. Unfortunately, though it’s probably okay to dump support for dinosaurs like IE6, we still have to live with vendor prefixes. That will probably be the case for the foreseeable future, as each browser maker comes up with new feature ideas.

Lump

I rarely wax political. I did briefly in No Excuses, and I’ll do so again today. As some of you may know, I’m not exactly a conservative. According to a Pew Political Party Quiz, I’m about as far left as one can be.

partyquiz

So you can imagine based solely on that that I wasn’t exactly a Trump supporter. But he is our President-Elect, so come January 20, just 70 short days away, he’ll take the reins and steer our country whichever way his whims take him.

Back in September, Salena Zito said, “The press takes him literally, but not seriously; his supporters take him seriously, but not literally.” I now hope his supporters were correct to not take him literally, because if he’s able to push through 66ish percent of his campaign promises, or if he decides to embrace the Republican platform instead, there are a great many people who may not be very happy in four years (or less).

I started to put together an analysis of some campaign promises he made, a dissection of his plan for his first 100 days in office, and more, but I abandoned (and deleted) all that because I don’t have time. I started a more limited one, but gave up on that. So here are just a few thoughts.

Trump said in December 2015 that he would have a total and complete ban on all Muslims entering the country, whether they wish to immigrate or if they’re tourists. While this is patently unconstitutional, he can legally ban people from certain countries from entering the US. But one of the things that Makes America Great™ is that we welcome all. A poem, “The New Colossus” by Emma Lazarus engraved in bronze in the base of La Liberté éclairant le monde famously reads in part,

Give me your tired, your poor,
Your huddled masses yearning to breathe free,
The wretched refuse of your teeming shore.
Send these, the homeless, tempest-tost to me

Despite nearly four centuries of this portion of North America harboring refugees from persecution, be it religious or ethnic, Trump has decided that “Muslims” as a whole cannot be tolerated. Will Muslims that already live here be able to stay? Will those US Citizens who are Muslim be able to enter the country if they leave to visit family? Will those who “look Muslim” be able to cross the border? Yes, America does have a dirty history that includes racial discrimination for immigration, citizenship, internment camps, and slavery, but I thought we had moved past that 60 years ago. Apparently I was wrong.

Another consequence that seems likely is that ISIS/ISIL/Daesh will find it easier to recruit new members. The “Death to America” crowd will grow. If Muslims already present in the US find themselves even more oppressed than they already are (a few individuals are already taking Trump’s victory as validation and permission for racist behavior, vandalism, even violence), we’ll grow our own terrorists, no outside intervention required.

That’s just Muslims, which aren’t necessarily of one race or country of origin. He also set his sights on Mexicans. “When Mexico sends its people, they’re not sending their best. … They’re sending people that have lots of problems, and they’re bringing those problems with [them]. They’re bringing drugs. They’re bringing crime. They’re rapists.” I don’t know about you, but that sounds pretty racist to me. He wants to deport 11 million people in 2 years. That works out to more than 15000 a day, seven days a week. How he’s going to find these people, he hasn’t said. Imagine the National Guard, or some other “deportation force”, going door-to-door in your neighborhood, harassing and/or interrogating those who “look Mexican”. I know the Fourth Amendment has eroded nearly to the point of uselessness already, but when are we finally going to say, “That’s too far!”? This probably falls afoul of the Fifth Amendment, too. On top of that, he has his famous Wall. If actually built, would be an engineering and upkeep nightmare, but it at least would provide jobs for a while. Experts say it would cost upwards of $25 billion to build.

His Vice President is about as anti-LGBTQ as humanly possible, another old white guy who doesn’t understand female anatomy (probably went to the same school as I did, where you Just Don’t Talk About It) and wants to control it anyway. Those who do not conform to sexual or gender “norms” are still treated as second-class citizens in this country. Access to contraception and abortion, already controversial subjects, is frowned upon by the VP-Elect, and Trump does, in fact, have the power to define away contraception as part of basic women’s health coverage. So your birth control may not be safe come January. My health care costs are already increasing next year. Add the cost of another prescription to the pile (it was free under Obama), I guess…

He says global warming is a hoax perpetrated by the Chinese (another group he loves to villainize). Anthropogenic climate change is real. It’s happening. The average temperature of the world is going up, fast, and humans are doing it. Not volcanos. Cows are a problem, but it’s humans who have made them so. It’s mostly burning fossil fuels, though. What’s the hottest year on record? The hottest month? Probably this one.

He wants to dismantle the Environmental Protection Agency, Department of Energy, National Institutes of Health, and Department of Education. He wants the founder of Lucas Oil to be in charge of our National Parks.

All this is still speculation. We don’t know how his presidency will turn out. Capricious as he is, he may give ponies to everyone next year. I’d like to hope that he’ll magically become presidential, that he’ll encounter people who will stand up to him and explain how reality works, and, further, he’ll actually understand that. I’m not holding my breath.