Skip to content

Instantly share code, notes, and snippets.

View devdays's full-sized avatar

Bruce D Kyle devdays

View GitHub Profile
@devdays
devdays / embeddedstylesheet
Created November 29, 2014 22:11
Embedded style sheet in html
<head>
<!-- other items in head -->
<style>
hr {color:sienna;}
p {margin-left:20px;}
body {color: black;}
</style>
</head>
@devdays
devdays / stylesheetinhtmlhead
Created November 29, 2014 22:14
Style sheet in Html head
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css">
</head>
@devdays
devdays / inlinestyle
Created November 29, 2014 22:16
inline style
<p style="color:sienna;margin-left:20px;">This is a paragraph.</p>
@devdays
devdays / websocket-client.html
Last active August 29, 2015 14:10
Demonstration of a Web Client connected to WebSocket
<!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 August 29, 2015 14:10
Check for WebSocket support in your browser by checking for the existence of WebSocket in the window object
function onload() {
if (window.WebSocket) {
// WebSocket supported
} else {
// WebSocket not supported
}
}
@devdays
devdays / create-check-with-websocket-server.js
Last active August 29, 2015 14:10
Create and Connect to a WebSocket Server
var wsUri = "ws://echo.websocket.org/";
var webSocket = = new WebSocket(wsUri);
@devdays
devdays / gist:a5989143e7ffb03af046
Created November 30, 2014 08:27
Add event listeners for Web Sockets
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 August 29, 2015 14:10
Verify web socket is still open
function doSend(message) {
if (websocket.readyState != WebSocket.OPEN)
return;
websocket.send(message);
}
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 August 29, 2015 14:10
Send and receive binary Blog or an ArrayBuffer depending on the value of WebSocket binaryType property
var a = new Uint8Array([8,6,7,3,5,9.0]);
websocket.send(a.buffer);