Skip to content

Instantly share code, notes, and snippets.

View Tolsee's full-sized avatar
🎯
Focusing

Tolsee Tolsee

🎯
Focusing
View GitHub Profile

Keybase proof

I hereby claim:

  • I am tolsee on github.
  • I am tsapkota (https://keybase.io/tsapkota) on keybase.
  • I have a public key ASB-OD-1ebRgiVNGqXXczxaVC2wGEHOxNx_3dgm3danwMQo

To claim this, I am signing this object:

@Tolsee
Tolsee / spinner.js
Last active August 9, 2018 06:12
Cli spinner
const Spinner = require('cli-spinner').Spinner;
// Create a spinner
const spinner = new Spinner('Syncing data.. %s');
// Set a string, that shows loding and replaced with %s in above declaration
spinner.setSpinnerString('▖▘▝▗');
// Now you can start spinner when ever you want
// For our case before http request
@Tolsee
Tolsee / googleApi.js
Last active August 9, 2018 04:52
Node google calendar api
const {google} = require('googleapis');
const calendar = google.calendar({
version: 'v3',
auth: oauth2Client
});
const res = await calendar.events.list({
calendarId: 'primary',
maxResults: 10
});
@Tolsee
Tolsee / listWithSpinner.js
Created August 9, 2018 04:46
Adding spinner to list command
gEvent
.command('list')
.option('-f, --from [date]', 'Get events from the date[chrono based date parsing]')
.option('-t, --to [date]', 'Get events until the date[chrono based date parsing]')
.option('-r, --results <events>', 'Number of events to show')
.description('List google event')
.action(async function(args, callback) {
const spinner = new Spinner('Syncing data.. %s');
spinner.setSpinnerString('▖▘▝▗');
spinner.start();
@Tolsee
Tolsee / createCommand.js
Created August 9, 2018 04:45
Create google events
gEvent
.command('create [summary...]')
.option('-s, --start [date]', 'Set start date[chrono based date parsing]')
.option('-e, --end [date]', 'Set end date[chrono based date parsing]')
.option('-l, --location [eventLocation]', 'Set location of the event')
.option('--notify', 'Notify me about the event')
.validate(function (args) {
if (!args.options.start) {
return 'start date is missing';
} else if (!args.options.end) {
gEvent
.command('list')
.option('-f, --from [date]', 'Get events from the date[chrono based date parsing]')
.option('-t, --to [date]', 'Get events until the date [chrono based date parsing]')
.option('-r, --results <events>', 'Number of events to show')
.description('List google event')
.action(async function(args, callback) {
const calender = google.calendar({
version: 'v3',
auth: oauth2Client
@Tolsee
Tolsee / listCommandStart.js
Created August 9, 2018 04:43
List command for google calendar events.
gEvent
.command('list [date...]')
.description('List google event')
.action(async function(args, callback) {
const calendar = google.calendar({
version: 'v3',
auth: oauth2Client
});
const res = await calendar.events.list({
calendarId: 'primary',
@Tolsee
Tolsee / vorpalStarter.js
Created August 9, 2018 04:35
A starter command line tool, written in vorpal.js
const vorpal = require('vorpal')();
vorpal
.command('say [words...]')
.description('Echo what you type')
.action(function (args, callback) {
this.log(args.words.join(' '));
callback();
});
vorpal
.delimiter('echo $')
@Tolsee
Tolsee / indexWithConfig.js
Created August 9, 2018 04:34
Authenticate with google calendar and store token for next use.
const gEvent = require('vorpal')();
const {google} = require('googleapis');
const opn = require('opn');
const utils = require('./utils');
const CLIENT_ID = 'GOOGLE_CLIENT_ID';
const CLIENT_SECRET = 'GOOGLE_CLIENT_SECRET';
const REDIRECT_URL = 'urn:ietf:wg:oauth:2.0:oob';
@Tolsee
Tolsee / storeConfig.js
Created August 9, 2018 04:32
Read, write operation in json file.
const fs = require('fs');
const path = require('path');
const readConfig = () => {
const rawConfig = fs.readFileSync(path.join(__dirname, 'config.json'), 'utf8');
return JSON.parse(rawConfig);
};
module.exports.readConfig = readConfig;