Skip to content

Instantly share code, notes, and snippets.

View alexcastillo's full-sized avatar
💭
Building an API to the brain

Alex Castillo alexcastillo

💭
Building an API to the brain
View GitHub Profile
@alexcastillo
alexcastillo / whilePageIsVisible.js
Created August 17, 2020 19:02
RxJS pipe: whilePageIsVisible
import { fromEvent, partition, pipe } from "rxjs";
import { shareReplay, takeUntil, repeatWhen } from "rxjs/operators";
// 🛑 unsubscribes when the browser tab is not active
// ✅ resubscribe when it is becomes active again
export function whilePageIsVisible() {
const visibilityChange$ = fromEvent(document, "visibilitychange").pipe(
shareReplay({ refCount: true, bufferSize: 1 })
);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Socket.io Client</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="//cdn.jsdelivr.net/socket.io-client/1.3.2/socket.io.js" />
<script>
@alexcastillo
alexcastillo / n2-notifications.1.ts
Last active May 24, 2016 11:37
ng2-notifications: getting started
import { SystemNotificationDirective } from 'ng2-notifications';
@Component({
...
directives: [SystemNotificationDirective]
})
@alexcastillo
alexcastillo / fileDirective.js
Created March 31, 2015 15:58
File Directive
angular.module('Aether').directive('onReadFile', function($parse, Constants) {
return {
restrict : 'A',
scope : false,
link : function(scope, element, attrs) {
var fn = $parse(attrs.onReadFile);
element.on('change', function(onChangeEvent) {
var file = (onChangeEvent.srcElement || onChangeEvent.target).files[0];
var reader = new FileReader();
reader.onload = function(onLoadEvent) {
@alexcastillo
alexcastillo / browserify-sample.js
Created March 30, 2015 17:52
browserify sample
{
"name": "sample-app",
"version": "0.0.1",
"description": "App Description",
"main": "js/app.js",
"dependencies": {
"underscore": "^1.7.0"
},
"devDependencies": {
"browserify": "~6.2.0",
@alexcastillo
alexcastillo / angular-css-bust-cache.js
Created January 7, 2015 12:36
AngularCSS - Bust Cache
$routeProvider
.when('/page1', {
templateUrl: 'page1/page1.html',
controller: 'page1Ctrl',
css: {
href: 'page1/page1.css',
bustCache: true
}
});
@alexcastillo
alexcastillo / angular-css-preload.js
Created January 7, 2015 12:36
AngularCSS - Preload
$routeProvider
.when('/page1', {
templateUrl: 'page1/page1.html',
controller: 'page1Ctrl',
css: {
href: 'page1/page1.css',
preload: true
}
});
@alexcastillo
alexcastillo / angular-css-persist.js
Created January 7, 2015 12:35
AngularCSS - Persist
$routeProvider
.when('/page1', {
templateUrl: 'page1/page1.html',
controller: 'page1Ctrl',
css: {
href: 'page1/page1.css',
persist: true
}
});
@alexcastillo
alexcastillo / angular-css-sqm.js
Created January 7, 2015 12:34
AngularCSS - SMQ
$routeProvider
.when('/tickets', {
templateUrl: 'tickets/tickets.html',
controller: 'ticketsCtrl',
css: [
{
href: 'tickets/tickets.mobile.css',
media: '(max-width: 480px)'
}, {
href: 'tickets/tickets.tablet.css',
@alexcastillo
alexcastillo / angular-css-directive1.js
Created January 7, 2015 12:32
AngularCSS - Directive 1
myApp.directive('itinerary', function () {
return {
restrict: 'E',
templateUrl: 'itinerary/itinerary.html',
css: 'itinerary/itinerary.css'
}
});