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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / 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 / compare-arrays.js
Created February 19, 2020 12:38
Compare arrays return true/false
//test #1: exactly the same.
let myArrayA = [
{periodSeqNo: 30010, period_month :'jan 2020', start_date: '2020-01-01', end_date: '2020-01-31', opening_bal: 350000.11, opening_rate: 3.100, int_amount_charged: 255.10},
{periodSeqNo: 30020, period_month :'feb 2020', start_date: '2020-02-01', end_date: '2020-02-29', opening_bal: 360000.12, opening_rate: 3.200, int_amount_charged: 255.20},
{periodSeqNo: 30030, period_month :'mar 2020', start_date: '2020-03-01', end_date: '2020-03-31', opening_bal: 370000.13, opening_rate: 3.300, int_amount_charged: 255.30},
];
let myArrayB = [
{periodSeqNo: 30010, period_month :'jan 2020', start_date: '2020-01-01', end_date: '2020-01-31', opening_bal: 350000.11, opening_rate: 3.100, int_amount_charged: 255.10},
{periodSeqNo: 30020, period_month :'feb 2020', start_date: '2020-02-01', end_date: '2020-02-29', opening_bal: 360000.12, opening_rate: 3.200, int_amount_charged: 255.20},
{periodSeqNo: 30030, period_month :'mar 2020', start_date: '2020-03-01', end_date: '2020-03-31',
@joe-oli
joe-oli / ExpandoObject-example.cs
Created February 20, 2020 02:13
dynamic and ExpandoObject
IDictionary<string, object> expando = new ExpandoObject();
expando["foo"] = "bar";
dynamic d = expando;
Console.WriteLine(d.foo); // bar
//Example use case, convert XML payload. loop over the elements, e.g.
var doc = XDocument.Load(file);
IDictionary<string, object> expando = new ExpandoObject();