Skip to content

Instantly share code, notes, and snippets.

View hthuong09's full-sized avatar

Thuong (Tyson) Nguyen hthuong09

View GitHub Profile
@hthuong09
hthuong09 / gist:7e10957df5bdd5ef2e354aa5334c4e42
Created April 28, 2016 06:00 — forked from gleuch/gist:2475825
Javascript documentfragment to string (w/ text selection)
// selection range
var range = window.getSelection().getRangeAt(0);
// plain text of selected range (if you want it w/o html)
var text = window.getSelection();
// document fragment with html for selection
var fragment = range.cloneContents();
// make new element, insert document fragment, then get innerHTML!
/*
* robotMaze.js
*
* The blue key is inside a labyrinth, and extracting
* it will not be easy.
*
* It's a good thing that you're a AI expert, or
* we would have to leave empty-handed.
*/
@hthuong09
hthuong09 / gist:f9f124aef3cffa1b9aa723abfa1be4a6
Created September 26, 2016 01:57 — forked from maskit/gist:2252422
WebSocket traffic sniffer
(function () {
WebSocket.prototype._send = WebSocket.prototype.send;
WebSocket.prototype.send = function (data) {
this._send(data);
this.addEventListener('message', function (msg) {
console.log('>> ' + msg.data);
}, false);
this.send = function (data) {
this._send(data);
console.log("<< " + data);
@hthuong09
hthuong09 / b64url-np.md
Created November 14, 2019 17:58 — forked from catwell/b64url-np.md
Decoding Base64-URL without padding

Decoding Base64-URL without padding

1) Add padding

Divide the length of the input string by 4, take the remainder. If it is 2, add two = characters at the end. If it is 3, add one = character at the end.

You now have Base64-URL with padding.

2) Translate to Base64

@hthuong09
hthuong09 / introrx.md
Created January 22, 2023 05:00 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing