Skip to content

Instantly share code, notes, and snippets.

View xudaolong's full-sized avatar
🎯
Focusing

Dillon Xu xudaolong

🎯
Focusing
View GitHub Profile
@kerminz
kerminz / single-page-application-1-yt.js
Last active May 8, 2019 09:01
Testen auf Single-Page-Application mit DOM Observer (YouTube)
var event = new Event('abtest');
// Listen for the event.
window.addEventListener('abtest', function (e) {
console.log("AB Test running...");
console.log("Sign In Page");
}, false);
function waitForElement(selector, target, callback) {
@ORESoftware
ORESoftware / resize-base64.js
Last active October 28, 2023 19:27
resizing an image on the front-end before sending to a server
// Using this code, we can retrieve an image from a user's filesystem, resize the image, and then upload the image
// to a server using AJAX. Because we use base64 encoding, we can just include the image data as just another string value
// in a JSON payload.
// So we can use AJAX to send the file to a server, which is convenient.
// We have one line of relevant html
// get file in the first place => <input type="file" custom-on-change="onAcqImageFileChange" class="form-control">
@adrianmcli
adrianmcli / tutorial-refactor.js
Created January 6, 2017 19:24
A refactor of André Staltz's example twitter program in his tutorial on RxJS: https://gist.github.com/staltz/868e7e9bc2a7b8c1f754
// UI Event Streams --------------------------------------------
const refreshButton = document.querySelector('.refresh');
const closeButton1 = document.querySelector('.close1');
const closeButton2 = document.querySelector('.close2');
const closeButton3 = document.querySelector('.close3');
const refreshClickStream = Rx.Observable.fromEvent(refreshButton, 'click');
const close1ClickStream = Rx.Observable.fromEvent(closeButton1, 'click');
const close2ClickStream = Rx.Observable.fromEvent(closeButton2, 'click');
const close3ClickStream = Rx.Observable.fromEvent(closeButton3, 'click');
@mxstbr
mxstbr / idea.md
Last active February 16, 2021 18:33
Code splitting react-router routes with webpack 2

NOTE: Sokra confirmed I had a misunderstanding, Webpack is still a static build tool and the below won't work. It's still a nice concept though...

With webpack 1, code splitting react-router routes is quite tedious. It requires us to repeat the getComponent function over and over again. (See here for an explanation how it works with webpack 1)

Example:

<Router history={history}>
  <Route
    path="/"
(function(win) {
'use strict';
var listeners = [],
doc = win.document,
MutationObserver = win.MutationObserver || win.WebKitMutationObserver,
observer;
function waitForElement(selector, repeat, fn) {
@JordanDelcros
JordanDelcros / combine-rgba-colors.js
Created July 31, 2015 09:55
Combine two RGBA colors with JavaScript
// Fast and easy way to combine (additive mode) two RGBA colors with JavaScript.
// [red, green, blue, alpha] based on these maximul values [255, 255, 255, 1].
var base = [69, 109, 160, 1];
var added = [61, 47, 82, 0.8];
var mix = [];
mix[3] = 1 - (1 - added[3]) * (1 - base[3]); // alpha
mix[0] = Math.round((added[0] * added[3] / mix[3]) + (base[0] * base[3] * (1 - added[3]) / mix[3])); // red
mix[1] = Math.round((added[1] * added[3] / mix[3]) + (base[1] * base[3] * (1 - added[3]) / mix[3])); // green
mix[2] = Math.round((added[2] * added[3] / mix[3]) + (base[2] * base[3] * (1 - added[3]) / mix[3])); // blue