Skip to content

Instantly share code, notes, and snippets.

@amitittyerah
amitittyerah / gist:8963256
Created February 12, 2014 19:55
Sample Django App for uWSGI
import os, sys
import django.core.handlers.wsgi
sys.path.append('/var/www/html/PROJECT')
os.environ['DJANGO_SETTINGS_MODULE'] = 'PROJECT.settings'
application = django.core.handlers.wsgi.WSGIHandler()
@amitittyerah
amitittyerah / gist:8963278
Created February 12, 2014 19:56
uWSGI Start Server on Django
uwsgi --socket 127.0.0.1:8000 --master --workers 1 --harakiri 30 --daemonize /tmp/daemonize.log --pidfile /tmp/uwsgi.pid --vacuum --max-requests 100 --gid 500 --uid 500 --pythonpath /var/www/html/PROJECT --module UWSGI
@amitittyerah
amitittyerah / nginx.conf
Created February 12, 2014 20:06
NGINX Config for uWSGI
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
@amitittyerah
amitittyerah / markers.js
Created March 17, 2014 01:14
Adding markers to a google map with a loop
google.maps.event.addListener(marker, 'click',
(function(marker_inner) {
return function() {
new google.maps.InfoWindow({
content: 'Marker : ' + marker_inner.data.title
}).open(map,marker_inner);
map.setCenter(marker_inner.getPosition());
}
})(marker)
);
@amitittyerah
amitittyerah / array_chunk.py
Created March 24, 2014 00:49
array_chunk($arr, $size) version of Python
def array_chunk(arr, size):
chunks=[arr[x:x+size] for x in xrange(0, len(arr), size)]
@amitittyerah
amitittyerah / AppDelegate.m
Created March 26, 2014 10:17
Dummy navigation controllers within a tab bar controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
...
self.tabBarController = [[UITabBarController alloc] init];
UIViewController *homeViewController = [[HomeViewController alloc] init];
UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];
self.tabBarController.viewControllers =[NSArray arrayWithObjects:homeNavigationController, nil];
@amitittyerah
amitittyerah / gist:10370325
Created April 10, 2014 11:22
Python cc error
ARCHFLAGS=-Wno-error=unused-command-line-argument-hard-error-in-future easy_install
@amitittyerah
amitittyerah / django_file_upload.py
Last active August 29, 2015 13:58
Simple file upload example without forms for Django
# view.py
def upload(request):
if 'file' in request.FILES:
upload_location = ModelName.upload_file(request.FILES.get('file'))
if upload_location:
print upload_location
else:
print 'oops, file upload failed!'
@amitittyerah
amitittyerah / decorators.py
Created April 10, 2014 22:45
Decorators with arguments for neat ACL
# decorators.py
def parameters_missing(request):
response_data = {}
response_data['status'] = False
response_data['message'] = 'Missing parameter'
return HttpResponse(json.dumps(response_data), content_type="application/json")
def open_request(request):
@csrf_exempt
@amitittyerah
amitittyerah / deploy_heroku.sh
Created April 11, 2014 04:58
Django deployment with Heroku
pip install django-toolbelt
nano Procfile
foreman
foreman start
pip freeze > requirements.txt
sudo pip install dj_database_url
heroku create
git init
git add -A
git commit -m ''