Skip to content

Instantly share code, notes, and snippets.

View akshar-raaj's full-sized avatar
💭
Learning something new everyday!

Akshar Raaj akshar-raaj

💭
Learning something new everyday!
View GitHub Profile
@akshar-raaj
akshar-raaj / fabfile.py
Created May 11, 2014 16:50
Minimal fabfile
from fabric.api import run, env, cd
from fabric.colors import green
from fabric.context_managers import prefix
import time
env.hosts = ['<your_ip>']
env.user = '<user_on_server>'
def pull_code():
#application.py
from wsgiref.simple_server import make_server
# This is the "Application side" of WSGI
def application(environ, start_response):
response_body = "Hello"
status = "200 OK"
response_headers = [("Content-Length", str(len(response_body)))]
start_response(status, response_headers)
#application.py
from wsgiref.simple_server import make_server
# This is the "Application side" of WSGI
def application(environ, start_response):
path = environ.get('PATH_INFO')
if path == '/':
response_body = 'Index'
else:
django-admin.py startproject polls
python manage.py migrate
python manage.py runserver
http://localhost:8000/admin/auth/user/
python manage.py startapp poll
@akshar-raaj
akshar-raaj / binsearch
Created November 24, 2012 10:32
Binary Search
not_found = -1
import unittest
class TestBinS(unittest.TestCase):
def test_empty(self):
lst = []
key = 0
self.assertEquals(binsearch(lst, 0,), -1)
"""def test_equal(self):
lst = [0, 0, 0, 0]
@akshar-raaj
akshar-raaj / abc.py
Created November 30, 2012 13:21
Some test file
from django.test import TestCase
from django.test.client import Client
from django.contrib.auth.models import User
class TestViews(TestCase):
def setUp(self):
self.test_user = User.objects.create_user(username="test",
password="test",
email="test@agiliq.com")
In [17]: class A(object):
....: pass
....:
In [18]: aa = A()
In [19]: aa.__name__
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-19-f5dbf2ef814f> in <module>()
@akshar-raaj
akshar-raaj / dem_race_condition.py
Created September 8, 2013 05:54
A simple program demonstrating race condition
import threading
#define a global variable
some_var = 0
class IncrementThread(threading.Thread):
def run(self):
#we want to read a global variable
#and then increment it
global some_var
# polls/models.py
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
def __str__(self):
return self.question_text
def was_published_recently(self):
now = timezone.now()
from rest_framework import serializers
from polls.models import Question
class QuestionSerializer(serializers.ModelSerializer):
class Meta
model = Question
exclude = ()