Skip to content

Instantly share code, notes, and snippets.

View TravelingTechGuy's full-sized 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 14:10
Get your Chrome history as a CSV file
#!/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 / ChromeExtensionGulp.js
Created April 5, 2014 19:22
Gulp file for building a Chrome Extension
'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 / defaultparams.js
Last active January 12, 2023 19:22
Demonstrates taking an object parameters, with default values
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 / Object2QS.js
Last active September 28, 2022 07:19
JSON object to query string (using underscore/lodash)
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 / await-delay.js
Last active March 4, 2019 23:44
A delay function that can be used with async-await
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 August 1, 2011 05:01
Using SQLite from Node.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 October 21, 2017 19:10
Use `fetch` with `async` and `await`
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 / bypass-should-eslint-error.js
Created June 12, 2015 15:33
Bypass ESLint no-unused-vars error for Should in a Mocha test
// 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 March 14, 2017 21:14
Ensure an array contains unique elements, using a Set
let arr = [2, 3, 5, 2, 1, 3];
arr = [...new Set(arr)]; //arr now contains [2, 3, 5, 1]

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: