Skip to content

Instantly share code, notes, and snippets.

View dixonsiu's full-sized avatar

Dixon Siu dixonsiu

View GitHub Profile
@dixonsiu
dixonsiu / pandoc_filter_procedures.md
Last active June 9, 2021 01:15
How to convert markdown link to html using Pandoc

How to convert markdown link to html using Pandoc

Issue

Pandoc cannot convert a link's URL as expected.
Markdown:

[Document](./document.md)

HTML:

Document

For my testing environment

Add

  1. Calorie Smile

    mklink /D Y:\Apache24\htdocs\hn-app-genki__\src Z:\K5\Personium\forked\calorie-smile-app\src

  2. UnitManager

    mklink /D Y:\Apache24\htdocs\unit-manager Z:\K5\Personium\forked\unit-manager\src

@dixonsiu
dixonsiu / change_attr.md
Created August 3, 2017 04:41
i18next tips

Issue

When message/label is translated and written directly to the HTML tag, switching to other language will not re-translate such HTML tag.

Wrong way

  1. Execute the following JavaScript to put English message.

     $('dispMsg').html(i18next.t("msg.error.fileNotFound");
    
  2. Result.

$('dispMsg').html(i18next.t("msg.error.fileNotFound");
@dixonsiu
dixonsiu / convert_link.py
Last active April 27, 2021 20:22
Python scripts for Pandoc
@dixonsiu
dixonsiu / sample.js
Created August 4, 2017 05:59
Look up special cookie instead of i18next to avoid conflicting settings in same domain
i18next
.use(i18nextXHRBackend)
.use(i18nextBrowserLanguageDetector)
.init({
detection: {
lookupCookie: "i18nextFujitsu"
},
fallbackLng: 'en',
debug: true,
backend: {
@dixonsiu
dixonsiu / passing_options_to_localize.md
Created August 21, 2017 08:01
Proper way to translate sentence with variable

Modifying element's attribute does not work.

    is.displaySearchResult = function(count) {
        $('#searchResult')
            .attr("data-i18n", "candidateFilter:searchResult")
            .attr("data-i18n-options", '{ "count": ' + count + ' }')
            .localize();
    };

Passing the data-i18n-options as options of localize.

@dixonsiu
dixonsiu / i18next_tips.md
Created August 24, 2017 23:57
Make sure you specify "[html]" when assigning "data-i18n" attribute to avoid escaped characters!!

I have defined the following strings.

var sTerm="2017/08/01";
var eTerm="2017/09/01";

The following will produce escaped "/" as "/".

$("#refSearchTerm").attr("data-i18n","glossary:survey.surveyPeriod").localize({ startDate: sTerm, endDate: eTerm });

2017/08/01 ~ 2017/09/01
@dixonsiu
dixonsiu / check_input.js
Created September 4, 2017 02:10
Using underscore.js methods to make validation logic simplier
function checkInput(id, msgId) {
/*
* someFieldsMissingValue is true if at least one input element's value is empty
*/
var someFieldsMissingValue = _.some(
$("form input"),
function(aDom) {
return _.isEmpty($(aDom).val());
}
);
@dixonsiu
dixonsiu / validate.js
Created September 7, 2017 02:28
Validate a field and raise error according to length, character types, etc.
function validateCheck(displayNameID, formFieldMsgId) {
var displayName = $("#" + displayNameID).val();
var MINLENGTH = 1;
var MAXLENGTH = 128;
var allowedLetters = /^[0-9a-zA-Z-_]+$/;
var lenDisplayName = displayName.length;
$("#" + formFieldMsgId).empty();
if(lenDisplayName < MINLENGTH || displayName == undefined || displayName == null || displayName == "") {
$("#" + formFieldMsgId).html(i18next.t("create_form.validate.warning.less_minimum_length", { value: MINLENGTH}));