Monday, March 31, 2014

Powershell - File Date Change Routine

There are times you need to have files that are created and modified on a specific date for integration testing some file management or metadata gathering routine. This is a simple routine to assist in that.

$varFileName=read-host "Enter path and file name e.g. c:\dir\file.zip"
$varCreatedDateOffset=read-host "Enter the created date offset in days e.g. -7"
$varModifiedDateOffset=read-host "Enter the modified date offset in days e.g. 0"

    $change = Get-Item $varFileName
    $createDate = Get-Date
    $modDate = Get-Date
    $createDate = $createDate.AddDays($varCreatedDateOffset)
    $modDate = $modDate.AddDays($varModifiedDateOffset)
    $change.CreationTime = $createDate
    $change.LastWriteTime = $modDate
    Get-Item $change|Select-Object Mode,CreationTime,LastWriteTime,Length,Name

Wednesday, March 19, 2014

What happens when a transaction dies a terrible blocking death in SQL Server

USE <DATABASE>

DECLARE @UoWID uniqueidentifier
SET @UoWID = (
select TOP 1 req_transactionUoW as [UoW ID] from sys.syslockinfo where req_spid = -2)

DECLARE @SQL NVARCHAR(MAX)

SET @SQL = 'KILL ''' + CAST(@UoWID AS VARCHAR(300)) + ''''

SELECT @SQL
EXEC sp_executesql @SQL

REFS:
http://www.sqlskills.com/blogs/paul/disaster-recovery-101-dealing-with-negative-spids-2-and-3/
http://www.eraofdata.com/orphaned-msdtc-transactions-2-spids/

Monday, March 17, 2014

Start a Peek at Clojure

Many tutorials are old and have outdated installation paths and environment hacks. I am sure these instructions will suffer no worse the ravages of time. However they worked at the time of this writing.


Terms
REPL
LEIN
MAP
VECTOR

Install
Clojure can be run in Windows (with or without Cygwin), OS X, and Linux. Do yourself a favor and create an Ubuntu partition on your machine. I am using Ubuntu 13.10.
  • Update Ubuntu OS
  • Install Current Java JRE
  • Install Java Clojure library. I use apt-get leiningen to install clojure 1.4, lein, and Leiningen.
  • Unfortunately 1.4 was not the current version of Clojure. So I needed to Download and unzip the Clojure jar. <<NEEDS WORK>> I opened a command line cd to the directory in which I have my clojure fines (cd /usr/share/maven-repo/org/clojure/clojure) expanded clojure jar 
    java -cp clojure-1.6.0.jar clojure.main
  • Install Eclipse Java EE IDE. Using apt-get Eclipse was a terrible idea. The  version of the package available through apt-get is very old. Get the tar ball for Kepler or the highest version supported by the Clojure community.
  • Make sure you can see the Eclipse Help menu. If you cannot, edit the Eclipse shortcut properties to use the command: env UBUNTU_MENUPROXY=0 /usr/lib/eclipse/eclipse
  • Using the Eclipse Market place from the Help menu, install the counterclockwise extension. This provides a Clojure perspective.
Some people want to use emacs to code. Not really my style but here are some notes:

  1. Pick an Emacs, install it. Everyone uses emacs
  2. Install ELPA
  3. Use ELPA to install the Emacs support for Clojure
  4. Install Leiningen
  5. Check project out of source control, use Lein to build it and run Swank, connect to that from Emacs.
Tutorial Listhttp://learn-clojure.com/clojure_tutorials.html
https://www.codeschool.com/code_tv/getting-started-with-clojure-part-2
http://doc.ccw-ide.org/documentation.html

References
Leiningen, a Clojure project build tool you will inevitably use to some extent.
http://code.google.com/p/counterclockwise/
https://github.com/technomancy/emacs-starter-kit
https://www.eclipse.org/downloads/
Don't use SourceForge nor Google Code
http://clojure.org/

Disorganized notes from JP meeting
Nike uses scala?!
(def tax-payer(
:first "Eric"
:last "Ald"
))
Jvm RUNNING THE CLOSURE source generates classes at run time.. Or as read eval print loop (REPL) can modify code as being executed?
Keyword type , starts with : make good keys on maps. A kind of function that can make all kinds of inputs and reduces the potential outputs…
Nil in closure = null in c#
[1,2,3, "word", :base] this  is a vector, like anarray or tuple…
Supports dynamic types..
Get - get values out of a map
Idiomatic closure (how to pass key words and map as function..also pass map object as function)
'(1,2,3)
See that single quote, it makes this just a data set not evaluated
Pst - REPL stack trace
You can filter the exception report by writing your own library
Network REPL in production using a TCP/IP connection to allow real time live debugging!
Operator precedence rules…none in clojure as there are no operators because all is functions
Defn define new function
Sample map
{
:rank :ace
:suit :club
}
(defn points [rank]
(case))
(points (:rank flip-card))
Thread first macro….
(--> flip-card
:rank
points)
Thread first/thread last macros
Let word..local symbols/variables
First, rest, next
First - first in collection
Rest remaining exclude nil
Next remaining or nil
Clojure conventions (isTrue? Is acceptable name)
#(= first-suit %)
Cond  - eval a condtion, like an if/then
Empty list is a false value as does nil, but nil and empty list are different values so you need to test for both conditions
Iterate - take a function set and create new sets from them
Iterate first (1,2,3)
first (1,2,3)
first (2,3)
first (3)
first ()
Does this work like it did with iterate rest?
Macros and functions live in the same name space during execution, macros are extensions
Mapping functions over collections
Macro expansion expands macro code down to byte code…special forms
Macros take parms
What does ~ represent in a macro..instance of a parm t be used later
Self Defined macros are increase complexity of debugging code
Clojars and leiningin --- distro
Lighttable IDE
Nightcode---mac only?
4clojure learning site vs clojure koans
Cognicast broabcast learning
Look at datonic non sql database that goes with this
Ring compojure - web crap
Code.test specj , clojure.test- testing frameworks