http://www.regular-expressions.info/lookaround.html
Lookahead means look forwards (to the right)
If the regex is x(?=insert_regex_here), which is positive look ahead, that means "find an x that is followed by insert_regex_here".
If the regex is x(?!insert_regex_here), which is negative look ahead, that means "find an x that is not followed by insert_regex_here".
Lookbehind means look backwards (to the left)
If the regex is (?<=insert_regex_here)x, which is positive look behind, that means "find an x that is preceded by insert_regex_here".
If the regex is (?<!insert_regex_here)x, which is negative look behind, that means "find an x not preceded by insert_regex_here"
The above (?= (?! (?<= (?<! etc are Perl regex syntax - the syntax might be slightly different depending on your flavour of regex. You can also use https://regex101.com/ to play around these two concepts in RegExp.
Monday, August 28, 2017
Tuesday, August 22, 2017
2017 IRA and 401k Contribution Limit
A 403(b) is a retirement plan offered by certain public institutions and tax-exempt organizations.
A 401(k) plan is the tax-qualified, defined-contribution pension account defined in subsection 401(k) of the Internal Revenue Code.
A 457 plan is a type of nonqualified, tax advantaged deferred-compensation retirement plan that is available for governmental and certain non-governmental employers in the United States.
A traditional IRA is a way to save for retirement that gives you tax advantages. Contributions you make to a traditional IRA may be fully or partially deductible, depending on your circumstances, and Generally, amounts in your traditional IRA (including earnings and gains) are not taxed until distributed.
A Roth IRA (individual retirement account) is a retirement plan under US law that is generally not taxed, provided certain conditions are met.
A SIMPLE IRA plan (Savings Incentive Match PLan for Employees) allows employees and employers to contribute to traditional IRAs set up for employees. It is ideally suited as a start-up retirement savings plan for small employers not currently sponsoring a retirement plan.
A SIMPLE 401K plan is a subset of the 401(k) plan. Just like the SIMPLE IRA plan, this is a plan just for you: the small business owner with 100 or fewer employees.
Friday, August 11, 2017
Javascript Keyboard events
Events & event values
There are keydown, keypress, and keyup events. For most keys, browser dispatches a sequence of key events like this:
Using this kind of tool, we can quickly detect the keyCode, which, charCode values from keydown, keypress and keyup events.
Cross browser compatibility
Different Keyboard Layouts
There are keydown, keypress, and keyup events. For most keys, browser dispatches a sequence of key events like this:
- When the key is first depressed, the keydown event is sent.
- If the key is not a modifier key, the keypress event is sent.
- When the user releases the key, the keyup event is sent.
In the event object, event.which, event.keyCode and event.charCode are more relating to Javascript programming.
There is some online testing tool for these keyboard events, for instance
Using this kind of tool, we can quickly detect the keyCode, which, charCode values from keydown, keypress and keyup events.
Cross browser compatibility
However, different browsers might return different keyCode for same character. For instance, IE/Edge browser returns 229 but Chrome/Firefox returns 50 keyCode from keydown event. If we look at below comparison figure, same browser returns different keyCode value from different keyboard events. One example here is: keypress event, for same @ char, chrome returns 64 keyCode, but Firefox returns 0 keyCode.
Fortunately, jQuery normalize browser difference for keyCode etc. Further more, jQuery recommends event.which over event.keyCode and event.charCode keyboard events.
http://api.jquery.com/event.which/
http://api.jquery.com/event.which/
The event.which property normalizes event.keyCode and event.charCode. It is recommended to watch event.which for keyboard key input.
event.which also normalizes button presses (mousedown and mouseupevents), reporting 1 for left button, 2 for middle, and 3 for right. Use event.which instead of event.button.
MDN (Mozilla Developer Network) has the following note:
In a keypress event, the Unicode value of the key pressed is stored in either the keyCode or charCode property, never both. If the key pressed generates a character (e.g. 'a'), charCode is set to the code of that character, respecting the letter case. (i.e. charCode takes into account whether the shift key is held down). Otherwise, the code of the pressed key is stored in keyCode. charCode is never set in the keydown and keyup events. In these cases, keyCode is set instead.
http://unixpapa.com/js/key.html gives more details regarding keyboard events compatibility landscape across different browsers.
Different Keyboard Layouts
Same character might have different keyCode when using foreign keyboard layouts
Stackoverflow gives some simple solution as below for different keyboard layouts compatiblity:
Use onkeypress to ascertain the correct character code for the key that was pressed. In the event handler, check the event.which and event.keyCode properties:
function whichKey(evt) {
alert(String.fromCharCode(evt.which || evt.keyCode));
}
KeyboardEvent.key to the rescue?
Model browsers start to support KeyboardEvent.key which should be used to replace charCode etc.
The definition of 'KeyboardEvent.key' is in "Document Object Model (DOM) Level 3 Events Specification" Working Draft (as of August 2017).
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/key
http://caniuse.com/#feat=keyboardevent-key
Apart from Android browsers, IE11/Edge, other modern browsers have support event.key.
Conclusion
Apart from Android browsers, IE11/Edge, other modern browsers have support event.key.
Conclusion
Explore event.key if your web app doesn't need to support legacy browsers.
Use event.which, event.keyCode, and event.charCode wisely in different keyboard events.
Use event.which, event.keyCode, and event.charCode wisely in different keyboard events.
Subscribe to:
Posts (Atom)

