Skip to content

Instantly share code, notes, and snippets.

@oleoneto
oleoneto / nginx.conf
Last active October 1, 2020 11:16 — forked from asmallteapot/nginx.conf
Generic Nginx configuration for serving Django projects [updated]
# 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
@oleoneto
oleoneto / PythonSetup.md
Created July 13, 2018 19:45 — forked from patriciogonzalezvivo/PythonSetup.md
How to install Python correctly on Mac OSX

Install Homebrew

ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"

Add PATH to ~/.bash_profile and ~/.zshrc

export PATH=/usr/local/bin:$PATH
@oleoneto
oleoneto / RAILS_CHEATSHEET.md
Created August 9, 2018 20:52 — forked from mdang/RAILS_CHEATSHEET.md
Ruby on Rails Cheatsheet

Ruby on Rails Cheatsheet

Architecture

Create a new application

Install the Rails gem if you haven't done so before

@oleoneto
oleoneto / rails-and-mongo.md
Created August 12, 2018 00:46 — forked from casidiablo/rails-and-mongo.md
Steps to create a Rails application with MongoDb

This document contains the steps to create a mongo-enabled Rails 3.1 application. This is just for personal reference actually.

Create base application

We have to skip the Active Record stuff:

rails new app_name --skip-active-record

Add mongo and bson_ext to the Gemfile

@oleoneto
oleoneto / fetch_with_timeout.js
Created August 21, 2019 19:08 — forked from sobstel/fetch_with_timeout.js
fetch with timeout
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);
});
@oleoneto
oleoneto / workflows-in-django.md
Created December 1, 2019 04:27 — forked from Nagyman/workflows-in-django.md
Workflows in Django

Workflows (States) in Django

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.

Common Software Uses

  • Publishing (Draft->Approved->Published->Expired->Deleted)
@oleoneto
oleoneto / middleware.py
Created January 2, 2020 13:42 — forked from igniteflow/middleware.py
Django language middleware. 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.
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
@oleoneto
oleoneto / git-pushing-multiple.rst
Created January 6, 2020 04:51 — forked from rvl/git-pushing-multiple.rst
How to push to multiple git remotes at once. Useful if you keep mirrors of your repo.

Pushing to Multiple Git Repos

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

@oleoneto
oleoneto / Knex-Migrations-Seeding.md
Created February 5, 2020 00:21 — forked from NigelEarle/Knex-Migrations-Seeding.md
Migration and seeding instructions using Knex.js!

Migrations & Seeding

What are migrations??

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!

Creating/Dropping Tables

@oleoneto
oleoneto / async-await.js
Created February 5, 2020 01:10 — forked from wesbos/async-await.js
Simple Async/Await Example
// 🔥 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
});
}