24 January 2014

cr

slightly more complex friendly command-line tester. put in ~/bin, then PATH=~/bin:$PATH.

(Using this a lot right now because I'm at a programming camp on a guest account of an Ubuntu box that reboots afresh every day)

[[vim stash]]
#!/bin/bash
if [[ $# < 1 ]]; then
    echo "cr: args pl0x" >&2
    exit 1
fi
if g++ $1.cpp -O2 -Wall -o $1; then
    echo "cr: compile OK" >&2
    if [[ $# > 1 ]]; then
        ./$1 < $1-$2.in
    else
        ./$1 < /dev/stdin
    fi
fi

12 December 2013

Paper Size

1in = 2.54cm

A4= 21.0cm × 29.7cm= 8.27in × 11.69in
A4 − 1in margins= 15.92cm × 24.62cm= 6.27in × 9.69in
Letter= 21.59cm × 27.94cm= 8.5in × 11in

06 October 2013

Parameters and Arguments

Parameters are the things when you define the function. Arguments are the things when you call the function.

int f(int x) { return x + 1; } // x is parameter
int main() { cout << f(2 + 3); } // 2 + 3 is argument
Terrible mnemonic:
  • Parameters have parallel structure --- just [type name] [var name] or some variant thereof, nothing fancy.
  • Arguments can include arithmetic operations, or any other kind of operations.
  • Parameters are part of the function definition.
  • Arguments are what actually arrive inside the function.

The only reason I'm remembering this is to be technically correct ("the best kind of correct!")

11 September 2013

qNSOrfkVpr

tinyurl is not dependable :-/


http://share.xmarks.com/folder/bookmarks

26 August 2013

GIMP modes

http://docs.gimp.org/2.8/en/gimp-concepts-layer-modes.html
M = mask (top), I = image (bottom)
  • normal: E = M
  • dissolve: E = M or I, randomly picked per pixel
  • multiply: E = M × I / 255
    • darker
  • divide: E = I × (256 / (M+1))
    • brighter, brightens dark M parts strongly
  • screen: E = 255 − (255 − M)(255 − I)/255
    • brighter, equiv. "multiply" conjugated by inversion
  • dodge: E = I × (256 / (256−M))
    • brighter, brightens bright M parts strongly; equivalent to divide with inverted mask
  • burn: E = 255 − (255 − I) × (256 / (M+1))
    • darker, darkens dark M parts strongly
  • hard light: super complicated
    • for M in [0,128] it's multiply with 2M; for larger M it's all conjugated with inversion
  • soft light: also complicated, I somehow doubt the documentation...
  • grain extract: E = I − M + 128
  • grain merge: E = I + M − 128
  • difference: E = |I − M|
  • addition: E = M + I
  • subtraction: E = I − M
  • darken: E = min
  • lighten: E = max
  • hue, saturation, brightness, value: takes that component from M and others from I

Bx

+0.25: ε → 1 → 8 → 13 → 20 → 35
+0.5: 35 → 55 → 85 → 125
+1.5: 125 → 200
+1: 200 → 250 → 300 → 350 → 400 → 450

01 June 2013

chem

R = 0.082 L⋅atm / mol⋅K

at STP (0°C, 1 atm): 22.4 L / mol

H  =   1.008

C  =  12.011
N  =  14.007
O  =  15.999
F  =  18.998

Na =  22.990
Mg =  24.305
P  =  30.974
S  =  32.06
Cl =  35.45

K  =  39.098
Ca =  40.078
Br =  79.904
I  = 126.904

22 November 2012

Frequency




Output will go here

23 October 2012

Shift

Wonderful. Random javascript. Note I added //<!-- and //--> to get Blogger to stop escaping those pesky less-than and greater-than signs.






(A ↔ Z, B ↔ Y...)

Output will go here

21 October 2012

Functional Groups

Ok so I made this and then left it somewhere. Hmm.

Functional group
Molecule name


Hydroxyl             -O-H
HO
Alcohol

Carbonyl                H
CO                     /
(Aldehyde)           -C
                       \
                        O

                      (O)
                      | |
(Ketone)             -(C)-

                         O       O
Carboxyl               //      //
COOH                 -C      -C       (ionized)
Carboxylic acid        \       \
                        O-H     O+

                        H      H
Amino                  /       |
NH_3                 -N      -(N+)-H  (ionized)
Amine                  \       |
                        H      H

Sulfhydryl
SH2                  -S-H
Thiol

                         O
Phosphate               ||
O_3P                 -O-P-(O-)
Organic phosphate       |
                       (O-)

More Vim Stash

"System-wide gvimrc":
set backspace=indent,eol,start
syntax on
Basic:

S 'sc'
  'smd'
S 'hls'
  'is'
C 'ic'
  'scs'
L 'list'
  'lcs'
I 'ai'
  'bs'

N 'nu'
  'ru'
T 'ts'
  'sw'
  

  'lbr'
  'so'

set showcmd
set showmode
set hlsearch
set incsearch
set ignorecase
set smartcase
set list
set listchars=tab:›\ ,trail:·,extends:▶,precedes:◀
set autoindent
set backspace=indent,eol,start
filetype plugin indent on
set number
set ruler
set tabstop=4
set shiftwidth=4

color torte
set linebreak " note: canceled by list
set scrolloff=2

Core insert commands: ^H deletes character (backwards), ^W deletes word (backwards), ^O lets you do one normal command.
^C will also get you out of insert mode, just without abbreviations. Wow, I should try using abbreviations.

Switch to directory of currently edited file
command Cwd cd %:p:h

Occasionally useful
function Hex(n)
 return printf("%x", n)
endfunction

function Bin(n)
 if a:n == 0
  return "0"
 elseif a:n == 1
  return "1"
 else
  return Bin(a:n/2) . (a:n%2)
endfunction

11 May 2012

Notes on Die Kutschfahrt zur Teufelsburg

Darn, I lost the instruction book and the only way I can find the rules (for the classic version, not the translated and modified Castle of the Devil) online, apparently, is by translating the Portuguese translation on their website back into English.

Random corner cases so I do not have to do this again:
  • A Secret Bag cannot be traded for a Secret Bag. (But I knew that already)
  • The person who declares victory needs at least one of the keys or goblets that his association wins with. (I have a feeling our group is just going to ignore this)
  • All players who the person names in declaring victory need at least one of the keys or goblets as well. (Ditto)
  • The card limit is 8 cards for 3 players, 6 cards for 4 players, 5 cards for more. When somebody has more cards than the limit (not equal), he must give a card to a player whose cards haven't reached the limit. (This is an amendment on the official website because otherwise two players could swap all their cards.)
  • If the Diplomat succeeds in forcing a trade, he can still have his normal turn action. If he fails, his turn ends. This trade does activate special abilities of objects.
  • The Doctor must be the attacker or defender to use his ability.
  • The Priest must not be the attacker or defender to use his ability. (Possible glitch of translation because it says "did not must")
  • The Hypnotist has to use his ability after declarations and before special objects.

23 March 2012

Floating-point

Single-precision: sign 1b, exponent 8b, fraction 23+1b implied (= 6 ~ 9 decimal sigfigs)
Double-precision: sign 1b, exponent 11b, fraction 52+1b implied (= 15 ~ 17 decimal sigfigs)

Special cases:
  • Exponent = 0
    • fraction = 0: (+/-) zero
    • fraction != 0: "subnormal" number with implied bit set to 0 instead
  • Exponent = (FF or 3FF, maximum value in allocated bits)
    • fraction = 0: (+/-) infinity
    • fraction != 0: NaN (sign ignored)
      • top explicit fraction bit = 1: "quiet NaN"
      • top explicit fraction bit = 0 (and rest != 0): "signaling NaN"

18 March 2012

Cross-Platform Regular Expressions

There used to be a lot of blathering about regexes but I think nobody would read them anyway and I want a reference. Also it's incomplete and there is no logic whatsoever to which parts I chose. This is why I wanted colorful code tags.

The patterns in this post are the regex string, which may need to be escaped further in code. Perl's regexes are the base of many other ones, but tiny differences abound.
References: perlre; java.util.Pattern; Python re; vimdoc *pattern*;
As expected, normal alphanumeric characters are regexes that match themselves and only themselves.
^ matches start of string.
$ matches end of string.
. matches any character except newline.
| matchers the OR of two regexes (Vim: requires escaping as \|.)
(pattern) groups a regex (Vim: requires escaping as \(pattern\).)
[chars] matches any of a set of characters, e.g. c or h or a or r or s.

Quantifiers

hee hee, h3 tags
Quantifiers (Vim calles them "multis") take the previous piece of regex and allow it to match repeatedly some number of times (possibly none).

*: 0 or more
+: 1 or more
?: 0 or 1
{5}: 5
{5,}: 5 or more
{5,10}: 5 to 10 inclusive
Python: {,10} is allowed (not in perl!)
Vim: \+, \?, and \{ must be escaped for the above meaning (under normal 'magic' setting). You can escape or not escape the }. \= is a synonym for \?, as a second question mark would delimit the offset in backward search. \{} or \{,5} is allowed.
They are tightly bounding, so 42+ matches strings like 42222, not 42424242.

The above quantifiers are greedy; they try to match as much as possible. At the end of any of them, add an extra ? and it becomes reluctant (Java tutorial term), trying to match as little as possible. Alternatively, adding a + makes the quantifier possessive; it matches everything it can and no less, even if it takes up something the rest of the pattern might need.
Python, Vim: no possessives.
Vim: No adding ?s. Instead only bracket quantifiers can be made reluctant, by adding a dash, like \{-5,10}.

Character Classes

As we've seen [aeiou] matches one of the characters between the square brackets. Then there are a variety of commonly-occurring character-sets that people want to match. Some very common ones:
\w = "word" character (alphanumeric, underscore)
\d = digit
\s = whitespace (space, tab, newlines)
\h = horizontal whitespace
Each can be capitalized to match any character not in the class instead. Note that they might include foreign Unicode characters with the same properties; check your language.

Weird Stuff

X is a regex.
(?#X): nothing, merely a comment (not in Java)
(?:X): X, non-capturing
(?=X): X, via zero-width positive lookahead
(?!X): X, via zero-width negative lookahead
(?<=X): X, via zero-width positive lookbehind
(?<!X): X, via zero-width negative lookbehind
(?>X): X, as an independent, non-capturing group

As should be expected Vim has different notation for every single one of these:
\%(X\): X, non-capturing
For other assertions, put one of \@=, \@!, \@<=, \@<!, \@> after a regex, probably a group.

Explanation: Zero-widths match a null substring, but only if the part after/before that null substring matches/does not match the pattern.

Independent group: It will look for the "first" way this pattern matches and only match that. Same idea as possessive quantifiers.

Here's a Vim string for a standalone URL from the random rst syntax I'm staring at. Admire.
"\<\%(\%(\%(https\=\|file\|ftp\|gopher\)://\|\%(mailto\|news\):\)[^[:space:]'\"<>]\+\|www[[:alnum:]_-]*\.[[:alnum:]_-]\+\.[^[:space:]'\"<>]\+\)[[:alnum:]/]"


A weak Vim substitute command for detecting raw ampersands in XML, for some reason.
:%s/&\(amp;\|gt;\|lt;\|quot;\|#\)\@!/\&/gc

Also. Infamous RFC regex

17 March 2012

Chapter 23

I happen to feel like this is a good way to, I don't know, let off steam and deal with reality. It's probably just me.
1
  • (dermal tissue)
  • (vascular tissue)
  • (ground tissue)
  • epidermal cell
  • (trichome)
  • (xylem) [nonlinear syllabus; from Chapter 22]
  • (tracheid) [ditto] 
  • (phloem) [ditto]
  • vessel element
  • sieve tube element
  • companion cell
  • parenchyma
  • collenchyma
  • sclerenchyma
  • meristem
  • meristematic tissue
  • apical meristem
  • differentiation
2
  • taproot
  • fibrous root
  • (epidermis)
  • root hair
  • cortex
  • endodermis
  • vascular cylinder
  • root cap
  • Casparian strip
3
  • node
  • internode
  • bud
  • vascular bundle
  • pith
  • primary growth
  • secondary growth
  • vascular cambium
  • cork cambium
  • heartwood
  • sapwood
  • bark
4
  • blade
  • petiole
  • mesophyll
  • palisade mesophyll
  • spongy mesophyll
  • stoma
  • guard cell
  • transpiration
5
  • adhesion
  • capillary action
  • pressure-flow hypothesis
  • (transpirational pull)

04 March 2012

Accent Marks

cliché
déjà vu
doppelgänger
naïve
Pokémon
touché


Of course substituting the unmarked letters will annoy only the grammar Nazis among us, but...

24 February 2012

Current Events News Sources

Wait, why am I posting here again!?!?

I really hate it when I find blogs that say "this blog has moved to some other place" and a bunch of dead content. On the other hand I don't want to just delete this subdomain (just in case), and I like having colored <code> tags for when they're needed a lot. Therefore I will now start stashing random things like reference material or code snippets here. Unsubscribing might be a good idea.

Today's reference doesn't have <code> tags, however. I hope nobody thinks this is a link farm.

A.
B.
C.
D.


27 December 2011

Freedom Writers

This post used to contain a link to the IBSH Freedom Writers contest website, http://freedomwriters.ibsh.co.cc/, which is now dead.

The link was impossible to find on a search engine... aside from the complete absence of links from the school website, the fake domain .co.cc was flagged for lots of spam by Google and Avira. So people kept ending up on this blog post instead.

Most originally, this blog post contained reviews of stories from there, but they were pointlessly critical and the link is dead anyway. As is this blog.