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 / .jshintrc
Created August 13, 2014 14:50
Chrome extension .jshintrc
{
"maxerr" : 50, // {int} Maximum error before stopping
// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
@TravelingTechGuy
TravelingTechGuy / fillArray.js
Created June 17, 2014 23:54
Fill array with same value/function
var myFunc = function(x){return x*2;};
var num = 3;
var array = Array.apply(null, Array(num)).map(function(){return myFunc;});
@TravelingTechGuy
TravelingTechGuy / occurrences.js
Created June 16, 2014 04:55
Find number of occurrences of substring in string
var str = "This is a string.",
term = 'is',
reg = new RegExp(term, 'ig'); //remove the `i` if you need case-sensitivity
var count = str.match(reg).length;
console.log(count);
@TravelingTechGuy
TravelingTechGuy / getValueFromQueryString.js
Created June 10, 2014 18:39
Get value from a key in a query string
var getValueFromQueryString = function(url, key) {
return decodeURIComponent(new RegExp('[?|&]' + key + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [,""])[1].replace(/\+/g, '%20') || null;
};
@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 / 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 / online.html
Created April 1, 2014 01:20
Check if device is online
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener("offline", function(e) {alert("offline");})
window.addEventListener("online", function(e) {alert("online");})
</script>
</head>
<body>
</body>
@TravelingTechGuy
TravelingTechGuy / updateNPM.sh
Created January 29, 2014 17:36
Update (global) NPM repositories, and show which repositories were updated by comparing version numbers
npm -g ls --depth=0 > ~/before.txt
npm -g update > /dev/null 2>&1
npm -g ls --depth=0 > ~/after.txt
diff -as ~/before.txt ~/after.txt
rm ~/before.txt ~/after.txt
0 info it worked if it ends with ok
1 verbose cli [ '/opt/local/bin/node', '/opt/local/bin/npm', '-g', 'update' ]
2 info using npm@1.3.23
3 info using node@v0.10.24
4 verbose cache add [ 'express', '*' ]
5 verbose cache add name="express" spec="*" args=["express","*"]
6 verbose parsed url { protocol: null,
6 verbose parsed url slashes: null,
6 verbose parsed url auth: null,
6 verbose parsed url host: null,
@TravelingTechGuy
TravelingTechGuy / copyrightYear.html
Last active January 2, 2016 00:39
Add the current year to copyright notice/footer
<!-- Assuming you have the text &copy <span id="year"></span> in your footer -->
<!-- Without jQuery, add to bottom of page -->
<script>document.getElementById('year').textContent = (new Date()).getFullYear();</script>
<!-- If you're using jQuery, add this to $(document).ready() or $(function()) -->
$('#year').text((new Date()).getFullYear());
<!-- One line in the HTML page -->
<footer>copyright © <script>document.write((new Date()).getFullYear());</script></footer>