Skip to content

Instantly share code, notes, and snippets.

View dnasca's full-sized avatar

Derrik dnasca

View GitHub Profile
@dnasca
dnasca / DateRange1.sql
Last active August 29, 2015 14:20
Date Range
exec (' SELECT DISTINCT '
+ @SearchField + ' FROM SchemaAudit WHERE StartDate >= '
+ Convert(varchar(20), @DateFrom)
+ 'AND WHERE EndDate >= '
+ Convert(varchar(20),@DateTo)
+ ' ORDER BY '
+ @SearchField
+' ASC')
exec ('
SELECT DISTINCT ' +
@SearchField + ' FROM SchemaAudit WHERE StartDate >= "'
+ CAST(@DateFrom as varchar(20))
+ '" AND EndDate >= "'
+ CAST(@DateTo as varchar(20))
+ '"
ORDER BY ' + @SearchField +' ASC')
@dnasca
dnasca / registerApp.ps1
Last active August 29, 2015 14:20
easy way to create aliases to run applications from the console
# properties
$registerApp = new-object psobject -property @{
name = $null
path = $null
type = $null
}
# constructor
function RegisterApp {
param(
@dnasca
dnasca / oop_in_powershell.ps1
Created May 9, 2015 06:01
using the PSClass CmdLet and implementing a basic class in Powershell 5
$ApplicationClass = new-psclass Application {
note -static objectCount 0
method -static displayObjectCount {
"$($this.ClassName) has $($this.ObjectCount) instances"
}
note -private Name
note -private Path
@dnasca
dnasca / Microsoft.PowerShell_profile.ps1
Last active September 8, 2015 07:43
just some quality of life objects to increase workflow in powershell.
#goes in C:\Users\user.name\Documents\WindowsPowerShell (Microsoft.PowerShell_profile.ps1)
#prompt is automatically invoked
function prompt {
# display the full, current path in the window title
$host.ui.RawUI.WindowTitle = ( get-item -path ".\" -verbose ).FullName + " :: ${env:username}"
# prompt: 14:22 :: c:\ >
write-host (($(get-date).ToString("HH:mm")) + " :: " + (get-location | get-item).Name) -nonewline -foregroundcolor yellow
return " > "
@dnasca
dnasca / ObjectsInheritFromOtherObjects.js
Last active September 8, 2015 07:32
Proto chains. Beavis is a Human, a Human is a Being. Understanding prototypical inheritance and the differences from class based inheritance.
Beavis = { name: 'Beavis' };
Beavis.__proto = Human;
Human = {};
Human.__proto__ = Being
Being = {
toString: function() { return this.name; }
@dnasca
dnasca / functionClosure.js
Last active August 29, 2015 14:26
A super simple example of a function closure in JavaScript. The example shows how to increment a private property within a function closure.
result = (function () {
var result = 0;
return {
value: function() {
return value;
},
increment: function() {
return ++value;
@dnasca
dnasca / scopeFollowingAFunction.js
Created July 29, 2015 05:25
Scope follows a function. Creating a simple state object.
var createIdempotentWorker = function() {
var isWorking = false;
return {
doWork: function() {
if (isWorking) {
console.log("I'm already working");
return;
}
isWorking = true;
@dnasca
dnasca / pattern_functionWithScope.js
Created July 29, 2015 05:53
Pattern: A function with scope
// function with scope
functionWithScope = (function (){
var x = 1;
return function() {
console.log('Private variable value: ' + x);
};
}());
functionWithScope(); //output: 'Private variable value: 1'
@dnasca
dnasca / pattern_synchronousCallback.js
Last active August 29, 2015 14:26
Pattern: the synchronous callback -- the callback that is called at the same time [in the same processing cycle] that the function is called.
/*
the synchronous callback:
create a function that can be called at a later time whenever the
higher order function (the function that were passing this function into -- aka: the function doing the calling)
is ready to call/invoke this function. Read this a few times and it will eventually make sense :)
*/
whenDone = function () {
console.log ("done")
};