Skip to content

Instantly share code, notes, and snippets.

View thebeebs's full-sized avatar
🏠
Working from home

Martin Beeby thebeebs

🏠
Working from home
View GitHub Profile
<div id="app">
<button @click="disconnect" v-if="status === 'connected'">Disconnects </button>
<button @click="connect" v-if="status === 'disconnected'">Connect</button> {{ status }}
<br /><br />
<div v-if="status === 'connected'">
<form @submit.prevent="sendMessage" action="#">
<input v-model="message"><button type="submit">Send Message</button>
</form>
<ul id="logs">
<li v-for="log in logs" class="log">
@thebeebs
thebeebs / webAudio.js
Created December 20, 2016 14:16
Web Audio Example
var context= new (window.AudioContext || window.webkitAudioContext)();
var oscillator = context.createOscillator();
oscillator.frequency.value = 5000;
oscillator.start();
oscillator.connect(context.destination);
// Only be heard by those under 40
// oscillator.frequency.value = 15000;
// Only be heard by those under 18
@thebeebs
thebeebs / AsyncExample.js
Last active September 15, 2020 19:41
An example of using Async Await to create some text in a guaranteed order.
// Calling the function using promises.
addElement("first promise sexy syntax")
.then(x => addElement("second promise syntax"))
.then(x => addElement("third promise syntax"))
.then(x => addElement("fourth promise syntax"))
// Calling the function using Async/Await
async function myFunction(){
await addElement("first async");
await addElement("second async");
@thebeebs
thebeebs / designer.html
Created November 7, 2014 16:17
designer
<link href="../core-icon-button/core-icon-button.html" rel="import">
<link href="../core-toolbar/core-toolbar.html" rel="import">
<link href="../core-header-panel/core-header-panel.html" rel="import">
<link href="../topeka-elements/category-images.html" rel="import">
<link href="../core-icon/core-icon.html" rel="import">
<link href="../core-icons/core-icons.html" rel="import">
<link href="../core-icons/av-icons.html" rel="import">
<link href="../paper-fab/paper-fab.html" rel="import">
<polymer-element name="my-element">
@thebeebs
thebeebs / definitionFiles.ts
Last active August 29, 2015 13:56
TypeScript can infer meaning about the (e) parameter because of the lib.t.ds file that provides an 8000 line interface for the entire javascript runtime.
window.onmousemove = function(e) {e.clientX};
@thebeebs
thebeebs / objectInterface.ts
Created February 12, 2014 22:09
You can add an interface to an object so the miss spelling of clear() is picked up and the app will not compile.
interface Rapper {
say(x: string): void;
clear(): void;
speak(): string;
}
function makeRapper(): Rapper{
var words;
return {
say: function (x: string){
@thebeebs
thebeebs / constructorsAndIndexes.ts
Last active August 29, 2015 13:56
You can model constructors, You can model what happen when someone indexes the (thing) telling TypeScript to return a date.
interface Thing {
a: number;
b: string;
foo: {
(x: string): string;
(x: number): number;
data: any;
};
new (s: string): Element;
[index: number]: Date;
@thebeebs
thebeebs / realWorld.ts
Last active August 29, 2015 13:56
Modeling Real world JavaScript objects can be complex. Here we have added the overloads with a slightly different syntax, and have added a data object to foo.
interface Thing {
a: number;
b: string;
foo: {
(x: string): string;
(x: number): number;
data: any;
};
}
@thebeebs
thebeebs / overloads.ts
Created February 12, 2014 21:39
You can have overloads
interface Thing {
a: number;
b: string;
foo(x: string): string;
foo(x: number): string;
}
function process(x: Thing){
return x.foo(2)
}
@thebeebs
thebeebs / opFunctions.ts
Created February 12, 2014 21:34
Functions can have optional parameters too
interface Thing {
a: number;
b: string;
foo(x: string, n?: number): string;
}
function process(x: Thing){
return x.foo("string");
}