Skip to content

Instantly share code, notes, and snippets.

View dnasca's full-sized avatar

Derrik dnasca

View GitHub Profile
@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 / 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 / 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 / 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 / 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 / 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 / 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(
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 / 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')
@dnasca
dnasca / 2014_b_BABIP.sql
Created April 21, 2015 04:50
Batting Average on Balls In Play (BABIP) - measures how often a ball in play goes for a hit. A ball is “in play” when the plate appearance ends in something other than a strikeout, walk, hit batter, catcher’s interference, sacrifice bunt, or home run. In other words, the batter put the ball in play and it didn’t clear the outfield fence.
#using the Lahman Baseball Database
SELECT
m.birthYear AS BIRTH,
CONCAT(m.nameFirst, ' ', m.nameLast) AS NAME,
SUM(b.AB) AS AB,
SUM((b.H - b.HR)/(b.AB - b.SO - b.HR + COALESCE(b.SF, 0))) AS BABIP #Batting Average on Balls In Play
FROM
Batting b,
Master m