Skip to content

Instantly share code, notes, and snippets.

View joe-oli's full-sized avatar
💭
what the flock? no status to report, i am not a facebook junkie.

joe-oli

💭
what the flock? no status to report, i am not a facebook junkie.
View GitHub Profile
@joe-oli
joe-oli / sortArrayOfObjectsByDate.js
Created February 13, 2020 13:08
sort Array Of Objects By Date
//Sort Array of Objects by Date Str yyyy-MM-dd;
//to run in node, open cmd prompt enter >node sortArrayOfObjectsByDate.js
let myArray = [
{trans_date : '2020-01-03', closing_bal: 298700.70},
{trans_date : '2020-01-07', closing_bal: 654321.20},
{trans_date : '2020-01-06', closing_bal: 111700.70},
{trans_date : '2020-01-01', closing_bal: 3000.70}
];
@joe-oli
joe-oli / Is-string-valid-date.txt
Created February 9, 2020 00:08
is string a valid date in javascript js
//*** Is STRING a Valid Date? ***
approach: check if .getTime is equal to itself; WTF?
because if date is invalid, it will return NaN for .getTime();
You can a) check isNaN(.getTime()) or (b) NaN is never equal to itself;
; i.e. return .getTime() === .getTime() is true, if valid date; false if not date - haha WTF indeed.
@joe-oli
joe-oli / shallow-compare-2-objects.js
Created January 31, 2020 02:43
shallow compare 2 javascript JS objects
const shallowCompareFN = (obj1, obj2) =>
Object.keys(obj1).length === Object.keys(obj2).length &&
Object.keys(obj1).every(key =>
obj2.hasOwnProperty(key) && obj1[key] === obj2[key]
);
let obj1 = {
prop1 : 'abc',
prop2 : '123'
}
@joe-oli
joe-oli / file-to-start-cmd-prompt-and-remain-open.txt
Created January 30, 2020 06:04
starts cmd prompt, runs cmd, and remains open
Put in your batch file
start cmd.exe /k "net use"
From cmd /?
Starts a new instance of the Windows XP command interpreter
CMD [/A | /U] [/Q] [/D] [/E:ON | /E:OFF] [/F:ON | /F:OFF] [/V:ON | /V:OFF] [[/S] [/C | /K] string]
/C Carries out the command specified by string and then terminates
@joe-oli
joe-oli / sql-server-snippets.sql
Last active January 22, 2020 00:08
SQL Server snippets
--bit(boolean) flag in SQL COlumn. To check for both false or Null use: isnull(MyTable.isBoolCol, 0) = 0
select * from MyTable
where isnull(MyTable.isBoolCol, 0) = 0
-- find all tables that have a DateTime column
select * from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME like 'hlc%' -- tables starting with hlc
and data_type = 'datetime'
@joe-oli
joe-oli / display-only-text-files.txt
Created January 17, 2020 01:24
display only text files within parent folder and children
Tree accepts only a few command line parameters:
c:\>Tree /?
Graphically displays the folder structure of a drive or path.
TREE [drive:][path] [/F] [/A]
/F Display the names of the files in each folder.
/A Use ASCII instead of extended characters.
None of the indicated parameters are a file mask or filter.
@joe-oli
joe-oli / object-has-AtLeastOne-property.js
Last active January 16, 2020 01:48
Does JS object have properties?
function objectHasProperties(obj) {
for (var prop in obj) {
if (obj.hasOwnProperty(prop)) {
return true;
}
}
return false;
}
// ALT for more modern JS
@joe-oli
joe-oli / DateTimeOffset-Serialization.txt
Last active January 13, 2020 02:01
How to Serialize and Deserialize a class containing DateTimeOffset Property in C#
DateTimeOffset fails silently with XmlSerializer; instead use DataContractSerializer.
Apparently XMLSerializer does not support certain aspects of the DateTimeOffset structure.. WTF?!
Generic example below (uses UTF8 encoding here, but you can use whatever you like):
public static string SerializeObject<T>(T instance) where T : class
{
try
{
MemoryStream stream = new MemoryStream();
@joe-oli
joe-oli / open-url-in-browser.txt
Created January 1, 2020 14:03
open urls in browser
https://github.com/sindresorhus/open/issues/89
Simple example. the array contains 3 urls;
It iterates thru, logs the urls correctly but only the first url is opened.
urlsArray.forEach(function(urlLine){
opn(urlLine); //for each url... launch in Browser
console.log(urlLine);
});
My environment is Windows / default Browser chrome
@joe-oli
joe-oli / favicon.html
Last active December 27, 2019 17:35
favicon favourite icon fave icon no more annoying favicon could not be loaded message.
<!--
No more annoying messages in console, and no need to add another file to the repository; just include it in the head for a "blank" icon.
-->
<link href="data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQEAYAAABPYyMiAAAABmJLR0T///////8JWPfcAAAACXBIWXMAAABIAAAASABGyWs+AAAAF0lEQVRIx2NgGAWjYBSMglEwCkbBSAcACBAAAeaR9cIAAAAASUVORK5CYII=" rel="icon" type="image/x-icon" />
<!-- ALT: apparently either of the following also suppresses Browser request for favicon.ico -->
<link rel="shortcut icon" type="image/x-icon" href="data:image/x-icon;,">