mongo //Start mongo shell
show dbs //Display databases
use mydb //Start using 'mydb' database
db //Display current database
show collections //Display collections
help //help
# Get documents, where writters are Joel Coen and Ethan Coen.
db.movieDetails.find({ "writters" : ["Joel Coen", "Ethan Coen"] }).count()
# Get documents, where Jeff Bridges is playing leading role.
> db.movieDetails.find({ "actors.0": "Jeff Bridges" }).pretty()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Cleanup docker files: untagged containers and images. | |
# | |
# Use `docker-cleanup -n` for a dry run to see what would be deleted. | |
untagged_containers() { | |
# Print containers using untagged images: $1 is used with awk's print: 0=line, 1=column 1. | |
# NOTE: "[0-9a-f]{12}" does not work with GNU Awk 3.1.7 (RHEL6). | |
# Ref: https://github.com/blueyed/dotfiles/commit/a14f0b4b#commitcomment-6736470 | |
docker ps -a | tail -n +2 | awk '$2 ~ "^[0-9a-f]+$" {print $'$1'}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Ask for the user password | |
# Script only works if sudo caches the password for a few minutes | |
sudo true | |
# Install kernel extra's to enable docker aufs support | |
sudo apt-get -y install linux-image-extra-$(uname -r) | |
# Add Docker PPA and install latest version | |
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9 | |
sudo sh -c "echo deb https://get.docker.io/ubuntu docker main > /etc/apt/sources.list.d/docker.list" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python manage.py shell: | |
>>> sql = '''drop table mytable cascade; | |
... drop table mytable2; ''' | |
>>> | |
>>> from django.db import connections, transaction | |
>>> cursor = connections['default'].cursor() | |
>>> cursor.execute(sql) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var myApp = angular.module('myApp').config(function($httpProvider) { | |
$httpProvider.defaults.headers.post['X-CSRFToken'] = $('input[name=csrfmiddlewaretoken]').val(); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// service.js | |
angular.service('Address', function($resource, $cookies, $xhr, $log) { | |
// Add Header to comply with Django's CSRF implementation | |
token = $cookies['csrftoken']; | |
$xhr.defaults.headers['delete']['X-CSRFToken'] = token; | |
return $resource('/api/user/address/:addressId', {addressId:'@id'}, {}); | |
}); |
First create backend endpoints using Django Rest Framework:
task/models
from django.db import models
class Task(models.Model):
completed = models.BooleanField(default=False)
title = models.CharField(max_length=100)
description = models.TextField()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
filename: angularjs.py | |
Usage: | |
{% ng Some.angular.scope.content %} | |
e.g. | |
{% load angularjs %} | |
<div ng-init="yourName = 'foobar'"> | |
<p>{% ng yourName %}</p> |
##SETUP VIRTUALENV on Ubuntu Server
console: ~ $ sudo apt-get install python-virtualenv
console: ~ $ virtualenv python #Careful where you call this command as it creates a folder in the current directory
console: ~ $ source ./python/bin/activate
console: ~ $ deactivate
- IF YOU WANT TO DELETE A VIRTUALENV JUST DELETE THE FOLDER
OlderNewer