Skip to content

Instantly share code, notes, and snippets.

View amowu's full-sized avatar
🧑‍💻

Amo Wu amowu

🧑‍💻
View GitHub Profile
@amowu
amowu / RxJSDragDrop.js
Last active February 17, 2017 03:10
Drag and drop with RxJS
const body = document.body;
const draggableElement = document.getElementById('drag');
const mouseDown$ = Rx.Observable.fromEvent(draggableElement, 'mousedown');
const mouseUp$ = Rx.Observable.fromEvent(body, 'mouseup');
const mouseMove$ = Rx.Observable.fromEvent(body, 'mousemove');
mouseDown$
.map(event => mouseMove$.takeUntil(mouseUp$))
.concatAll()
@mixin for-size($range) {
$phone-upper-boundary: 600px;
$tablet-portrait-upper-boundary: 900px;
$tablet-landscape-upper-boundary: 1200px;
$desktop-upper-boundary: 1800px;
@if $range == phone-only {
@media (max-width: #{$phone-upper-boundary - 1}) { @content; }
} @else if $range == tablet-portrait-up {
@media (min-width: $phone-upper-boundary) { @content; }
@amowu
amowu / functional-programming.md
Created January 15, 2017 09:02
Functional Programming
@amowu
amowu / frozen-objects.js
Created January 15, 2017 08:38 — forked from ericelliott/frozen-objects.js
Frozen object
const a = Object.freeze({
foo: 'Hello',
bar: 'world',
baz: '!'
});
a.foo = 'Goodbye';
// Error: Cannot assign to read only property 'foo' of object Object
@amowu
amowu / isSupportEmoji.js
Created January 2, 2017 08:50
如何判断当前浏览器是否支持某一个 emoji
const getTextFeature = (text, color) => {
try {
const canvas = document.createElement('canvas');
/*
因为进行scale以后的图案区域实际上不能确定,
理论上应该只在(0,0,1,1),但有的也会在它周围的像素里,
综合效率的考虑,给一个2*2的范围是比较合适的;
*/
canvas.width = 2;
canvas.height = 2;
@amowu
amowu / customIEEvent.js
Created December 14, 2016 09:47
Custom mouse event data on IE
var event = document.createEvent('MouseEvent');
var args = ['click', true, true];
event.data = { 'foo': 'bar' };
event.initEvent.apply(event, args);
element.dispatchEvent(event);
@amowu
amowu / container.js
Created October 31, 2016 06:08
Container
var Container = function (x) {
this.__value = x;
};
Container.of = function (x) {
return new Container(x);
};
Container.of(3);
@amowu
amowu / compose.js
Created October 30, 2016 08:45
Compose
var compose = function (f, g) {
return function (x) {
return f(g(x));
};
};
var toUpperCase = x => x.toUpperCase();
var exclaim = x => x + '!';
var shout = compose(exclaim, toUpperCase);
@amowu
amowu / curry.js
Created October 30, 2016 08:13
Curry
var curry = _.curry;
var match = curry((what, str) => str.match(what));
var replace = curry((what, replacement, str) => str.replace(what, replacement));
var filter = curry((f, ary) => ary.filter(f));
var map = curry((f, ary) => ary.map(f));
match(/\s+/g, 'hello world');
// [" "]
match(/\s+/g)('hello world');
@amowu
amowu / zindex.scss
Created October 24, 2016 02:03
z-index management
// | ------------- | ------------ | ------------------------------------------ |
// | z-index range | content type | details |
// | ------------- | ------------ | ------------------------------------------ |
// | < 0 | Background | |
// | | Elements | |
// | ------------- | ------------ | ------------------------------------------ |
// | 0 - 4,999 | Main Content | Standard ad tags in place with regular |
// | | Standard Ads | content. Includes OBA Self Regulation |
// | | | Message (CLEAR Ad Notice) |
// | ------------- | ------------ | ------------------------------------------ |