Skip to content

Instantly share code, notes, and snippets.

View YashdalfTheGray's full-sized avatar
🔥
On a hot streak

Yash Kulshrestha YashdalfTheGray

🔥
On a hot streak
View GitHub Profile
@YashdalfTheGray
YashdalfTheGray / osx-10.10-setup.md
Last active September 11, 2015 16:34 — forked from kevinelliott/osx-10.10-setup.md
Mac OS X 10.10 Yosemite Setup

Mac OS X 10.10 Yosemite

Custom recipe to get OS X 10.10 Yosemite running from scratch, setup applications and developer environment. I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

Install Software

@YashdalfTheGray
YashdalfTheGray / simple-handling.js
Last active November 9, 2015 02:57
Handing Promises using .then()
var promise = $timeout(messageFunction, delay);
promise.then(function(result) {
ctrl.message = result;
});
// The call to then() can also be chained.
$timeout(messageFunction, delay).then(function(result) {
ctrl.message = result;
});
@YashdalfTheGray
YashdalfTheGray / promise-api.js
Created November 9, 2015 03:38
Promise API
server.getData(url)
.then(function(result) {
// this code block runs when the
// promise gets fulfilled.
ctrl.myData = result;
})
.catch(function(error) {
// this code block runs when there
// is an error encountered or if the
@YashdalfTheGray
YashdalfTheGray / promise-chain.js
Created November 9, 2015 04:29
Chaining Promises
server.getUsername()
.then(function(result) {
return server.getProfile(result);
}).then(function(result) {
displayProfile(result);
return server.getProfilePicture(result.imageUrl);
}).then(function(result) {
udpateProfilePicture(result);
console.log('Data loaded');
}).catch(function(error) {
@YashdalfTheGray
YashdalfTheGray / promises-in-angular.js
Created November 9, 2015 04:42
Creating a promise using $q
function getFile(url) {
// create a deferred object.
var def = $q.defer();
// NOTE
// the $http methods success() and error()
// have been deprecated in favor of using then()
// from the standard Promises API. These are
// used here to show how to create a promise.
$http.get(url)
@YashdalfTheGray
YashdalfTheGray / wrapping-with-when.js
Last active November 10, 2015 05:05
Wrapping other async tasks
// assume that getUsers returns a promise but
// the service may not be written in angular
$q.when(service.getUsers()).then(function(result) {
ctrl.userList = result;
});
// $q.when() can also be useful when writing stubs
function getUsers() {
// this function is supposed to return a promise
// but in test, it doesn't make sense to do that
@YashdalfTheGray
YashdalfTheGray / waiting-for-all.js
Last active November 10, 2015 06:23
Waiting for multiple resolutions
$q.all([
server.getFollowersList(),
server.getFollowingList(),
server.getTweets(),
server.getUserDescription()
]).then(function(result) {
// The result object will be an array
// with all of the results.
ctrl.updateFollowers(result[0]);
ctrl.updateFollowing(result[1]);
@YashdalfTheGray
YashdalfTheGray / promise-notification.js
Created November 12, 2015 06:03
Promise progress notification using Angular's $q
function getResource(url) {
var resource = [];
var def = $q.defer();
var lastProgress = 0;
server.openAndGet(url, function(chunk) {
resource.push(chunk);
});
while(!server.txDone()) {
if (server.getProgress() !== lastProgress) {
lastProgress = server.getProgress();
@YashdalfTheGray
YashdalfTheGray / promises.md
Created November 15, 2015 20:49 — forked from domenic/promises.md
You're Missing the Point of Promises

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.

You're Missing the Point of Promises

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.