BeyondCompare from WSL

Configure merge and diff

[diff]
        tool = BCompare
[difftool]
        prompt = true
[difftool "BCompare"]
        path = "/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe"
        cmd = "/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe"  "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)"                                                                                                                          [merge]
        tool = BCompare
[mergetool "BCompare"]
        path = "/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe"
        cmd = "/c/Program\\ Files/Beyond\\ Compare\\ 4/bcomp.exe" "$(wslpath -aw $BASE)" "$(wslpath -aw $LOCAL)" "$(wslpath -aw $REMOTE)" "$(wslpath -aw $MERGED)"

Reference

Configure Alias

[alias]
        review = "!sha=$1; git status; b() { total=$(git diff | wc -l); if [ $total -eq \"0\" ]; then git diffdir --cached; else git diffdir; fi; }; s() { git diffdir $sha^ $sha; }; r() { if [ -z \"$1\" ]; then b; else s; fi; }; r"
        diffdir = difftool --dir-dif --no-symlinks

Run

touch tmp.txt
git add .
git review
git commit -am "tmp"
git review HEAD

Angular w/ Bootstrap from WSL

Install Node & Angular

sudo apt-get update
sudo apt-get upgrade
curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs
sudo npm install -g @angular/cli

Make Project

mkdir /path/to/working/dir
cd /path/to/working/dir
ng new my-app
cd my-app
npm install --save bootstrap
code .

Configure VS Code

  • Extensions: Angular Essentials by John Papa
  • Configure Chrome Launch: localhost:4200
  • Set Terminal Default: WSL
  • Open WSL & Run: ng serve

Batch Scripts

Looping FTP

Example usage would be to push a file to a set of clients

updt.bat Main executable

1
2
@echo off
FOR /F "tokens=3 delims=|" %%i in (list) DO ftp -s:updt %%i >> updt.out

ftpCmds.txt FTP Commands to run once connected

sys_username
sys_password
bin
cd desired/path
put filename.exe
bye

ftpServers.txt Servers and any other info you may need later

1
2
3
4
token 1|token 2|192.168.0.1 |token 4|token 5|
token 1|token 2|192.168.0.2 |token 4|token 5|
token 1|token 2|192.168.0.3 |token 4|token 5|
...

filename.exe This can be a uuencoded install script or really anything

Looping Excecutable

Similar to bash’s xargs, this allows you to iterate over each file in a directory and execute/modify

printFiles.bat

1
2
3
4
5
6
7
8
9
@ECHO OFF
SETLOCAL
set file=.\*
FOR %%i IN ("%file%") DO (
ECHO filedrive=%%~di
ECHO filepath=%%~pi
ECHO filename=%%~ni
ECHO fileextension=%%~xi
)

Create XSDs

1
for %%i in (.\*) DO xsd %%i  /c /n:myNamespace.XSD.%%~ni /o:..\..\MyProject\GeneratedClasses\

MS Docs - batch for

Create Shortcut

Creates a shortcut to a given file

1
2
3
4
5
6
7
8
9
10
rem Creating the File Shortcut
@echo off
set SCRIPT="%TEMP%\%RANDOM%-%RANDOM%-%RANDOM%-%RANDOM%.vbs
echo Set oWS = WScript.CreateObject("WScript.Shell") >> %SCRIPT%
echo sLinkFile = "\Path\To\Shortcut.lnk" >> %SCRIPT%
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> %SCRIPT%
echo oLink.TargetPath = "\\Path\To\File.exe" >> %SCRIPT%
echo oLink.Save >> %SCRIPT%
cscript /nologo %SCRIPT%
del %SCRIPT%

Bash Scripts

Redirect stdout/stderr

redirect stdout/stderr

1
a.out 0<input.txt 1>out.txt 2>&1
  • a.out is executable
  • input.txt replaces standard input (0)
  • out.txt receives the redirected standard output (1) that would have gone to the screen
  • &1 (location of stdout) receives the redirected stderr (2) that would have gone to the screen

Ignore stdout

1
a.out 1>/dev/null

Ignore stderr

1
a.out 2>/dev/null

Chaining Commands

1
2
3
4
5
6
7
8
9
10
11
12
$ true; echo "sup"
sup
$ false; echo "sup"
sup

$ true && echo "sup"
sup
$ false && echo "sup"

$ true || echo "sup"
$ false || echo "sup"
sup

Awk a CSV Column

1
awk -F "'*,'*" '{print $3}' filename.csv | uniq | wc -l

Trim Alias

1
alias trim="awk '{\$1=\$1;print}'"

Usage:

1
grep --no-filename 'xsd:restriction' *.xsd | trim | sort | uniq

SSH With Expect

1
2
3
4
5
6
7
8
9
10
11
12
#!/bin/expect -f

set timeout 15
set force_conservative 1
set addr [lindex $argv 0]
set storenum [lindex $argv 1]

spawn ssh my_id@$addr
set session $spawn_id
expect "Password:"
send "my_password\r"
expect -exact "\$ "
send "...

FTP With Expect

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    #!/usr/bin/expect -f


    set addr [lindex $argv 0]
    set timeout -1
    spawn ftp $addr
    expect {
    "):" { send "my_username\r" }
    "timed" exit
    }
    expect {
    "d:" { send "my_password\r" }
    "ftp>" { send "\r" }
    }
    expect "ftp>"
    send "bin\r"
    expect "ftp>"
    send "hash\r"
    expect "ftp>"
    send "cd my_directory\r"
    expect "ftp>"
    send "put myfile\r"
    expect "ftp>"
    send "by\r" 

Threading Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
mkdir locations
uudecode $0
chmod 777 filename.exe
for entry in $LIST
do
ip=`echo $entry | awk -F \: '{print $2}'`
loc=`echo $entry | awk -F \: '{print $1}'`
logfile="./locations/$loc.log"
./filename.exe $ip > $logfile &
count=`ps -ef | grep -i exp | wc -l | awk '{print $1}'`
while [ $count -gt 100 ]
do
count=`ps -ef | grep -i exp | wc -l | awk '{print $1}'`
echo "waiting for process to finish"
done
sleep 2
done
exit 0
begin 777 check_stores.exp
###... UUENCODED CODE GOES HERE ...###

###... filename.exe is here ...###

###... in this case ...###

...
end
  • The & after executing allows you to continue without waiting for completion.
  • filename.exe executed can be any program type (sh, exp, c, cpp, py, etc) but should be uniq.
  • filename.exe doesn’t need to be uuencoded into the script but it’s useful if execution isn’t on your box.

Default Shell

Set

1
chsh -s /bin/bash

Verify

1
ps -p $$

Bash Alternative

Using tcsh instead of bash?

Use vi on command line

bash

1
set -o vi

tcsh

1
bindkey -v

Adding an alias

bash

1
alias vi='vim'

tcsh

1
alias vi 'vim'

Kramdown syntax

Markdown (or Textile), Liquid, HTML & CSS go in. Static sites come out ready for deployment.

Headings

Heading 1

Heading 2

Heading 3

Heading 4

Heading 5
Heading 6

Blockquote

No more databases, comment moderation, or pesky updates to install—just your content.

Unordered List

  • Jekyll
    • Nested Jekyll
    • Nested Ruby
  • Ruby
  • Markdown
  • Liquid

Ordered List

  1. Jekyll
    1. Nested Jekyll
    2. Nested Ruby
  2. Ruby
  3. Markdown
  4. Liquid

This is an example inline link.

Paragraph w/ strong, em, etc.

These are just a few of the available configuration options. Many configuration options can either be specified as flags on the command line, or alternatively (and more commonly) they can be specified in a _config.yml file at the root of the source directory. Jekyll will automatically use the options from this file when run. For example, if you place the following lines in your _config.yml file.

Image

Photo by Rachel Davis.

Video

Default Code Block

This is code blog.

Styled Code Block

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/usr/bin/ruby

$LOAD_PATH << '.'
require "support"

class Decade
include Week
   no_of_yrs=10
   def no_of_months
      puts Week::FIRST_DAY
      number=10*12
      puts number
   end
end
d1=Decade.new
puts Week::FIRST_DAY
Week.weeks_in_month
Week.weeks_in_year
d1.no_of_months

Definition Lists

Definition Title
Definition Description

Paragraphs w/ Aligned Images

The Jekyll gem makes a jekyll executable available to you in your Terminal window. You can use this command in a number of ways.

Photo by Dustin Lee.

This site aims to be a comprehensive guide to Jekyll. We’ll cover topics such as getting your site up and running, creating and managing your content, customizing the way your site works and looks, deploying to various environments, and give you some advice on participating in the future development of Jekyll itself.

Jekyll is a simple, blog-aware, static site generator. It takes a template directory containing raw text files in various formats, runs it through a converter (like Markdown) and our Liquid renderer, and spits out a complete, ready-to-publish static website suitable for serving with your favorite web server. Jekyll also happens to be the engine behind GitHub Pages, which means you can use Jekyll to host your project’s page, blog, or website from GitHub’s servers for free.

Photo by LoboStudio Hamburg.

Throughout this guide there are a number of small-but-handy pieces of information that can make using Jekyll easier, more interesting, and less hazardous. Here’s what to look out for.

If you come across anything along the way that we haven’t covered, or if you know of a tip you think others would find handy, please file an issue and we’ll see about including it in this guide.

The front matter is where Jekyll starts to get really cool. Any file that contains a YAML front matter block will be processed by Jekyll as a special file. The front matter must be the first thing in the file and must take the form of valid YAML set between triple-dashed lines.

Installation

I assume you have already downloaded and installed Ruby. Here’s what you need to do next:

  1. Run gem install jekyll bundler.
  2. Copy the theme in your desired folder.
  3. Enter into the folder by executing cd name-of-the-folder.
  4. Run bundle install.
  5. If you want to access and customize the theme, use bundle exec jekyll serve. This way it will be accessible on http://localhost:4000.
  6. Upload the content of the compiled _site folder on your host server.

If something goes wrong, it’s likely you’re missing a package or on a wrong version. This may help.

sudo apt-get update
sudo apt-get autoremove
sudo apt-get autoclean
sudo apt-get upgrade
sudo apt-get install ruby-full build-essential zlib1g-dev
echo '# Install Ruby Gems to ~/gems' >> ~/.bashrc
echo 'export GEM_HOME="$HOME/gems"' >> ~/.bashrc
echo 'export PATH="$HOME/gems/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
sudo gem install jekyll bundler
sudo bundle install
sudo gem update --system
bundle exec jekyll serve