Skip to content

Instantly share code, notes, and snippets.

View Yogendra0Sharma's full-sized avatar
🎯
Focusing

Yogendra Sharma Yogendra0Sharma

🎯
Focusing
View GitHub Profile
@Yogendra0Sharma
Yogendra0Sharma / MongoDB Commands.md
Created January 10, 2017 10:33
MongoDB Commands

Basic Mongo shell commands

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()
@Yogendra0Sharma
Yogendra0Sharma / docker-cleanup
Created January 12, 2017 06:56 — forked from balos1/docker-cleanup
Cleanup unused Docker images and containers
#!/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'}'
@Yogendra0Sharma
Yogendra0Sharma / install.sh
Created January 12, 2017 07:08 — forked from balos1/install.sh
Install Latest Docker and Docker-compose on Ubuntu
# 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"
@Yogendra0Sharma
Yogendra0Sharma / rawSQL.py
Created January 12, 2017 08:41 — forked from citmusa/rawSQL.py
delete heroku - postgress table
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)
@Yogendra0Sharma
Yogendra0Sharma / gist:42870b90e3b7c446b4c04083b1c2960a
Created January 12, 2017 08:44 — forked from guillaumepiot/gist:3939452
ANGULARJS - Django CSRF Token header setup
var myApp = angular.module('myApp').config(function($httpProvider) {
$httpProvider.defaults.headers.post['X-CSRFToken'] = $('input[name=csrfmiddlewaretoken]').val();
});
// 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'}, {});
});
@Yogendra0Sharma
Yogendra0Sharma / angularjs.md
Created January 12, 2017 08:47 — forked from suhailvs/angularjs.md
Angularjs Task add/edit example

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()
@Yogendra0Sharma
Yogendra0Sharma / angularjs.py
Created January 12, 2017 08:48 — forked from atabary/angularjs.py
Django and angular.js are using a conflicting templating syntax, relying on double curly brackets, eg. `{{ something }}`. This template-tag mitigate the problem by allowing the use of {% ng something %} in a django template, which is then outputed as {{ something }} for angular.js to use.
"""
filename: angularjs.py
Usage:
{% ng Some.angular.scope.content %}
e.g.
{% load angularjs %}
<div ng-init="yourName = 'foobar'">
<p>{% ng yourName %}</p>
@Yogendra0Sharma
Yogendra0Sharma / PythonVirtualEnv.md
Created January 12, 2017 10:51
Howto Setup a Python Virtual Environment

Python Virtual Environment Howto

##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