Skip to content

Instantly share code, notes, and snippets.

Avatar
💭
Looking for my next project...

Guy Vider TravelingTechGuy

💭
Looking for my next project...
View GitHub Profile
@TravelingTechGuy
TravelingTechGuy / get_history.sh
Created May 9, 2016
Get your Chrome history as a CSV file
View get_history.sh
#!/bin/bash
# Locate the history file in your profile, and copy it to the same folder as this script.
# On Mac: ~/Library/Application\ Support/Google/Chrome/Default/History
# On Windows: C:\Users\YOUR USER NAME\AppData\Local\Google\Chrome\User Data\Default\History
sqlite3 History <<!
.headers on
.mode csv
.output out.csv
@TravelingTechGuy
TravelingTechGuy / Object2QS.js
Last active Sep 14, 2020
JSON object to query string (using underscore/lodash)
View Object2QS.js
var objectToQueryString = function(obj) {
var qs = _.reduce(obj, function(result, value, key) {
return (!_.isNull(value) && !_.isUndefined(value)) ? (result += key + '=' + value + '&') : result;
}, '').slice(0, -1);
return qs;
};
@TravelingTechGuy
TravelingTechGuy / ChromeExtensionGulp.js
Created Apr 5, 2014
Gulp file for building a Chrome Extension
View ChromeExtensionGulp.js
'use strict';
//npm install gulp gulp-minify-css gulp-uglify gulp-clean gulp-cleanhtml gulp-jshint gulp-strip-debug gulp-zip --save-dev
var gulp = require('gulp'),
clean = require('gulp-clean'),
cleanhtml = require('gulp-cleanhtml'),
minifycss = require('gulp-minify-css'),
jshint = require('gulp-jshint'),
stripdebug = require('gulp-strip-debug'),
@TravelingTechGuy
TravelingTechGuy / await-delay.js
Last active Mar 4, 2019
A delay function that can be used with async-await
View await-delay.js
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
// Sample code using `delay`
const test = async () => {
const time = () => console.log((new Date).toLocaleTimeString());
time();
await delay(1000);
time();
await delay(3000);
time();
@TravelingTechGuy
TravelingTechGuy / NodeSqlite.js
Created Aug 1, 2011
Using SQLite from Node.js
View NodeSqlite.js
var sqlite3 = require('sqlite3').verbose();
var db = new sqlite3.Database('guy.sqlite'); //':memory:'
db.serialize(function() {
db.get("SELECT name FROM sqlite_master WHERE type='table' AND name='lorem'", function(error, row) {
if (row !== undefined) {
console.log("table exists. cleaning existing records");
db.run("DELETE FROM lorem", function(error) {
if (error)
console.log(error);
@TravelingTechGuy
TravelingTechGuy / fetch.js
Created Oct 21, 2017
Use `fetch` with `async` and `await`
View fetch.js
let getJson = async url => {
try {
let response = await fetch(url);
let json = await response.json();
return json;
}
catch(ex) {
//throw ex; //may want to handle externally
console.error(ex);
}
@TravelingTechGuy
TravelingTechGuy / defaultparams.js
Created Oct 21, 2017
Demonstrates taking an object parameters, with default values
View defaultparams.js
let foo = ({param1 = 1, param2 = 2, param3 = 3} = {}) => {
return (param1 + param2) / param3;
};
console.log(foo()); //returns 1
console.log(foo({param3: 1})); //returns 3
console.log(foo({param1: 7, param2: 2})); //returns 3
console.log(foo({param1: 6, param3: 2})); //returns 4
@TravelingTechGuy
TravelingTechGuy / bypass-should-eslint-error.js
Created Jun 12, 2015
Bypass ESLint no-unused-vars error for Should in a Mocha test
View bypass-should-eslint-error.js
// Without line 9 hack, linting the file throws: 5:4 error should is defined but never used no-unused-vars
'use strict';
var debug = require('debug')('test:myModel');
var should = require('should');
var security = require('../models/myModel');
before((done) => {
should; //bypass ESLint no-unused-var error
done();
@TravelingTechGuy
TravelingTechGuy / ensureUnique.js
Created Mar 14, 2017
Ensure an array contains unique elements, using a Set
View ensureUnique.js
let arr = [2, 3, 5, 2, 1, 3];
arr = [...new Set(arr)]; //arr now contains [2, 3, 5, 1]
View keybase.md

Keybase proof

I hereby claim:

  • I am travelingtechguy on github.
  • I am travelingtechguy (https://keybase.io/travelingtechguy) on keybase.
  • I have a public key whose fingerprint is 518E C8E2 5D29 429C C77A 810A 5861 AB01 E38A 8CA4

To claim this, I am signing this object:

You can’t perform that action at this time.