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 / class-vs-functional-component.js
Last active March 20, 2020 12:33
React - Class vs Functional component
//--before
class Brief extend React.Component {
render() {
let {post} = this.props
return (
<div className="brief">
<Link to={`/apps/blog/posts/${post._id}`} className="title">
<strong>{post.title}</strong>
</Link>
@joe-oli
joe-oli / truthy-vs-falsy-in-javascript.txt
Created March 19, 2020 02:15
Truthy vs Falsy in JS
From http://www.sitepoint.com/javascript-truthy-falsy/
The following values are always falsy:
* false
* 0 (zero)
* "" (empty string)
* null
* undefined
* NaN (a special Number value meaning Not-a-Number!)
@joe-oli
joe-oli / LookupDescByCode.js
Created March 19, 2020 02:03
Lookup corresponding Description, given a Code
/* Usage:
node LookupDescByCode
You can ommit '.js'
Using a constant lookup Structure (either Array or Obj), fetch the Code+Desc, given the Code.
*/
const CodeDescArrMap = [
{Code: 'Z101', Desc: "Apples"},
{Code: 'Z201', Desc: "Bananas"},
{Code: 'Z301', Desc: "Oranges"}
@joe-oli
joe-oli / ajax-fetch-axios.txt
Created March 11, 2020 05:30
ajax fetch and axios
<script>
$(function(){
$.ajax(
{
type: "POST",
url: "https://testapi.XXXXXXXX.com/auth",
data: {
username:'TestUser',
password: 'TestPwd'
},
@joe-oli
joe-oli / testplayer.java
Created March 10, 2020 09:41
randomly play mp3 file in java
/*
* Download from http://www.javazoom.net/javalayer/sources.html
* Unarchive JLayer into source directory
*
* Build with something like:
* javac -classpath JLayer1.0.1/classes/ RandomMP3Player.java
* Run with something like:
* java -classpath .:jl1.0.1.jar RandomMP3Player 10 z.mp3 1.mp3
*
*/
@joe-oli
joe-oli / promise-async-await-example.js
Last active February 28, 2020 01:07
async-await example vs promise
/* in both cases, wire the `handleSubmit` FN in the html.form onSubmit event
<form onSubmit={this.handleSubmit}>
<input old pwd
<input new pwd
<input confirm pwd
<button etc
</form>
*/
//ALT #1: use Promise.then().catch() syntax
@joe-oli
joe-oli / LINQ-and-List-methods.txt
Last active February 20, 2020 05:12
LINQ and List methods
Just for reference, here is a table of some old .NET 2 style List<> instance methods, and their equivalent extension methods in Linq:
METHOD IN List<> METHOD IN Linq
------------------------------------------------------------------------------------------
list.Contains(item) query.Contains(item)
list.Exists(x => x.IsInteresting()) query.Any(x => x.IsInteresting())
list.TrueForAll(x => x.IsInteresting()) query.All(x => x.IsInteresting())
@joe-oli
joe-oli / ExpandoObject-example.cs
Last active February 20, 2020 02:55
dynamic and ExpandoObject
dynamic x = new ExpandoObject();
x.NewProp = string.Empty;
Alternatively:
var x = new ExpandoObject() as IDictionary<string, Object>;
x.Add("NewProp", string.Empty);
//=============
IDictionary<string, object> expando = new ExpandoObject();
expando["foo"] = "bar";
@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();
@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',