Skip to content

Instantly share code, notes, and snippets.

Looking for my next project...

Guy Vider TravelingTechGuy

Looking for my next project...
View GitHub Profile
TravelingTechGuy /
Created Jan 29, 2014
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
TravelingTechGuy / online.html
Created Apr 1, 2014
Check if device is online
View online.html
<!DOCTYPE html>
window.addEventListener("offline", function(e) {alert("offline");})
window.addEventListener("online", function(e) {alert("online");})
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 / 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;
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 / redirectToHTTPS.js
Last active Aug 29, 2015
Redirect from HTTP to HTTPS (in production)
View redirectToHTTPS.js
//redirect to https in production - add above all other routes
app.use('*', (req, res, next) => {
if(process.env.NODE_ENV !== 'development' && req.headers['x-forwarded-proto'] !== 'https') {
else {
TravelingTechGuy / DisplayJSFunctionName1.js
Created Aug 27, 2011
Display JavaScript function name
View DisplayJSFunctionName1.js
var fname = /^function\s+([^(]+)/.exec(arguments.callee.toString())[1];
TravelingTechGuy / DisplayJSFunctionName2.js
Created Aug 27, 2011
Display JavaScript function name
View DisplayJSFunctionName2.js
function reportName() {
var fname = /^function\s+([^(]+)/.exec(reportName.caller.toString())[1];
function MyFunctionHAsALongName() {
//Do some stuff
TravelingTechGuy / fuzzyclock.rb
Created Aug 27, 2011
Create a fuzzy, verbal clock
View fuzzyclock.rb
#!/usr/bin/env ruby
hour, minute ='%I').to_i,
ones = %w{ nil one two three four five six seven eight nine }
teens = %w{ ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen }
tens = %w{ nil nil twenty thirty forty fifty }
minute_str = case minute
when 0 then 'o-clock'
when 1..9 then "o-#{ones[minute]}"
TravelingTechGuy /
Created Aug 28, 2011
Test JSON service using python
import urllib2
import json
url = '<INSERT URL>'
data = {
'aaa': '7673336666',
'bbb': ['4544444445','xxxxxxx','334tttt890'],
'ccc': {
'ddd': 'on',
'eee': 5
You can’t perform that action at this time.