Tiny Cross-browser DOM ready function in 111 bytes of JavaScript.
1. Class selector - .<classname> | |
2. Id selector - #<id> | |
3. Scope selector - .<classname><space>.<dusra_classname> | |
4. Immediate child selector - .<classname>">".<child_classname> | |
5. Attribute selector - [<attributename>='<value>'] OR [<attributename>] | |
6. Tag selector - "<tagname>" | |
7. DOM element - Directly pass the element to jquery function | |
8. Multiple element - separate selectors using <comma> |
read -d '' SLACK_PAYLOAD_DATA << EOF | |
{ | |
"channel": "#channel", | |
"username": "Bot", | |
"text": "Message by _$(id -un)@$(hostname -f)_.", | |
"icon_emoji": ":poop:", | |
"attachments": [ | |
{ | |
"fields": [ | |
{ |
<button onclick="notifyMe()"> | |
Notify me! | |
</button> | |
<script id="jsbin-javascript"> | |
// request permission on page load | |
document.addEventListener('DOMContentLoaded', function () { | |
if (Notification.permission !== "granted") | |
Notification.requestPermission(); | |
}); |
TL;DR: Use window.addEventListener(...) (see final heading)
You may want to defer execution of javascript until the DOM has loaded. For example, the following will not work.
function respondToEvent() {
...
}
#Lessons From A JavaScript Code Review
I was recently asked to review some code for a new JavaScript application and thought I might share some of the feedback I provided as it includes a mention of JavaScript fundamentals that are always useful to bear in mind. Code reviews are possibly the single biggest thing you can do to improve the overall quality of your solutions and if you're not actively taking advantage of them, you're possibly missing out on bugs you haven't noticed being found or suggestions for improvements that could make your code better.
##Challenges & Solutions
Code reviews go hand-in-hand with maintaining strong coding standards. That said, standards don't usually prevent logical errors or misunderstandings about the quirks of a programming language. Even the most experienced developers can make these kinds of mistakes and code reviews can greatly assist with catching them.
Often the most challenging part of code reviews is actually finding an experienced developer you trust to complete
console.log('Loading event'); | |
var Q = require('q'); | |
var aws = require('aws-sdk'); | |
var cloudfront = new aws.CloudFront(); | |
exports.handler = function (event, context) { | |
//_log('Received event: ', event); | |
var bucket = event.Records[0].s3.bucket.name; |
function eachAsync(collection, iterator, callback) { | |
var iterate = function(i) { | |
setTimeout(function() { | |
iterator(collection[i]); | |
if (i < collection.length) { | |
iterate(i + 1); | |
} else { | |
callback(); | |
} | |
}, 0); |
server { | |
listen 80 default_server; | |
listen [::]:80 default_server ipv6only=on; | |
server_name www.dipl.io dipl.io; | |
return 301 https://dipl.io$request_uri; | |
} | |
server { | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; |