Skip to content

Instantly share code, notes, and snippets.

View hliyan's full-sized avatar

Hasitha N. Liyanage hliyan

View GitHub Profile
@hliyan
hliyan / svelte.md
Last active July 18, 2020 06:16
Svelte

1. Basics

<script>
	let name = 'world';
</script>

<h1>Hello {name}!</h1>
@hliyan
hliyan / post-message.html
Created July 29, 2019 11:57
Events using postMessage
<html>
<body>
<div>
<button onClick="onButton()">Hello</button>
</div>
<script>
// credit: https://dbaron.org/log/20100309-faster-timeouts
const eventQueue = [];
@hliyan
hliyan / rest-api-01.go
Created May 1, 2019 11:19
REST API in Go
package main
import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
)
const TodoTx = require('./src/app/todo-tx');
// the transmission layer *is* the app
const app = new TodoTx();
app.run();
const Emitter = require('../../lib/emitter');
const vorpal = require('vorpal');
const events = {
INIT:'init',
CREATE_TODO: 'CREATE_TODO',
GET_TODO_LIST: 'GET_TODO_LIST'
};
const constants = {
const Emitter = require('../../lib/emitter');
const events = {
INIT:'init',
CREATE_TODO: 'createTodo'
};
const constants = {
status: {
TODO: 'TODO',
@hliyan
hliyan / epc-todo-app.js
Last active November 26, 2017 04:09
epc-todo-app.js
// import the engine and shell as two independent modules
const TodoEngine = require('../engine/todo-engine');
const TodoShell = require('../shell/todo-shell');
/**
* This is the app -- it connects the business logic of the
* TodoEngine to the presentation capabilities of the TodoShell
*/
class TodoTx {
constructor() {
@hliyan
hliyan / jest-es6-setup.md
Last active November 25, 2022 13:10
Jest with ES6 imports and React

Create project and install deps

mkdir hello
cd hello

npm init
...
test command: jest --coverage
...
@hliyan
hliyan / javascript-001-prototypes-intro.md
Last active August 29, 2015 14:26
javascript-001-prototypes-intro
  • Until ECMA6, JavaScript had no classes. It had (and still has) prototypes.
  • A class is like a mold from which you build an object. A prototype is itself an object.
// think of this as the class AND its constructor
var Person = function() {
  this.canTalk = true;
};

// this is a 'class method'
@hliyan
hliyan / con1.js
Last active August 29, 2015 14:03
IndexedDB
// connectivity: ITERATION 1
var database = new Database('companydb');
database.connect(function(db) {
if (db.error) {
// handle error
}
// continue db ops
});