This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // function with scope | |
| functionWithScope = (function (){ | |
| var x = 1; | |
| return function() { | |
| console.log('Private variable value: ' + x); | |
| }; | |
| }()); | |
| functionWithScope(); //output: 'Private variable value: 1' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var createIdempotentWorker = function() { | |
| var isWorking = false; | |
| return { | |
| doWork: function() { | |
| if (isWorking) { | |
| console.log("I'm already working"); | |
| return; | |
| } | |
| isWorking = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| result = (function () { | |
| var result = 0; | |
| return { | |
| value: function() { | |
| return value; | |
| }, | |
| increment: function() { | |
| return ++value; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Beavis = { name: 'Beavis' }; | |
| Beavis.__proto = Human; | |
| Human = {}; | |
| Human.__proto__ = Being | |
| Being = { | |
| toString: function() { return this.name; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 " > " |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ApplicationClass = new-psclass Application { | |
| note -static objectCount 0 | |
| method -static displayObjectCount { | |
| "$($this.ClassName) has $($this.ObjectCount) instances" | |
| } | |
| note -private Name | |
| note -private Path |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # properties | |
| $registerApp = new-object psobject -property @{ | |
| name = $null | |
| path = $null | |
| type = $null | |
| } | |
| # constructor | |
| function RegisterApp { | |
| param( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exec (' | |
| SELECT DISTINCT ' + | |
| @SearchField + ' FROM SchemaAudit WHERE StartDate >= "' | |
| + CAST(@DateFrom as varchar(20)) | |
| + '" AND EndDate >= "' | |
| + CAST(@DateTo as varchar(20)) | |
| + '" | |
| ORDER BY ' + @SearchField +' ASC') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| exec (' SELECT DISTINCT ' | |
| + @SearchField + ' FROM SchemaAudit WHERE StartDate >= ' | |
| + Convert(varchar(20), @DateFrom) | |
| + 'AND WHERE EndDate >= ' | |
| + Convert(varchar(20),@DateTo) | |
| + ' ORDER BY ' | |
| + @SearchField | |
| +' ASC') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 |