ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
Add PATH to ~/.bash_profile
and ~/.zshrc
export PATH=/usr/local/bin:$PATH
# file: /etc/nginx/sites-available/example.com | |
# nginx configuration for example.com | |
server { | |
listen 80; | |
server_name example.com; | |
access_log /var/www/example.com/logs/access.log; | |
error_log /var/www/example.com/logs/error.log; | |
# pass root to django |
const API_URL = '...'; | |
const TIMEOUT = 10; // seconds | |
export default (path) => { | |
/* global fetch */ | |
const req = fetch(API_URL + path); | |
const timeout = new Promise((resolve, reject) => { | |
return setTimeout(() => reject(new Error('request timeout')), TIMEOUT * 1000); | |
}); |
I'm going to cover a simple, but effective, utility for managing state and transitions (aka workflow). We often need to store the state (status) of a model and it should only be in one state at a time.
class LanguageMiddleware(object): | |
""" | |
Detect the user's browser language settings and activate the language. | |
If the default language is not supported, try secondary options. If none of the | |
user's languages are supported, then do nothing. | |
""" | |
def is_supported_language(self, language_code): | |
supported_languages = dict(settings.LANGUAGES).keys() | |
return language_code in supported_languages |
If a project has to have multiple git repos (e.g. Bitbucket and Github) then it's better that they remain in sync.
Usually this would involve pushing each branch to each repo in turn, but actually Git allows pushing to multiple repos in one go.
If in doubt about what git is doing when you run these commands, just
Migrations are a way to make database changes or updates, like creating or dropping tables, as well as updating a table with new columns with constraints via generated scripts. We can build these scripts via the command line using knex
command line tool.
To learn more about migrations, check out this article on the different types of database migrations!
// 🔥 Node 7.6 has async/await! Here is a quick run down on how async/await works | |
const axios = require('axios'); // promised based requests - like fetch() | |
function getCoffee() { | |
return new Promise(resolve => { | |
setTimeout(() => resolve('☕'), 2000); // it takes 2 seconds to make coffee | |
}); | |
} |