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 / 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 / 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 / n2-notifications.1.ts
Last active May 24, 2016 11:37
ng2-notifications: getting started
import { SystemNotificationDirective } from 'ng2-notifications';
@Component({
...
directives: [SystemNotificationDirective]
})
<!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 / 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 })
);