Skip to content

Instantly share code, notes, and snippets.

@vonHabsi
Last active June 22, 2017 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vonHabsi/619ddf9775f60f0dd309eb32dbc3b060 to your computer and use it in GitHub Desktop.
Save vonHabsi/619ddf9775f60f0dd309eb32dbc3b060 to your computer and use it in GitHub Desktop.
Devblog

2017-06-18

More emacs tips

Whats the best way to package my Emacs installation (packages and config) so that it can quickly be installed anywhere?

2017-06-16

Running Emacs as a daemon

Emacs Stack Exchange "emacs daemon" search results

Running multiple daemons for different customisations

https://emacs.stackexchange.com/questions/41/start-two-separate-emacs-daemons-for-console-and-gui/1053#1053
OP’s issue could be fixed by advice which in turn could obviated by use of after-make-frame-functions hooks

2017-06-15

Things to do

2017-06-14

Main Emacs Wiki Indentation Page

Directory Variables which can set project language specific tabs and indentation

Basic Code for Space Instead of Tabs

    M-x set-variable<RET>
      indent-tabs-mode<RET> nil
Or in your .emacs file:
    (setq-default indent-tabs-mode nil)

Tasks

Set tab width, relating to programming language type

(defun my-setup-indent (n)
  ;; java/c/c++
  (setq c-basic-offset n)
  ;; web development
  (setq coffee-tab-width n) ; coffeescript
  (setq javascript-indent-level n) ; javascript-mode
  (setq js-indent-level n) ; js-mode
  (setq js2-basic-offset n) ; js2-mode, in latest js2-mode, it's alias of js-indent-level
  (setq web-mode-markup-indent-offset n) ; web-mode, html tag in html file
  (setq web-mode-css-indent-offset n) ; web-mode, css in html file
  (setq web-mode-code-indent-offset n) ; web-mode, js code in html file
  (setq css-indent-offset n) ; css-mode
  )

2017-06-13

Hash Tables in Bash and Zsh

2017-06-13

Listing and Logging Git Branches with git for-each-ref and hash tables in bash and zsh

Original query was how to list last commits on all branches on all relevant repos, displaying full directory names on each branch, their remotes and the remote URLs. Questions began with https://stackoverflow.com/questions/44433867/does-git-log-have-the-option-of-iterating-a-command-over-all-or-some-branches and https://stackoverflow.com/questions/44525202/can-the-url-of-the-remote-be-included-in-the-output-of-git-for-each-ref-comman
The latter has a good enough answer.

Answer to own question teaches some bash techniques new to me.

2017-06-12

Switching to vim editing mode on the terminal’s command line.

This is supported by the vi-mode plugin at ~/.oh-my-zsh/plugins/vi-mode

2017-06-11

Running emacs and spacemacs side by side, using ~/.spacemacs.d folder for emacs

Method is based on answer EMACS:SE-19936. Sample script in answer was modified

(setq use-spacemacs (getenv "USE_SPACEMACS"))
(when (> (length use-spacemacs) 0)
    (setq user-emacs-directory "~/.spacemacs.d/"))   ; defaults to ~/.emacs.d/
(load (expand-file-name "init.el" user-emacs-directory))

spacemacs script created in ~/bin to launch Spacemacs directory. emacs will launch as normal . Approach from now will be to install Spacemacs to ~/.spacemacs.d. It is in the documentation.

One suggestion on the spacemacs page is to install spacemacs to a separate .emacs.d under a ~/spacemacs but that appears to be for the purpose of testing. The logic of changing the HOME environment variable is also questionable

mkdir ~/spacemacs
git clone https://github.com/syl20bnr/spacemacs.git ~/spacemacs/.emacs.d
HOME=~/spacemacs emacs

The other more sensible suggestion is to install spacemacs to a spacemacs directory under the .emacs.d directory and use a switch to load the init.el file in the spacemacs subdirectory.

(setq spacemacs-start-directory "~/.emacs.d/spacemacs/")
(load-file (concat spacemacs-start-directory "init.el"))

As an exercise it may be a good idea to use a case statement to select the configuration based an on environment variable similar to the ~/bin/spacemacs script.

2017-06-09

Files to be copied as safety backup of user’s profile

Ensuring bash configuration doesn’t get broken.

There may be other files in other accounts

# script tp save files of personal .profile, there could be
# more in other accounts
mkdir -p ~/workpad/config
cp ~/.ba* ~/workpad/config/.
cp ~/.directory ~/workpad/config/.
cp ~/.house_aliases ~/workpad/config/.
cp ~/.gitconfig ~/workpad/config/.
cp ~/.profile ~/.screenrc ~/.spacemacs ~/.vimrc ~/workpad/config/.

2017-06-09

Harmonizing profiles across difference shells

Ensuring bash configuration doesn’t get broken.

Ensuring bash configuration doesn’t break is the main concern and so far it looks like it doesn’t. Can’t be too sure though. Making sure that rc files, functions and aliases are put in place is the main concern now. srvadmin account may need greater care. gogs may not be the ideal. Perhaps are dockerized Redmine may be better. That needs to be tested.

2017-06-09

notes on colorized command line difftools

Candidates

icdiff installed centrally.
Base system installation must include apt-get install python-setuptools python3-setuptools
vimdiff still looks better. More familiarity required with icdiff options. It would be better if vimdiff could be setup just to compare and not switch to editing mode.

2017-06-08

notes on colorized command line difftools

Candidates

icdiff looks more promising. Whether to install globally or locally is the main issue.
icdiff installed centrally.
Base system installation must include apt-get install python-setuptools python3-setuptools vimdiff still looks better. More familiarity required with icdiff options. It would be better if vimdiff could be setup just to compare and not switch to editing mode.

2017-06-07

zsh command history auto-complete

Outcome

Settled on https://github.com/psprint/zsh-navigation-tools which appears to be the goto tool for that function and is included with the oh-my-zsh distribution. It seems pretty straightforward and I have to lookup the docs.

2017-06-06

2017-06-02

Setting up users daemons to run at boot time using @reboot entry in crontab.

Update

adding export USER=gogs to top of script allows it work. `gogs appears to check it in some way.
Next step is to check default environment values are set, which ones are missing in a crontab running and know where they should be placed in dependent scripts. Perhaps in the individual crontab entries where required.

In Debian Jessie default environment variables in cron acquired via cron entry is: * * * * * env > ~/cronenv are (values in file ~/cronenv) are

HOME=/home/gogs
LOGNAME=gogs
PATH=/usr/bin:/bin
LANG=en_GB
SHELL=/bin/sh
PWD=/home/gogs

Debian Stretch/Sid has the following - LANGUAGE has been added but not sure what the : is doing there

LANGUAGE=:en_GB.utf8
HOME=/home/rchurch
LOGNAME=rchurch
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/rchurch

2017-06-01

Setting up users daemons to run at boot time using @reboot entry in crontab.

Summary of systems

In order to for user to logon and inspect the events, commands are run in a screen session. The The screen command has the form screen -d -m -S sessionName bash -c 'script.sh; exec bash'. The exec bash is needed for some reason. Examples are documented at MTC:1301. Workings and configuration of`xpra` must be revisted. pfbadmin needs it.

Problems with crontab environment

The @reboot script for gogs did not work because the environment variables when crontab are not properly set for the use and some programs require it. The solution for now will be to add export USER=gogs to the execution script.
There are some links to print out what variables are set when crontab runs and the missing once can be add to crontab or the actual execution scripts.
https://stackoverflow.com/questions/2135478/how-to-simulate-the-environment-cron-executes-a-script-with
https://unix.stackexchange.com/questions/49419/manually-run-a-cron-job-simulate-running-cron-job
https://serverfault.com/questions/85893/running-a-cron-job-manually-and-immediately
https://serverfault.com/questions/84542/how-can-i-test-a-new-cron-script
http://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables
http://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables/89596#89596

Moving a VirtualBox VM from Windows to Linux by exporting it

Execution error

After importing it, running result in error message:

Failed to open a session for the virtual machine CS_VBOX_VM_01.

VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED).

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: ConsoleWrap
Interface: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

It could be the default in the version of VirtualBox used on Linux, or imported from a setting actually used in the Windows version

Missing mount to local file system

The Shared Folders value dard wired (in Windows) version, needs setting at runtime and install time. Possibility on Windows needs to be checked.

2017-05-31

Creating Docs on buffer and window navigation in Emacs, Spacemacs, Vim primarily with tmux and screen

Queries at EmacsSE:33183 and SpacemacsRDT:6dwkfq
Main manual is at Single Page Manual and Page per Topic
emacs docs found at Buffers and Windows
C-x 2, C-x 3 and C-x 0 split horizontal, split vertical and delete respectively. Bringing up list of buffers

2017-05-30

2017-05-28

Updated advaita posts with (from Advaita Musings) message

Tells about Custom Submit Messages and how same can be accomplished with Rules module.

2017-05-26

vi editing mode in Geany and Kate

Geany doesn’t seem to be well supported, but there is a page at https://github.com/DGivney/geany-lua-scripts which has some code on scripting for geany. Kate has vi editing enabled at

To enable the VI input mode, go to
Settings → Configure Kate… → Editing → VI Input Mode.
It can also be toggled with the “VI Input Mode” setting in the “Edit” menu. (The default shortcut key is Meta+Ctrl+V – where Meta usually is the Windows key).

set date on servers with clocks behind

convert a set of graphic files from one format to another. The example in this case is converting from .jpg to .png files.

2017-05-23

Sorting text in Vim

Use the 'v' key to select the necessary lines - go to the command line using ':'. The range ot text selected will be shown. Enter sort and you are done.

2017-05-21

Embedding gists in Github gists

Found algorithms at https://tosbourn.com/insert-gists-without-javascript/. It essential involves opening the gist as javascript and stripping some content out of it.

  1. Find any reference of \n and remove it.

  2. Find any reference of \ and remove it.

  3. Find any double spaces and remove them.

  4. Then just remove the document.write(' and '); from the start and end of the two lines.

The 2 lines left are the CSS and the HTML. The example prefers to be the CSS in the HTML doc, but I will keep them separate. CSS though may differ for different document types.

2017-05-06

Getting Github pages up and running

Website name is vonhabsi.github.io and it is based on creating a repository with the same name as the domain name. ie vonhabsi.github.io

Different types and guides followed

  • https://pages.github.com/ This pages goes through basics of cloning the site at username.github.io making a change and pushing changes back. The master branch is the one used to create the site. It will make sense to develop locally in a separate branch, merge to master and push it when ready.

  • An alternative based on using multiple projects is to have an orphan branch in each relevant repo named gh-pages. If the account name is vonhabsi then each repo with a name project-repo-N with a gh-pages branch will have its website appear at vonhabsi.github.io/project-repo-N. There is also another page at https://service.github.com which has what seems to be a more hands on approach to learning about github.

  • The main video (an unlisted one) showing the basic starting process is https://www.youtube.com/watch?v=RaKX4A5EiQo&t=757s. It is also clickable at the end of the embedded introductory video at https://pages.github.com.

  • The main Youtube channel for Github is https://www.youtube.com/user/github and there is another channel for training at https://www.youtube.com/user/GitHubGuides which hosts the above mentioned guide.

  • Integrations Directory - https://github.com/integrations. This is a page which allows you to create different services offered by different companies, probably by connection to you Github account. The include services like Travis CI, Slack, Trello, Appveyor, Docker etc

2017-05-05

Notes on Highlighting Source piped to the screen

Other options are the use of the python pygments package, and Vim’s $VIMRUNTIME/macros/less.sh program which is bundled with Vim.

Both source-highlight from GNU and the Vim viewer $VIMRUNTIME/macros/less.sh worked well enough.

installation commands

Source Highlight

installed via debian package. Current debian packages are out of date at 3.18, including stretch. Authors version is at 3.26

apt-get install source-highlight
# link is required to get some of the scripts out there to work
ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh /usr/bin/src-hilite-lesspipe.sh

Vim viewer

automatically installed with Vim

Configuration in logon profile

# aliases added for colored less output
# based SU:71588
# based on linking /usr/bin to file in /usr/share
export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
export LESS=' -R '

#adapts for larger files
alias lessh='LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" less -M '

# terdon ULSE:267361
cless(){
     LESSOPEN='| source-highlight --failsafe --out-format=esc256 -o STDOUT -i %s 2>/dev/null ' less -R "$@"
}

2017-06-08

notes on colorized command line difftools

Candidates

icdiff looks more promising. Whether to install globally or locally is the main issue.
icdiff installed centrally.
Base system installation must include apt-get install python-setuptools python3-setuptools vimdiff still looks better. More familiarity required with icdiff options. It would be better if vimdiff could be setup just to compare and not switch to editing mode.

2017-06-07

zsh command history auto-complete

Outcome

Settled on https://github.com/psprint/zsh-navigation-tools which appears to be the goto tool for that function and is included with the oh-my-zsh distribution. It seems pretty straightforward and I have to lookup the docs.

2017-06-06

2017-06-02

Setting up users daemons to run at boot time using @reboot entry in crontab.

Update

adding export USER=gogs to top of script allows it work. `gogs appears to check it in some way.
Next step is to check default environment values are set, which ones are missing in a crontab running and know where they should be placed in dependent scripts. Perhaps in the individual crontab entries where required.

In Debian Jessie default environment variables in cron acquired via cron entry is: * * * * * env > ~/cronenv are (values in file ~/cronenv) are

HOME=/home/gogs
LOGNAME=gogs
PATH=/usr/bin:/bin
LANG=en_GB
SHELL=/bin/sh
PWD=/home/gogs

Debian Stretch/Sid has the following - LANGUAGE has been added but not sure what the : is doing there

LANGUAGE=:en_GB.utf8
HOME=/home/rchurch
LOGNAME=rchurch
PATH=/usr/bin:/bin
LANG=en_GB.UTF-8
SHELL=/bin/sh
PWD=/home/rchurch

2017-06-01

Setting up users daemons to run at boot time using @reboot entry in crontab.

Summary of systems

In order to for user to logon and inspect the events, commands are run in a screen session. The The screen command has the form screen -d -m -S sessionName bash -c 'script.sh; exec bash'. The exec bash is needed for some reason. Examples are documented at MTC:1301. Workings and configuration of`xpra` must be revisted. pfbadmin needs it.

Problems with crontab environment

The @reboot script for gogs did not work because the environment variables when crontab are not properly set for the use and some programs require it. The solution for now will be to add export USER=gogs to the execution script.
There are some links to print out what variables are set when crontab runs and the missing once can be add to crontab or the actual execution scripts.
https://stackoverflow.com/questions/2135478/how-to-simulate-the-environment-cron-executes-a-script-with
https://unix.stackexchange.com/questions/49419/manually-run-a-cron-job-simulate-running-cron-job
https://serverfault.com/questions/85893/running-a-cron-job-manually-and-immediately
https://serverfault.com/questions/84542/how-can-i-test-a-new-cron-script
http://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables
http://unix.stackexchange.com/questions/27289/how-can-i-run-a-cron-command-with-existing-environmental-variables/89596#89596

Moving a VirtualBox VM from Windows to Linux by exporting it

Execution error

After importing it, running result in error message:

Failed to open a session for the virtual machine CS_VBOX_VM_01.

VT-x is disabled in the BIOS for all CPU modes (VERR_VMX_MSR_ALL_VMX_DISABLED).

Result Code: NS_ERROR_FAILURE (0x80004005)
Component: ConsoleWrap
Interface: IConsole {872da645-4a9b-1727-bee2-5585105b9eed}

It could be the default in the version of VirtualBox used on Linux, or imported from a setting actually used in the Windows version

Missing mount to local file system

The Shared Folders value dard wired (in Windows) version, needs setting at runtime and install time. Possibility on Windows needs to be checked.

2017-05-31

Creating Docs on buffer and window navigation in Emacs, Spacemacs, Vim primarily with tmux and screen

Queries at EmacsSE:33183 and SpacemacsRDT:6dwkfq
Main manual is at Single Page Manual and Page per Topic
emacs docs found at Buffers and Windows
C-x 2, C-x 3 and C-x 0 split horizontal, split vertical and delete respectively. Bringing up list of buffers

2017-05-30

2017-05-28

Updated advaita posts with (from Advaita Musings) message

Tells about Custom Submit Messages and how same can be accomplished with Rules module.

2017-05-26

vi editing mode in Geany and Kate

Geany doesn’t seem to be well supported, but there is a page at https://github.com/DGivney/geany-lua-scripts which has some code on scripting for geany. Kate has vi editing enabled at

To enable the VI input mode, go to
Settings → Configure Kate… → Editing → VI Input Mode.
It can also be toggled with the “VI Input Mode” setting in the “Edit” menu. (The default shortcut key is Meta+Ctrl+V – where Meta usually is the Windows key).

set date on servers with clocks behind

convert a set of graphic files from one format to another. The example in this case is converting from .jpg to .png files.

2017-05-23

Sorting text in Vim

Use the 'v' key to select the necessary lines - go to the command line using ':'. The range ot text selected will be shown. Enter sort and you are done.

2017-05-21

Embedding gists in Github gists

Found algorithms at https://tosbourn.com/insert-gists-without-javascript/. It essential involves opening the gist as javascript and stripping some content out of it.

  1. Find any reference of \n and remove it.

  2. Find any reference of \ and remove it.

  3. Find any double spaces and remove them.

  4. Then just remove the document.write(' and '); from the start and end of the two lines.

The 2 lines left are the CSS and the HTML. The example prefers to be the CSS in the HTML doc, but I will keep them separate. CSS though may differ for different document types.

2017-05-06

Getting Github pages up and running

Website name is vonhabsi.github.io and it is based on creating a repository with the same name as the domain name. ie vonhabsi.github.io

Different types and guides followed

  • https://pages.github.com/ This pages goes through basics of cloning the site at username.github.io making a change and pushing changes back. The master branch is the one used to create the site. It will make sense to develop locally in a separate branch, merge to master and push it when ready.

  • An alternative based on using multiple projects is to have an orphan branch in each relevant repo named gh-pages. If the account name is vonhabsi then each repo with a name project-repo-N with a gh-pages branch will have its website appear at vonhabsi.github.io/project-repo-N. There is also another page at https://training.github.com which has what seems to be a more hands on approach to learning about github.

  • The main video (an unlisted one) showing the basic starting process is https://www.youtube.com/watch?v=RaKX4A5EiQo&t=757s. It is also clickable at the end of the embedded introductory video at https://pages.github.com.

  • The main Youtube channel for Github is https://www.youtube.com/user/github and there is another channel for training at https://www.youtube.com/user/GitHubGuides which hosts the above mentioned guide.

  • Integrations Directory - https://github.com/integrations. This is a page which allows you to create different services offered by different companies, probably by connection to you Github account. The include services like Travis CI, Slack, Trello, Appveyor, Docker etc

2017-05-05

Notes on Highlighting Source piped to the screen

Other options are the use of the python pygments package, and Vim’s $VIMRUNTIME/macros/less.sh program which is bundled with Vim.

Both source-highlight from GNU and the Vim viewer $VIMRUNTIME/macros/less.sh worked well enough.

installation commands

Source Highlight

installed via debian package. Current debian packages are out of date at 3.18, including stretch. Authors version is at 3.26

apt-get install source-highlight
# link is required to get some of the scripts out there to work
ln -s /usr/share/source-highlight/src-hilite-lesspipe.sh /usr/bin/src-hilite-lesspipe.sh

Vim viewer

automatically installed with Vim

Configuration in logon profile

# aliases added for colored less output
# based SU:71588
# based on linking /usr/bin to file in /usr/share
export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s"
export LESS=' -R '

#adapts for larger files
alias lessh='LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" less -M '

# terdon ULSE:267361
cless(){
     LESSOPEN='| source-highlight --failsafe --out-format=esc256 -o STDOUT -i %s 2>/dev/null ' less -R "$@"
 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment