Skip to content

Instantly share code, notes, and snippets.

@rudyryk
rudyryk / gist:2894223
Created June 8, 2012 07:30
Confirmation dialog for Twitter Bootstrap
<div class="modal hide fade" id="confirm-dialog">
<div class="modal-header">
<a class="close" data-dismiss="modal">×</a>
<h3>Confirm</h3>
</div>
<div class="modal-body">
&nbsp;
</div>
<div class="modal-footer">
<a href="#" class="btn btn-danger">Ok</a>
@rudyryk
rudyryk / gist:4190318
Created December 2, 2012 18:24
Override delete_selected in Django admin
from django.core.exceptions import PermissionDenied
from django.contrib import admin
from django.contrib.admin.actions import delete_selected as delete_selected_
def delete_selected(modeladmin, request, queryset):
if not modeladmin.has_delete_permission(request):
raise PermissionDenied
if request.POST.get('post'):
for obj in queryset:
@rudyryk
rudyryk / gist:5732114
Last active December 18, 2015 05:19
~/.profile virtualenvwrapper loader example for Python3
# virtualenvwrapper
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
@rudyryk
rudyryk / gist:5732553
Created June 7, 2013 21:30
Emperor uWSGI UpStart script for Ubuntu example
# Emperor uWSGI script /etc/init/uwsgi-emperor.conf
description "uWSGI Emperor"
start on runlevel [2345]
stop on runlevel [06]
env UWSGI_VASSAL_SOCKET=/tmp/uwsgi/%n.sock
exec uwsgi --master --die-on-term --emperor "/home/*/uwsgi/*.ini" --emperor-tyrant
# MyApp UpStart script template
description "MyApp python server"
start on startup
stop on shutdown
respawn
# It's a good idea to setup LANG
env LANG=en_US.UTF-8
env USER=myuser
env COMMAND=/home/myuser/.virtualenvs/myapp/bin/python
@rudyryk
rudyryk / gist:5966593
Created July 10, 2013 14:08
Serialize Javascript object to URL string without [] suffix
/* Based on http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
*/
var serializeToURL = function(obj, prefix) {
var url = [];
for(var p in obj) {
var k = prefix ? prefix : p, v = obj[p];
url.push(typeof v == "object" ?
serializeToURL(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
@rudyryk
rudyryk / make_random_password.py
Last active July 14, 2016 14:32
Python os.urandom example: make random password
import os
def make_random_password(length=12, symbols='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@$^_+&'):
password = []
for i in map(lambda x: int(len(symbols)*x/255.0), os.urandom(length)):
password.append(symbols[i])
return ''.join(password)
@rudyryk
rudyryk / georange.py
Last active December 21, 2015 08:39
Approximate longitude & latitude rectangle for specified location and distance.
import math
def georange(origin, distance):
"""
Returns approximate longitude & latitude rectangle range for
specified origin and distance in km. Works good when:
distance is far smaller 6400 km (approximate Earth radius)
origin isn't too close to North and South poles
@rudyryk
rudyryk / generate.sh
Created August 26, 2013 06:34
Helper script for generating push notification certificates based on tutorial: http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
#!/bin/sh
# Helper script for generating push notification certificates based on tutorial:
# http://www.raywenderlich.com/32960/apple-push-notification-services-in-ios-6-tutorial-part-1
function show_help_and_exit
{
echo "usage:" $0 \<certificate output\> \<private key output\> \<combined output\>
echo
echo "Input files are not specified, they are supposed to have"
@rudyryk
rudyryk / server.conf
Last active December 30, 2015 08:29
Nginx config sample: Django + FastCGI, e.g. Gunicorn
upstream app_server {
# Gunicorn or runfcgi-powered Django server
server 127.0.0.1:8000 fail_timeout=0;
}
server {
server_name server.name;
listen 443 ssl;
client_max_body_size 4G;
keepalive_timeout 5;