Skip to content

Instantly share code, notes, and snippets.

View nantcom's full-sized avatar

NantCom Co., Ltd. nantcom

View GitHub Profile
@nantcom
nantcom / RxBlog-TimeStopWhenNoOneCares-Rx.cs
Created April 25, 2021 12:02
Sample for Rx Blog - Using Rx to Create more readable timer which stops when no one is listening
#r "nuget:System.Reactive/5.0.0"
using System.Reactive.Linq;
public class TimeStopWhenNoOneCares
{
private IObservable<long> _Interval;
private long _Time;
public IDisposable ObserveTime( Action<long> subscriber )
{
@nantcom
nantcom / RxBlog-observable-skeleton.cs
Created April 25, 2021 11:42
Skeleton of Code for Creation Observable - distilled from my experience~ 😊
using System.Reactive.Linq;
public class MyStateType {
}
IObservable<MyStateType> observable = Observable.Create<MyStateType>( observer => {
// should be CancellationTokenSource
// but use bool so it easier to understand
bool stop = false;
@nantcom
nantcom / rxblog-csharptimer.cs
Created April 25, 2021 11:17
RXBlog - CSharp Timer Sample (Sample for RoslynPad)
public class TimeStopWhenNoOneCares
{
private long _Time;
private CancellationTokenSource _Canceller;
private Action<long> _TimeHasSpassed;
public event Action<long> TimeHasSpassed
{
add {
_TimeHasSpassed += value;
@nantcom
nantcom / ncb-imgdefer.js
Last active February 15, 2020 14:02
Sample Directive for Defer loading image
module.directive('ncbImgdefer', function ($http, $datacontext) {
var imgList = [];
var existingTimeout = null;
function fixIsotope() {
if (existingTimeout != null) {
window.clearTimeout(existingTimeout);
existingTimeout = null;
@nantcom
nantcom / deferResource.js
Last active February 15, 2020 14:03
Sample Script to Defer Loading Resources
var delayStack = 100;
window.deferCSS = function (url) {
var link = document.createElement('link');
link.rel = 'stylesheet';
link.href = url;
link.type = 'text/css';
@nantcom
nantcom / getbathtext.js
Last active April 29, 2020 04:37
Get Thai Baht Text using JavaScript
var getBathText = function (inputNumber) {
var getText = function (input) {
var toNumber = input.toString();
var numbers = toNumber.split('').reverse();
var numberText = "/หนึ่ง/สอง/สาม/สี่/ห้า/หก/เจ็ด/แปด/เก้า/สิบ".split('/');
var unitText = "/สิบ/ร้อย/พ้น/หมื่น/แสน/ล้าน".split('/');
var output = "";