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 / .jshintrc
Created Aug 13, 2014
Chrome extension .jshintrc
View .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 Jun 17, 2014
Fill array with same value/function
View fillArray.js
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 Jun 16, 2014
Find number of occurrences of substring in string
View occurrences.js
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 Jun 10, 2014
Get value from a key in a query string
View getValueFromQueryString.js
var getValueFromQueryString = function(url, key) {
return decodeURIComponent(new RegExp('[?|&]' + key + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [,""])[1].replace(/\+/g, '%20') || null;
};
@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 / online.html
Created Apr 1, 2014
Check if device is online
View online.html
<!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 Jan 29, 2014
Update (global) NPM repositories, and show which repositories were updated by comparing version numbers
View updateNPM.sh
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
View 4515
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 Jan 2, 2016
Add the current year to copyright notice/footer
View copyrightYear.html
<!-- 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>
You can’t perform that action at this time.