Want to create a Gist from your editor, the command line, or the Services menu? Here's how.
The MIT License (MIT) | |
Copyright (c) 2016 Stuart Powers | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
# Local Dates: | |
git log --date=local --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.local.tsv.txt | |
# ISO Dates: | |
git log --date=iso --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.iso.tsv.txt |
This article has been given a more permanent home on my blog. Also, since it was first written, the development of the Promises/A+ specification has made the original emphasis on Promises/A seem somewhat outdated.
Promises are a software abstraction that makes working with asynchronous operations much more pleasant. In the most basic definition, your code will move from continuation-passing style:
getTweetsFor("domenic", function (err, results) {
// the rest of your code goes here.
license: gpl-3.0 | |
height: 2000 | |
border: no | |
redirect: https://beta.observablehq.com/@mbostock/d3-cluster-dendrogram |
When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:
const Article = require('../../../../app/models/article');
Those suck for maintenance and they're ugly.
// Usage: mongo {Server without mongodb:// example 127.0.0.1:27017}/{DbName} [-u {Username}] [-p {Password}] < ./mongo-ls.js | |
var collections = db.getCollectionNames(); | |
print('Collections inside the db:'); | |
for(var i = 0; i < collections.length; i++){ | |
var name = collections[i]; | |
if(name.substr(0, 6) != 'system') | |
print(name + ' - ' + db[name].count() + ' records'); |
WebSockets is a modern HTML5 standard which makes communication between client and server a lot more simpler than ever. We are all familiar with the technology of sockets. Sockets have been fundamental to network communication for a long time but usually the communication over the browser has been restricted. The general restrictions
- The server used to have a permanent listener while the client (aka browser) was not designated any fixed listener for a more long term connection. Hence, every communication was restricted to the client demanding and the server responding.
- This meant that unless the client requested for a particular resource, the server was unable to push such a resource to the client.
- This was detrimental since the client is then forced to check with the server at regular intervals. This meant a lot of libraries focused on optimizing asynchronous calls and identifying the response of asynchronous calls. Notably t
function downloadString(text, fileType, fileName) { | |
var blob = new Blob([text], { type: fileType }); | |
var a = document.createElement('a'); | |
a.download = fileName; | |
a.href = URL.createObjectURL(blob); | |
a.dataset.downloadurl = [fileType, a.download, a.href].join(':'); | |
a.style.display = "none"; | |
document.body.appendChild(a); | |
a.click(); |
/* | |
In a fairly typical webapp data model you often want to send | |
the client different "views" of the data model. | |
Many database and caching tools require the base model to be quite | |
standard with json tags and types, so the following approach is | |
ideal: | |
Based on this blog post and SO question: |