Skip to content

Instantly share code, notes, and snippets.

Avatar

Bruce D Kyle devdays

View GitHub Profile
@devdays
devdays / embeddedstylesheet
Created Nov 29, 2014
Embedded style sheet in html
View embeddedstylesheet
<head>
<!-- other items in head -->
<style>
hr {color:sienna;}
p {margin-left:20px;}
body {color: black;}
</style>
</head>
@devdays
devdays / stylesheetinhtmlhead
Created Nov 29, 2014
Style sheet in Html head
View stylesheetinhtmlhead
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
View inlinestyle
<p style="color:sienna;margin-left:20px;">This is a paragraph.</p>
@devdays
devdays / websocket-client.html
Last active Aug 29, 2015
Demonstration of a Web Client connected to WebSocket
View websocket-client.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script type="text/javascript">
var wsUri = "ws://echo.websocket.org/";
var output;
var socket;
@devdays
devdays / check-for-web-socket-support.js
Last active Aug 29, 2015
Check for WebSocket support in your browser by checking for the existence of WebSocket in the window object
View check-for-web-socket-support.js
function onload() {
if (window.WebSocket) {
// WebSocket supported
} else {
// WebSocket not supported
}
}
@devdays
devdays / create-check-with-websocket-server.js
Last active Aug 29, 2015
Create and Connect to a WebSocket Server
View create-check-with-websocket-server.js
var wsUri = "ws://echo.websocket.org/";
var webSocket = = new WebSocket(wsUri);
@devdays
devdays / gist:a5989143e7ffb03af046
Created Nov 30, 2014
Add event listeners for Web Sockets
View gist:a5989143e7ffb03af046
websocket.onopen = function (evt) { onOpen(evt) };
websocket.onclose = function (evt) { onClose(evt) };
websocket.onmessage = function (evt) { onMessage(evt) };
websocket.onerror = function (evt) { onError(evt) };
@devdays
devdays / verify-opsn-web-socket.js
Last active Aug 29, 2015
Verify web socket is still open
View verify-opsn-web-socket.js
function doSend(message) {
if (websocket.readyState != WebSocket.OPEN)
return;
websocket.send(message);
}
View send-a-canvas-using-websockets.js
function sendBinaryMessage() {
if (websocket.readyState != WebSocket.OPEN)
return;
var sourceCanvas = document.getElementById('source');
// msToBlob returns a blob object from a canvas image or drawing
websocket.send(sourceCanvas.toBlob());
// ...
@devdays
devdays / send-array-using-websocket.js
Last active Aug 29, 2015
Send and receive binary Blog or an ArrayBuffer depending on the value of WebSocket binaryType property
View send-array-using-websocket.js
var a = new Uint8Array([8,6,7,3,5,9.0]);
websocket.send(a.buffer);