Tuesday, December 27, 2016

How to compile a C++ program on Mac OSX

File "HelloWorld.cpp" contents between the dashed lines:

-----

#include <iostream>
using namespace std;

int main()
{
    cout << "Hello world!" << endl;
    cout << "Hello again!" << endl;
    return 0;
}

-----

Now compile the program:

g++ HelloWorld.cpp -o HelloWorld

Now run the program:

./HelloWorld


Wednesday, November 2, 2016

My .vimrc customizations on OS X (MacOS)

I have bits and pieces of this scattered throughout this blog.  This is an effort to put it into one place. Don't be surprised if I add more to this post later.

Helpful customizations for .vimrc:

" This turns off the annoying bell every time I hit the wrong key
set visualbell

" The following two lines turn on syntax highlighting
filetype plugin indent on
syntax on

" This tells vim that I am using a black background and need light colored text
set background=dark

Wednesday, September 28, 2016

Git - remotes

git clone <remote_location> <clone_name> - Create a duplicate (clone) of remote_location and locally call it clone_name

git remote -v - Display a list of Git project remotes

git fetch - Bring changes in remote master down to origin/master branch (not my local master branch)

git merge origin/master - Bring changes in origin/master branch into my local master branch


Workflow:
- Fetch and merge changes from remote
git fetch
git merge origin/master
- Create branch to work on new stuff
git branch <my_new_branch>
- Work on stuff in my branch and then commit work
git checkout <my_new_branch>
vi mychange.txt
git add mychange.txt
git commit -m "My message"
- Fetch and merge from remote again
git fetch
git merge origin/master
- Push my branch up to the remote for review
git push origin <my_new_branch>

[Edit]

The excellent Mark Moser suggests the following shortcut:

git pull

Instead of:

git fetch
git merge origin/master

[/Edit]

Git - branches

git branch - Which branch am I on?

git branch <new_branch> - Create a new branch

git checkout <branch_name> - Switch to different branch

git merge <branch_name> - Merge branch_name into my current branch?

git branch -d <branch_name> - Delete the branch no longer needed

Tuesday, September 27, 2016

Git refresher

git init - Initializes my directory for a Git project

Git project has three parts:
1 - Working Directory - Where I create, edit, delete, and organize files
2 - Staging Area - Where I list changes I make to the working directory
3 - Repository - Where Git permanently stores those changes as different versions of the project

git status - Check status of changed files

git add filename - Adds file to Git project so Git watches for changes
git add filename1 filename2 - Add multiple files to Git project

git diff filename - Identifies changes within the file

git commit -m "Message describing commit"

git log - View log of commits

git show HEAD - Displays the message for the HEAD commit plus all the file changes that were committed.
HEAD = The commit I am currently on

git checkout HEAD filename - Revert filename back to the HEAD commit

git reset HEAD filename - Unstage (reset) filename from staging area.
Useful for when I accidentally added a file to the staging area and do not want to commit it.

get reset <SHA> - Rewind back to commit identified by SHA value.  SHA value is first 7 characters.
SHA values can be seen in the git log (use "git log" to view)


Thursday, September 22, 2016

Powershell - Read SQL Log

Import-Module SQLPS -DisableNameChecking

$server = New-Object -TypeName Microsoft.SqlServer.Management.Smo.Server -ArgumentList "serverName"

# ReadErrorLog() returns a dataTable object
$d = $server.ReadErrorLog()

foreach ($r in $d.Rows)
{

    Write-Host "============================"
    Foreach ($c in $d.Columns)
    {
        Write-Host $c.ColumnName "=" $r[$c]

    }

}

---

ReadErrorLog(#)

If you provide a number, it reads that particular SQL log number.  (Eg - SQL log numbers 1 through 6).


Saturday, August 20, 2016

PowerShell - Send Email

# Send email
Send-MailMessage -SmtpServer "smtp.corp.org" -to "you@yourcorp.net" -from "powershell@hostname.domain.corp.org" -subject "Test PowerShell email 1" -body "This is my body"

# Send email with an attachment
$body = "This is the long-winded message."
$file = "c:\temp\file.txt"

Send-MailMessage -SmtpServer "smtp.corp.org" -to "you@yourcorp.net" -from "powershell@hostname.domain.corp.org" -subject "Test PowerShell email 2" -body $body -Attachments $file