Skip to content

Instantly share code, notes, and snippets.

View hliyan's full-sized avatar

Hasitha N. Liyanage hliyan

View GitHub Profile
@hliyan
hliyan / gasp1.js
Created March 9, 2014 14:57
GASP basics
// how to use GASP
var sheet = $('sheet1');
var range1 = $('sheet1', 'A5');
var range2 = $('sheet1', 1, 2);
var range3 = $('sheet1', 1, 1, 5, 5); // a 5 x 5 grid
var range4 = $(sheet, 'A5'); // same as range1, but with sheet already known
$.sheet = sheet; // you can even set the sheet context
var range5 = $(1, 2); // same as range 2
var range6 = $(1, 1, 5, 5); // same as range 3
@hliyan
hliyan / gaga1.js
Last active August 29, 2015 13:57
Github API for Google Apps
// how to use GAGA
var data = $git.token('<your github token here>')
.org('hliyan')
.project('enterprise')
.milestone(1)
.status('open+closed')
.fetch('issues', true); // true: returns GitIssue objects, false: raw data
for (var i = 0; i < data.length; i++) {
var issue = data[i];
@hliyan
hliyan / magpie.js
Created March 11, 2014 05:07
Magpie init
magpie = include.magpie; // use the library identifer instead of 'include' if it's different
include.$db.set(ScriptDb.getMyDb()); // Magpie will use the spreadsheet's database
// this will create the Magpie menubar items
function onOpen() {
magpie.onOpen();
};
// this will run when you select Magpie > Update
// and once every hour
@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
});
@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'
const Emitter = require('../../lib/emitter');
const events = {
INIT:'init',
CREATE_TODO: 'createTodo'
};
const constants = {
status: {
TODO: 'TODO',
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 = {
@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() {
const TodoTx = require('./src/app/todo-tx');
// the transmission layer *is* the app
const app = new TodoTx();
app.run();
@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"
)