Table of Contents

Linux

Raspberry Pi

Debugging Tips

Common Programs



Git and GitHub

Quick Tips


Overview

A repository, often called a repo, is a directory of files. Every directory under source conntrol is a complete independant repository, and can function even without network access.

The basic structures are:

When sharing work with other users, there is no special "central" repository. All repositories are equal in the eyes of git. Instead of checking an updated file into a source control central server, with Git you push or pull commits from one repository to another. In practice, one repository may be treated specially, like a central master, but that is outside of git. Different organizations may use different policies for identifying or protecting different special repositories.

GitHub is a web-based server where people can exchange and share a source tree. You can push your local repository to the server, and you can pull repositories from the server to your local repository. It also lets people chat and read each other's source code and many other functions like bug reporting and tracking. You do not need GitHub to use Git, but you do use git to interact with GitHub. Git does everything on the local computer, and GitHub is a web service that allows sharing between different git users. Git can also work with other similar services.

To start with Github, Login to GitHub at https://github.com and create a Free account.
WARNING! Use the same email you used for the local repository!

The git cheat sheet (in English) https://training.github.com/downloads/github-git-cheat-sheet.pdf

Some handy tutorials

Software Installation

Managing repositories

Each directory of source code is a separate repository.

Modifying and Committing Files

The states of a file are: Tracked ---> Modified ---> Staged ---> Committed/Tracked
A key idea in git is that changes are not stored as diffs, but rather as stand-alone snapshots.

If you are only working on a local storage (no GitHub or BitBucket or other remote store) then you are done. Your changes are saved. If you delete the working copy of the file, then do a "git reset --hard HEAD" the file will be restored.

If you want to use GitHub, then you ALSO need to do the next steps.

First, make a branch. In git, a branch is a reference to a commit. This becomes important when you have several commits in a directory, each with different set of snapshots of files. You use branch names to reference each commit. In practice, this means you specify a branch name to the command that changes the current working environment to reference a particlar commit.

Now, push a branch to Github git push origin my-new-branch Here, "origin" is just a special keyword that means the remote URL associated with this repository Or, you can try this, but I have to enter SSH public key passcodes which takes extra configuration. git push [email protected]:git/git.git yourbranchname

Now you can log into GitHub and create a pull request, examine the diff, and merge it into the main branch.

Getting Updates

In a directory that is a clone of a repository on GitHub
git pull origin master

To discard all local changes and replace the directory with the remote repository
git reset --hard HEAD git pull

To restore the state of a file from your local repository
git checkout However, if you deleted a file, then you will have to name it to restore it from the local repository.
git checkout myFileName

Status Commands

To see what has changed but not been committed in the working directory
git status

To see which branch you are currently working on
git branch

To see what remote repository
git remote -v

To see what has been changed and committed in the past:
git log

To see what changes are changed but not yet staged. Shows the differences between the working directory and the index. Note, if all changes are staged but not yet committed then "git diff" will show nothing.
git diff
git diff [fileName]
git diff [tag name]

The changes are in the current staged commit. These files have been added to the index and staged for a commit. These are the changes between the index and the HEAD (which is the last commit on this branch).
git diff --staged

Shows the changes between the index and the HEAD (which is the last commit on this branch).
git diff --cached

Shows all the changes between the working directory and HEAD (which includes changes in the index). This shows all the changes since the last commit, whether or not they have been staged for commit or not.
git diff HEAD

Delete/Undo Changes




Linux Commands



Microsoft Excel

Making a Cell whose value is defined by an expression

Select the cell, and type the expression in the fx (function) text box. Start the string with "=" to tell Excel that this is a formula and not a string value.

Example:
=(L2 / (K2 + L2)) * 100

The parameters refer to cells. These take the form of where is a letter and is a number. A "$" symbol in front of either the column or letter means it is absolute address, which is independent of the location of the cell making the reference. No "$" means that this address is relative to the cell making the reference. This can have several combinations:

Type Description Example
Absolute A specific cell independent of location of the referencing cell $A$1
Absolute Column, Relative Row A cell in a specific column, and in a row relative to the referencing cell $A1
Absolute Row, Relative Column A cell in a specific row, and in a column relative to the referencing cell A$1
Relative A cell in a relative row and column to the referencing cell A1

Once you have a cell with a formula, you can select it and drag the outline to fill a column or row. This will put that expression in every cell in the region. Assuming that hte formula uses relative cell references, this means every cell will have a value dependent on relative cells in its own row or column.

NOTE: The first cell uses relative addresses with specific constant names, like "A3" and so on. When you copy this to other cells, Excel will first convert the specific names (like "A3") to relative positions (like, one column to the left and two rows up) and then put the appropriate relative positions in each new cell. So, you define the pattern with a specific example and then Excel generalizes this and makes new specific constants for each new cell.

Besides algebraic expressions, there are a few built-in functions that are handy.


Creating a series of auto-fill data in rows or columns
  1. Click a cell, which should show a dark frame around the cell, with a box in the lower right corner. Select the box, and drag it to expand the region to a row or column or block of cells.
  2. Select the "Home" tab, then click the "Fill" combo box, then select the "Series..." item. This lets you control how data is filled in the selected region.

Counting the Number of rows that Meet a Condition

=CountIf(range, criteria)
where

Some examples

Some extensions




A few personal things for installing and configuring Linux

This is just my personal To-Do list for installine a new Fedora machine. This will probably not be useful to anyone else. This is also Fedora-specific, so will also differ from other distros.




Connecting to Synology NAS

A few common steps that I follow when managing disks on Synology NAS. Note - this is Fedora specific but may be close to what you would do on another distro.




Installing and configuring WSGI on Apache

A few common steps that I follow when running WSGI on Apache. This is *not* a stand-alone server, but rather adds WSGI as a backend for Apache. Note - this is Fedora specific but may be close to what you would do on another distro.

Some useful docs are at: https://modwsgi.readthedocs.io/en/master/user-guides/quick-configuration-guide.html




Installing and configuring Linux Disks and Samba File Server

A few common steps that I follow when managing disks and Samba on Fedora. Note - this is Fedora specific but may be close to what you would do on another distro.

Block Access to the SMB Ports from outside the router

See https://kb.netgear.com/8219/How-to-setup-Inbound-Outbound-firewall-rules-on-NETGEAR-Modem-router-gateways. This will block Internet access to the device but it will be accessible on the LAN to others.


Installing and configuring Emacs

A few common shortcuts that I personally prefer. The blessing/curse of emacs is that it is so customizable, everyone ends up with a slightly different solution. These are what I have come up with so far, but I am also still trying to tweak it to make it more to my liking. Still, you may not like these design choices.

When testing a .emacs file, you can always use "M-x load-file" and then enter the file name. This will reload the config file without quitting and restarting the program.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Emacs Customization
;; Tips and tricks from many sources, collected by Dawson Dean
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Font Size and Type
;;
;; The height is 1/100th of a point, so 100 is a 10pt font.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set-default-font "DejaVu Sans Mono")
(set-face-attribute 'default nil :height 100)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Text Colors
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set-face-foreground 'font-lock-string-face "black")
(set-face-foreground 'font-lock-comment-face "dark green")
(set-face-foreground 'font-lock-comment-delimiter-face "dark green")
(set-face-foreground 'font-lock-function-name-face "black")
(set-face-foreground 'font-lock-variable-name-face "black")
(set-face-foreground 'font-lock-keyword-face "dark blue")
(set-face-foreground 'font-lock-type-face "black")
(set-face-foreground 'font-lock-constant-face "black")
(set-face-foreground 'font-lock-builtin-face "black")
(set-face-foreground 'font-lock-preprocessor-face "black")

;; The color of the mark region
(set-face-attribute 'region nil :background "#BFEFFF")
;; Blue:    0000FF
;; Orange:  FFA000


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Custom Key Bindings
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Ctrl-Z is undo.
(global-set-key (kbd "C-z") 'undo)
(global-set-key (kbd "C-Z") 'undo)

;; Ctrl-/ will goto-line
;; This is totally unique to me, nobody else agrees on this. Lots of people
;; seem to like "Esc-g g" but that's still too many keystrokes for me.
(define-key global-map (kbd "C-/") 'goto-line)

;; I sometimes have the Control key held down while doing other things.
(define-key global-map (kbd "") (kbd ""))
(define-key global-map (kbd "") [Double-Mouse-1])


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Basic Editing
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Shift-click will extend the mark region
(define-key global-map (kbd "") 'mouse-save-then-kill)

;; Typing will replace the currently selected text.
(delete-selection-mode 1)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Syntax Table Hacking
;; http://www.emacswiki.org/emacs/EmacsSyntaxTable
;;
;; Word operations will not treat "_" as a word-break in C++. This puts
;; the character "_" (which is quoted with ? so it is ?_) in the "word"
;; class of characters (which is identified by "w").
;; Really, we just want to evaluate this:  (modify-syntax-entry ?_ "w")
;; But we add a hook so our customization is not clobbered every time
;; the symbol table is edited.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(add-hook 'text-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'c-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'c++-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'html-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'xml-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'java-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'js-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'js2-mode-hook (lambda () (modify-syntax-entry ?_ "w")))
(add-hook 'abbrev-mode-hook (lambda () (modify-syntax-entry ?_ "w")))



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Select the entire buffer
;; This was copied (with some small changes) from:
;; https://www.gnu.org/software/emacs/manual/html_node/eintr/mark_002dwhole_002dbuffer.html
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(defun mark-whole-buffer()
       "Select the entire buffer"
       (interactive)
       (message "mark-whole-buffer!")
        ;; Put point at beginning 
       (push-mark (point))
        ;; Put the mark at end of buffer.
       (push-mark (point-max) nil t)
       (goto-char (point-min))
) ;; defun
(global-set-key (kbd "C-S-A") 'mark-whole-buffer)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; CUA Mode
;;
;; This makes Ctl-x cut, Ctl-v paste, and Ctl-C copy.
;; This is what you use in Web browsers, so it makes sense for all applications to
;; share a common convention.
;; http://www.emacswiki.org/emacs/CuaMode
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(cua-mode t)
(transient-mark-mode 1) ;; Default in Emacs 23 and later. Selected region is only active when highlighted
;;(setq cua-auto-tabify-rectangles nil) ;; Don't tabify after rectangle commands
;;(setq cua-keep-region-after-copy t) ;; Standard Windows behaviour



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Searching: Find, Find-And-Replace, Grep 
;;
;; As I switched back to emacs after years on Microsoft's Visual Studio, I realized
;; that I use search to navigate around a buffer more than Ctl-V and Esc-V or similar
;; things. Here are some functions to find the next and previous instance of the
;; currently selected text.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Find the next instance of the selected text
(defun forward-search-selection (beg end)
    "Search for the current selection"
    ;; This tells elisp to call this command with the point and mark
    ;; as arguments parameters bound to beg and end
    (interactive "r")

    ;; Save the current selection to a local variable.
    ;; We want to deactivate the mark, so save a private copy first.
    (let (
          (selection (buffer-substring-no-properties beg end))
         )
        ;;(message "selection:%s" selection)
    
        ;; De-activate the current mark region. We will change the mark later
        (deactivate-mark)

        ;; Find the next instance of the string.
        ;; https://www.gnu.org/software/emacs/manual/html_node/eintr/search_002dforward.html#search_002dforward
        ;; search-forward takes 4 arguments:
        ;;      The search pattern
        ;;      Optional - limit of search. nil means end of buffer
        ;;      Optional - how to handle failed search. nil means print a message.
        ;;                   t means return a result
        ;;      Optional - How many instances to find
        (when (search-forward selection nil t)
            ;; If search-forward returned true, then it found a match.
            ;; Select the match. This is nice for user feedback but it also
            ;; lets another search-forward find the next occurrence.
            (setf
                (mark) (match-beginning 0)
                (point) (match-end 0))
        ) ;; when
    ) ;; let
) ;; forward-search-selection
(define-key global-map (kbd "") 'forward-search-selection)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Find the previous instance of the selected text
(defun reverse-search-selection (beg end)
    "Search for the current selection"
    ;; This tells elisp to call this command with the point and mark
    ;; as arguments parameters bound to beg and end
    (interactive "r")

    ;; Save the current selection to a local variable.
    ;; We want to deactivate the mark, so save a private copy first.
    (let (
          (selection (buffer-substring-no-properties beg end))
         )
      
        ;; De-activate the current mark region. We will change the mark later
        (deactivate-mark)

        ;; Find the prev instance of the string.
        ;; This works like search-forward except it runs in reverse
        ;; search-backward takes 4 arguments:
        ;;      The search pattern
        ;;      Optional - limit of search. nil means end of buffer
        ;;      Optional - how to handle failed search. nil means print a message.
        ;;                   t means return a result
        ;;      Optional - How many instances to find
        
        (when (search-backward selection nil t)
            ;; If search-forward returned true, then it found a match.
            ;; Select the match. This is nice for user feedback but it also
            ;; lets another search-forward find the next occurrence.
            (setf
                (mark) (match-end 0)
                (point) (match-beginning 0))
        ) ;; when
    ) ;; let
) ;; reverse-search-selection
(define-key global-map (kbd "") 'reverse-search-selection)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Replace Text

;; Replace the next instance of the selected text
(defun forward-replace-selection (beg end)
    "Search for the current selection"
    ;; This tells elisp to call this command with the point and mark
    ;; as arguments parameters bound to beg and end
    (interactive "r")

    ;; Save the current selection to a local variable.
    ;; We want to deactivate the mark, so save a private copy first.
    (let (
          (selection (buffer-substring-no-properties beg end))
         )
        ;; (message "forward-replace-selection:%s" selection)
    
        ;; De-activate the current mark region. We will change the mark later
        (deactivate-mark)

        (let (
            (replaceStr (read-from-minibuffer "Replacement: "))
            )
            ;;(message "replaceStr:%s" replaceStr)

            ;; Go to the start of the buffer.
            ;; search-forward will only start at the current position.
            (goto-char (point-min))

            ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Search-and-Replace.html
            (while (search-forward selection nil t)
                ;; https://www.gnu.org/software/emacs/manual/html_node/elisp/Replacing-Match.html
                ;; replace-match replacement &optional fixedcase literal string subexp
                ;; fixedcase says to not change the case of the replacement text
                ;; to match the text being replaced.
                (replace-match replaceStr t))
        ) ;; let

    ) ;; let
) ;; forward-replace-selection
(define-key global-map (kbd "C-r") 'forward-replace-selection)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Grep

;; Find the next instance of the selected text
(defun grep-selection (beg end)
    "Grep for the current selection"
    ;; This tells elisp to call this command with the point and mark
    ;; as arguments parameters bound to beg and end
    (interactive "r")

    ;; Save the current selection to a local variable.
    ;; We want to deactivate the mark, so save a private copy first.
    (let (
          (pattern (buffer-substring-no-properties beg end))
         )
        (message "ddGrep:%s" pattern)
    
        ;; De-activate the current mark region. We will change the mark later
        (deactivate-mark)

        ;; grep-find is a built-in emacs elisp function.
        ;; See: https://www.gnu.org/software/emacs/manual/html_node/emacs/Grep-Searching.html#Grep-Searching
        ;; See: https://www.gnu.org/software/emacs/manual/html_node/emacs/Grep-Searching.html

        ;; The options are the normal command line grep options.
        ;; Here, I use:
        ;;  -e, --regexp=PATTERN      use PATTERN for matching
        ;;  -i, --ignore-case         ignore case distinctions
        ;;  -n, --line-number         print line number with output lines
        ;;  -H, --with-filename       print file name with output lines
        ;;  -R, --recursive           like --directories=recurse, and also follow all symlinks
        ;;
        ;; Some useful topns which are not used now, but may be used later
        ;;  -w, --word-regexp         force PATTERN to match only whole words
        ;;  -x, --line-regexp         force PATTERN to match only whole lines
        ;;  -m, --max-count=NUM       stop after NUM selected lines
        ;;  -h, --no-filename         suppress the file name prefix on output
        ;;  -o, --only-matching       show only the part of a line matching PATTERN
        ;;  --include=FILE_PATTERN    search only files that match FILE_PATTERN
        ;;  -L, --files-without-match print only names of FILEs with no selected lines
        ;;  -l, --files-with-matches  print only names of FILEs with selected lines
        ;;  -T, --initial-tab         make tabs line up (if needed)
        ;;  -B, --before-context=NUM  print NUM lines of leading context
        ;;  -A, --after-context=NUM   print NUM lines of trailing context
        ;;  -C, --context=NUM         print NUM lines of output context
        (grep (concat "grep -i -n -H -R -e \"" (shell-quote-argument pattern) "\" /home/ddean/ddRoot/code"))
    ) ;; let
) ;; grep-selection
(define-key global-map (kbd "") 'grep-selection)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Parens and Braces
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Find the matching (open or close) paren
;; This was copied (with some small changes) from:
;; https://www.gnu.org/software/emacs/manual/html_node/efaq/Matching-parentheses.html
(defun find-match-paren (arg)
    "Go to the matching paren if on a paren; otherwise insert %."
    (interactive "p")
    (cond
            ((looking-at "\\s(") (forward-list 1) (backward-char 1))
            ((looking-at "\\s)") (forward-char 1) (backward-list 1))

            ((looking-at "\\s[") (forward-list 1) (backward-char 1))
            ((looking-at "\\s]") (forward-char 1) (backward-list 1))
    ) ;; cond
) ;; defun
(define-key global-map (kbd "C-]") 'find-match-paren)

;; Make braces act like parens, and match opens and closes
(modify-syntax-entry ?{ "(}")
(modify-syntax-entry ?} "){")





;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Tabs and Indentation
;;
;; http://www.emacswiki.org/emacs/IndentationBasics
;; https://stackoverflow.com/questions/344966/improved-tab-in-emacs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Tabs are space characters, not a tab character.
(setq-default indent-tabs-mode nil)

(global-set-key (kbd "TAB") 'tab-to-tab-stop)
(setq default-tab-width 4)
(setq tab-width 4)

;; tab-width is used when DISPLAYING tabs, while tab-stop-list 
;; is needed to determine tab stops when you ADD tabs.
;; From emacs documentation, "The variable tab-stop-list controls these positions. The default value is nil, which means a tab stop every 8 columns."
;;;(setq-default c-basic-offset 4)
(setq tab-stop-list (number-sequence 4 200 4))

;; Be careful. If you set this to newline-and-indent, then emacs
;; will autoindent no matter what you set the autoindent options to.
;;(global-set-key (kbd "RET") 'newline-and-indent)
(global-set-key (kbd "RET") 'newline)

;; Don't use tabs to indent code.
;;;(setq-default indent-tabs-mode nil)

;; Stop emacs from trying to second-guess what it thinks I want.
(when (fboundp 'electric-indent-mode) (electric-indent-mode -1))
;;(setq-default electric-indent-inhibit t)

;; Pasting a newline does not cause an indent.
(global-set-key "\C-j" 'newline)



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Indenting and Un-Indenting
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defun shift-region (distance)
  (let ((mark (mark)))
    (save-excursion
      (indent-rigidly (region-beginning) (region-end) distance)
      (push-mark mark t t)
      ;; Tell the command loop not to deactivate the mark
      ;; for transient mark mode
      (setq deactivate-mark nil))))

(defun shift-right ()
  (interactive)
  (shift-region 4))

(defun shift-left ()
  (interactive)
  (shift-region -4))

;; C-[ is equivalent to the escape key on US English keyboards
;; Changing  C-[ will break things like Esc-x
(global-set-key (kbd "C-]") 'shift-right)
(global-set-key (kbd "C-.") 'shift-right)
(global-set-key (kbd "C-,") 'shift-left)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Backup Files
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(setq backup-directory-alist `(("." . "~/emacsBackupFiles")))

(setq delete-old-versions t
  kept-new-versions 1
  kept-old-versions 1
  version-control t)

;; This will turn off all backup files.
;; (setq make-backup-files nil)











vi editor

I used emacs until I went into IDE's. Now that I am back to some linux programming, here are some tips for those times when I do a bit of VI (like when you are running as root and need an editor for a config file).




Emacs Common Things

For some reason, I always forget these things.




Burning DVDs on Linux

I use an online backup service, but I still like to burn my home directory to a DVD every few days. It lets me make my own offsite backups, as well as shuttle my home directory between machines and between Linux and Windows. I know I might be able to use some online service for that, but with more complexity, with a monthly subscription fee, with challenges in portability across operating systems, with a dependency on a third party company that may change their UI or features or costs, and with my data sitting on somebody else's computer which may be secure but is also an inviting target for hackers. On Windows, I just used Roxio, but on Linux, here is a quick and dirty solution. I wrote scripts to do this, so I just run the script to burn an image:

This uses growisofs, which requires you install

    yum install dvd+rw-tools

Burning a data DVD with a tree of files
    su
    mkisofs -J -R -o /your-temp-directory-name/foo.iso -root your-top-level-dir-name  /your-home-dir
    growisofs -dvd-compat -Z /dev/cdrom=/your-temp-directory-name/foo.iso 
    rm -rf /your-temp-directory-name/foo.iso
Restoring a Directory from a DVD
    su
    umount /dev/cdrom
    mount -t iso9660   /dev/cdrom   your-temp-directory-name
    rm -r -I   your-home-dir
    cp -r your-temp-directory-name   your-home-dir
    chown -R   your-user:your-group   your-home-dir
    chmod -R   u+rwx  your-home-dir
    umount /dev/cdrom
Note, these must run as root.
Burning VOB files to a Video DVD
There are several alternatives.


Compiling Linux programs with static libraries

Linux has adopted the philosophy that programs should be dynamic linked. There are both legal reasons for this (the libraries are built under GPL) and practical. However, suppose you want to compile a program, and then run your program on servers provided by web hosting companies. Your program must be compiled with exactly the same version of the runtime libc as is available on the hosting servers. Do hosting companies guarantee that? Of course not. So, instead your program must be compiled with static libraries. That is the problem I am trying to solve, and here are some notes.




Installing and configuring mySQL

Installation

I use Fedora, which uses dnf and yum, and the best guide I found (granted after only a cursory look) is at www.if-not-true-then-false.com/2010/install-mysql-on-fedora-centos-red-hat-rhel


Installing and configuring Apache
See https://fedoraproject.org/wiki/Apache_HTTP_Server


Using CSS "position" attributes for HTML Layout


Many HTML elements may use CSS to control where they are positioned on a page. This is done with a "position" attribute, that may have two values: "absolute" or "relative". For example:

These can be confusing, because they use the terms "absolute" and "relative" to place an element in a position in relation to the "normal position of that element in the HTML layout", and NOT necessarily in relation to another element. So, the browser first lays out an HTML document, which assigns every element in the document to a position on the page. This initial position is referred to as the element's position in the "document flow". Once the browser has completed this initial layout step, then the CSS position attributes may override each element's position and place the element in a different place.

"Relative" means place the element at some offset in relation to where it would normally go in the HTML laytout. So, for example, if a typical HTML page would place an element at x=100,y=200, and the element had an attribute

then the element would be placed at x=150,y=275.

"Absolute" means place the element at some "absolute" position, and just ignore where it would normally go in the HTML laytout. So, for example, if a typical HTML page would place an element at x=100,y=200, and the element had an attribute

then the element would be placed at x=50,y=75.

However, the confusing part is that an "absolute" coordinate is still in relation to somethng. It may be in relation to the bottom-left corner of the HTML page, but it may also be in relation to a containing element, like a div element. So, "position:absolute" means an absolute position compared to the flow of the document but still relative to the position of the parent HTML element that contains the element being moved.


Installing Raspberry Pi

Installation with Linux

Some handy references:

Copying Files from Linux to a Pi

Some handy references:

Cross-compiling on Linux and Running on Pi

I am not doing this yet. Currently, I am just maintaining source code on my dev box and copying it to a Pi and compiling it there. Some handy references: