Wednesday, April 13, 2016

PowerShellFunctions

PowerShell Functions:

Recently I made a PowerShellFunctions. In a previous post I talked about one of the functions used Display-Calendar. I have since updated it to utilize the appropriate verb show. For a list of appropriate PowerShell verbs look no further than: Approved Verbs

I have recently updated it to include:
  • PS-Windows-Functions
    • Sync-WindowsTime
  • PS-File-Functions
    • ConvertFrom-Base64
    • ConvertTo-Base64
    • Write-CompressedFiles
  • PS-Calendar-Functions
    • Show-Calendar
  • PS-Structured-Query-Language-Functions
    • Get-Sql
    • Show-DatabasesWithTable
  • PS-GUI-Functions
    • Set-Clipboard

PS-Windows-Functions

Sync-WindowsTime

This starts the Windows Time service and calls w32tm /resync
Why might you use such a command? Perhaps you dual boot and the time is off after rebooting.
See: KB2385818.

PS-File-Functions

ConvertTo-Base64

This takes a input and produces a Base64 string:
echo "Look of disapproval" | ConvertTo-Base64
Results in: TG9vayBvZiBkaXNhcHByb3ZhbA0K

ConvertFrom-Base64

"TG9vayBvZiBkaXNhcHByb3ZhbA0K" | ConvertFrom-Base64
Results in: Look of disapproval

Write-CompressedFiles

Takes a directoryPath and writes a zip file in the destinationFile location.
Write-CompressedFile $directoryPath $destinationFile
I use this to zip up my module directory and save to my cloud:
Write-CompressedFile $env:PSModulePath.Split(";")[0] $ExportCompressedModuleFilePath $true

PS-Calendar-Functions

Show-Calendar

Previous Blog Post

PS-Structured-Query-Language-Functions

Get-Sql

This one is probably one of my favorite functions in the library. Here is an example:
Get-Sql "mycoolserver" "mydb" "select * from widgets"
You can pipe it to something like:
Get-Sql "mycoolserver" "mydb" "select * from widgets" | Out-GridView
Or make a query that calls a query:
Get-Sql "mycoolserver" "mydb" "select serverName, databaseName from linkedServerTable" | %{Get-Sql $_.serverName $_.databaseName "Select * from Widgets"}
Hopefully your database doesn't do that, but if it does it is nice to know PowerShell can handle it.

Show-DatabasesWithTable

Sometimes you need to find a database with a specific table:
DatabasesWithTable "mycoolserver" "importantTableName"
Gives you a list of databases with the appropriate table.
As we learned from the previous example you can chain these via the pipe line so you could run a query for each database.

Wednesday, April 6, 2016

How to make the most of archiving a web page to PDF

When you work in a technology industry and like to code your own pet projects there is often overlap. Sometimes when I am at work and I find an interesting to which article I would like to dedicate further research, I email myself a link. 

When I don't have time to fully digest the page, I like to save the content for later. As the web is a dynamic ever changing environment often sites change owners, or newer content takes the place. I like to archive them into PDF. 

Typically the web page is filled with clutter, but some browsers offer a "Reading Mode"

Internet Explorer 11:

https://blogs.msdn.microsoft.com/ie/2014/03/04/introducing-reading-view-in-ie-11/

Edge:

http://windows.microsoft.com/en-us/windows-10/getstarted-take-your-reading-with-you

Firefox (proposed):

https://wiki.mozilla.org/Reading_Mode

Chrome (also in the works)
http://lifehacker.com/enable-the-new-hidden-reader-mode-in-chrome-for-andro-1666469700


Turning on reader mode increases the quality of your archive through noise reduction.


Friday, April 1, 2016

Handling distractions when sleeping (For a Friend)

If you work in the IT operations industry for any length of time you probably will be "on call" at some point.

Being on call is typically a stressful time. You are constantly dreading the inevitable beep from your phone, or pager if your company is stuck in the mid-eighties. With a modern cellphone it is mostly used for more than one task. Some phones have a messenger application which might use the same ringtone as your phone.

A call at 3:00AM versus a Facebook Messenger message from one of your buddies who works the night shift can be just as stressful if you can't tell the difference.

Two of my close friends and I were in a group Facebook message. One of us works a regular business schedule. Another works the nightshift, another works a slightly different nightshift. One of us was on call this week and informed us that "It's my midnight.". I got to thinking about how to manage applications which provide interruptions in our sleep.

Assuming you don't get "on call" messages via Facebook Messenger here is how to manage it:

Find the gearicon on the application:



It is currently located on the top bar, but with the constant refining of the application it might change in the future.

After clicking the gear you will find yourself on the settings page:


Click Notifications & Sounds:




The "kill it with fire" choice is up at the top:


Simply sliding to off whilst you sleep might give you the best bang for your buck, but some of the other choices might be more appropriate, such as changing the sounds.


Saturday, March 12, 2016

Calendar In Powershell

I've added a new Repo on GitHub for making a calendar in PowerShell, much like the Linux command cal. I have omitted multi-language support and have opted to only implement the core functionality of displaying a calendar rather than also including the date of Easter.


https://github.com/crb02005/PowerShellFunctions/blob/master/calendar.ps1

Tuesday, March 8, 2016

Visual Studio Debugging

If you are a VB.NET developer for any length of time you probably will need to debug code. One of the tools I use is the Immediate Window. CTRL-ALT-I will open it. If you use the ? shortcut to print the value of a variable with multiple lines you probably get something like "Blah"+vbnewline+"someotherfield", but with the string formatter ",nq" you can get the following:

Blah
someotherfield

I hope this helps.

Monday, February 8, 2016

EVE Online

I recently started playing a popular space game. EVE Online.

If you've never heard of the game, I would suggest going to YouTube and look at a few videos.

Here is a trailer:


I had joined a corp and they wanted to get a list of all their player's assets. I created a PowerShell Script specifically for that purpose.

This one requires setting up your API key:

Skill Script:
https://gist.github.com/anonymous/0bc8bd3da21cd217fb70

This one shouldn't need any special permissions:

Sector Script:
https://gist.github.com/anonymous/998410deed0c0efb7e51
The script above lists the solar systems along with some interest data. Kills, Warps, and Corporation Ownership.
Note:

To view all just use:
$solarSystems.Values

Since it is PowerShell you can harness the Pipeline to find quite spaces and put them in a CSV file:


 $solarSystems.Values | %{if($_.ShipJumps -lt 3 -and $_.ShipKills -eq 0){$_}} | export-csv "your file path.csv"


If you decide you want to try it sign up for a free trial below:


Click on my Buddy link and sign up for a free trial:
https://secure.eveonline.com/trial/?invc=967f06ed-54cd-4294-8db7-500eed4154b5&action=buddy

Sunday, November 22, 2015

Minecraft: The Castle that commands and command blocks built

My middle son was playing Minecraft and wanted a command block. He didn't really know what they were or what they did but he wanted one. I did a little research and found you have to use a command to get a command block.

/give YOUR_PLAYER_NAME_HERE command_block COUNT_DEFAULTS_TO_ONE

This gives the player listed the number of command blocks specified. If no number was specified it defaults to one.

If you wanted 47 diamonds you would do something like:

/give YOUR_PLAYER_NAME_HERE diamond 47

Once you have mastered that you can move on to the next phase.

Targeting the nearest player. Instead of targeting a specific player you can target the nearest with @p

/give @p command_block

That gives the nearest player a command block. Pretty handy.

If you place a command_block and put a button on it you execute the command with the press of the button.

I have made a command_button giver:



And the command:
*Note Previous Output user name removed.

So this is moderately interesting. You could use a dispenser for this but you would have to keep filling it up. This is a close enough to infinite item spawner.

You can also fill an area with an item. If you fill it with air you can clear a flat space to build a base. This is useful if you want a flat area to build on, but like the surrounding terrain, versus the super flat world.

Fill works thusly:

/fill X Y Z X Y Z ITEM_TO_FILL

Why did I put X Y Z twice? It is a range. This range can be a single block if the numbers are the same or a column, or row, or a cube.

To build my castle I cleared a bit of terrain. To find the X Y Z press "F3" on your keyboard. It shows the position of you in XYZ, and the block in Block.



To hide the debug window press "F3" again. Through a bit of trial and error you will soon be an expert in three dimensional coordinates.

This page has a pretty comprehensive list of items:

http://www.minecraftinfo.com/IDList.htm

An important item to remember is "air" that lets you clear a space. I cleared a big cube to start. Then I added walls. The only bit that wasn't added was the crenellations.


Using this fill command you can make gates open and close as well as drawbridges.

You can connect the blocks together for multiple effects using redstone wire. If you want a delay use a redstone repeater. 

Here is my close gate and remove the draw bridge.






You can even make a convertible castle:




Okay that was fun but what about making some monsters?

/summon CREATURE_NAME X Y Z