Skip to content

Instantly share code, notes, and snippets.

View pH200's full-sized avatar

pH pH200

  • Cytisan Software
  • Taipei, Taiwan
View GitHub Profile
@pH200
pH200 / sleep.ps1
Created November 19, 2018 19:22
Trigger IFTTT webhooks if the device goes into sleep mode
# Turn of all lights when your PC goes to sleep
#
# If {Webhooks receive a web request} then {Philips Hue turn off lights}
# https://ifttt.com
# Change $hook, $from and $to of your preference.
$hook = 'https://maker.ifttt.com/trigger/{event}/with/key/{key}'
$from = '00:00'
$to = '06:00'
@pH200
pH200 / index.html
Created April 27, 2016 02:17
Illustration of some issue with cycle-react + react-router
<html>
<head>
<title>RxJs+Cycle-React</title>
</head>
<body>
<div id='root'>
</div>
</body>
<script src="/index.js"></script>
</html>
@pH200
pH200 / cycle.js
Last active July 6, 2017 05:30
Small Todo by using Cycle.js
import Cycle, {Rx, h} from 'cyclejs';
Cycle.registerCustomElement('TodoList', (rootElem$, props) => {
let vtree$ = props.get('items$').map(items =>
h('div', h('ul', items.map((itemText, index) =>
h('li', { key: index + itemText }, itemText)))));
rootElem$.inject(vtree$);
});
let vtree$ = Cycle.createStream(function (interaction$) {
@pH200
pH200 / gist:6a3afc687195d3194369
Created April 23, 2015 11:56
Cycle.js mutable collection
import Cycle, {Rx, h} from 'cyclejs';
Cycle.registerCustomElement('x-element', function (rootElem$, props) {
let vtree$ = props.get('list$').map((list) =>
h('div', null, [
h('ol', list.map((value) => h('li', null, value)))
]));
rootElem$.inject(vtree$);
});
@pH200
pH200 / gist:21a78e99408a650062c5
Created November 16, 2014 09:17
Image size getter
function imageSizeGetter(image: HTMLImageElement, callback: (size:[number, number]) => any): void {
if (image.width > 0 && image.height > 0) {
callback([image.width, image.height]);
} else {
var observer = new MutationObserver(function (record) {
observer.disconnect();
callback([image.width, image.height]);
});
observer.observe(image, {
attributes: true,
@pH200
pH200 / gist:4474bf7d8d2075c56317
Last active March 29, 2017 02:46
RxJS for full screen image resizing
var gestureObservable = Rx.Observable.createWithDisposable(function (observer) {
var gesture = new MSGesture();
gesture.target = gestureTarget;
var pointerSub = Rx.Observable.fromEvent(gestureTarget, "pointerdown")
.subscribe((ev: any) => gesture.addPointer(ev.pointerId));
var gestureSub = Rx.Observable.fromEvent(gestureTarget, "MSGestureTap")
.subscribe((ev: MSGestureEvent) => observer.onNext(ev));
return new Rx.CompositeDisposable(
pointerSub,
@pH200
pH200 / gist:6946429
Last active December 25, 2015 08:28
coke concurrent promises
find_all_user_emails : function ( count, next ){
var i = Math.ceil( count / 10000 );
var skip = 0;
var promises = [];
for( ; i-- ; ){
promises.push( User.
find({ is_verified : true })
lean().
select( 'email' ).
@pH200
pH200 / promise.js
Last active December 24, 2015 01:29
coke promise
build_assets : function ( config, promise, type, tmp_dir ){
var self = this;
var path = config.path[ type ];
var assets = config[ type ];
return promise.all( Object.keys( assets ).map( function ( group ){
var input = assets[ group ].site ? assets[ group ].site.map( function ( asset ){
return self.pub_dir + path + '/' + asset + '.' + type;
}) : [];
@pH200
pH200 / gist:6713317
Last active December 23, 2015 23:59
q parallel example 2
var Q = require( 'q' );
var overwrite_array = function ( source, array ){
var result = source.slice( 0 );
Array.prototype.splice.apply( result, [ 0, array.length ].concat( array ));
return result;
};
var xyz = [ 5, 6, 7 ];
@pH200
pH200 / gist:6713146
Last active December 23, 2015 23:49
q parallel example
var Q = require( 'q' );
var xyz = { x : 5, y : 6, z : 7 };
Q.all([
// simulates a time consuming io operation
Q.delay( 200 ).then( function (){
console.log( 'first task ---------------' );
console.log( 'x : ' + xyz.x );