Skip to content

Instantly share code, notes, and snippets.

@khle
khle / index.html
Created January 26, 2016 05:42
CycleSocket Chat index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Cycle Socket Chat - khle"/>
<link rel="stylesheet" href="http://fonts.googleapis.com/icon?family=Material+Icons">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.5/css/materialize.min.css">
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<title>Cycle Socket Chat - khle</title>
@khle
khle / webpack.config.js
Created January 26, 2016 05:52
CycleSocket Chat webpack.config.js
module.exports = {
entry: './src/main.js',
output: {
filename: './dist/bundle.js'
},
devtool: 'source-map',
module: {
loaders: [
{
test : /.js$/,
@khle
khle / main.js
Last active February 3, 2016 02:58
CycleSocket Chat main.js
import {Observable} from 'rx';
import {run} from '@cycle/core';
import {h4, h2, div, label, nav, a, makeDOMDriver} from '@cycle/dom';
import {appBar} from './appBar.js';
import {chatPane} from './chatPane.js';
import {presencePane} from './presencePane.js';
import {textEntryView} from './textEntry.js';
function view(DOMSource) {
@khle
khle / appBar.js
Created January 28, 2016 05:33
CycleSocket Chat appBar.js
import {Observable} from 'rx';
import {h2, div, label, nav, a} from '@cycle/dom';
export function appBar({DOM}) {
let vdom$ = Observable.of(
div('navbar-fixed', [
nav([
div('nav-wrapper', [
a({className: 'brand-logo center', href: '#'}, 'Cycle Socket Chat'),
])
@khle
khle / chatPane.js
Created January 28, 2016 05:35
CycleSocket Chat chatPane.js
import {Observable} from 'rx';
import {h4, div, ul, li, span, p, input, label, a, i} from '@cycle/dom';
export function chatPane({DOM}) {
let vdom$ = Observable.of(
div([
h4('Chat Messages'),
div({className: 'row'}, [
div({className: 'input-field col s10'}, [
@khle
khle / presencePane.js
Created January 28, 2016 05:37
CycleSocket Chat presencePane.js
import {Observable} from 'rx';
import {h4, div, table, thead, tbody, th, tr, td} from '@cycle/dom';
export function presencePane({DOM}) {
let vdom$ = Observable.of(
div([
h4('Active Users'),
table({className: 'striped'}, [
thead([
tr([
import {Observable} from 'rx';
export function textEntryIntentWithSendButtonClicked(DOMSource) {
const textStream$ = DOMSource.select('#input-msg').events('keyup').map(e => e.target);
const buttonClick$ = DOMSource.select('#send-btn').events('click').map(e => e.target);
return {textStream$, buttonClick$};
}
export function textEntryIntentWithEnterKeyPressed(DOMSource) {
@khle
khle / main.js
Last active February 3, 2016 12:03
main.js
...
import {textEntryIntentWithEnterKeyPressed} from './textEntry.js';
import {textEntryIntentWithSendButtonClicked} from './textEntry.js';
function intentWithSendButtonClicked(DOMSource) {
const {textStream$, buttonClick$} = textEntryIntentWithSendButtonClicked(DOMSource);
return buttonClick$.withLatestFrom(textStream$, (buttonClick, textStream) => {
return textStream;
});
@khle
khle / server.js
Created February 25, 2016 01:38
server.js
var express = require('express'),
app = express(),
fs = require('fs'),
aad = require('azure-ad-jwt');
app.get('/books', function(req, res) {
var audience = 'http://samplewebservice.azure-mobile.net'
var authorization = req.headers['authorization']
if (authorization) {
var bearer = authorization.split(" ");
@khle
khle / gettoken
Last active February 29, 2016 06:10
Get Access Token
curl -X POST --data "grant_type=client_credentials&resource=https://graph.windows.net&client_id=http://samplewebservice.azure-mobile.net&client_secret=[which is also called keys in AAD portal]&scope=Directory.ReadWrite.All" https://login.microsoftonline.com/your-tenant.onmicrosoft.com/oauth2/token