This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<script> | |
window.addEventListener("offline", function(e) {alert("offline");}) | |
window.addEventListener("online", function(e) {alert("online");}) | |
</script> | |
</head> | |
<body> | |
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getValueFromQueryString = function(url, key) { | |
return decodeURIComponent(new RegExp('[?|&]' + key + '=' + '([^&;]+?)(&|#|;|$)').exec(url) || [,""])[1].replace(/\+/g, '%20') || null; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myFunc = function(x){return x*2;}; | |
var num = 3; | |
var array = Array.apply(null, Array(num)).map(function(){return myFunc;}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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') { | |
res.redirect(`https://${req.host}${req.url}`); | |
} | |
else { | |
next(); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fname = /^function\s+([^(]+)/.exec(arguments.callee.toString())[1]; | |
console.log(fname); | |
//alert(fname); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function reportName() { | |
var fname = /^function\s+([^(]+)/.exec(reportName.caller.toString())[1]; | |
console.log(fname); | |
} | |
function MyFunctionHAsALongName() { | |
reportName(); | |
//Do some stuff | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
hour, minute = Time.now.strftime('%I').to_i, Time.now.min | |
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]}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib2 | |
import json | |
url = '<INSERT URL>' | |
data = { | |
'aaa': '7673336666', | |
'bbb': ['4544444445','xxxxxxx','334tttt890'], | |
'ccc': { | |
'ddd': 'on', | |
'eee': 5 |
OlderNewer