Skip to content

Instantly share code, notes, and snippets.

@rudyryk
rudyryk / flask_admin_helpers.py
Last active August 29, 2015 14:07
Flask-Admin simple helpers: require login mixing, serving protected static pages. Snippet is written for Python 3.x
# No Rights Reserved
# http://creativecommons.org/publicdomain/zero/1.0/
"""
Flask-Admin simple helpers
==========================
Just copy and paste to some of your helpers or base classes module, import and use.
You'll also need to install Flask-Login for using authentication.
@rudyryk
rudyryk / django_minicart.py
Last active August 29, 2015 14:01
Simple and agnostic session based cart for Django
# -*- coding: utf-8 -*-
#
# No Rights Reserved
# http://creativecommons.org/publicdomain/zero/1.0/
"""Agnostic minimal session based cart for Django.
Just copy-n-paste this snippet to your project.
See `Cart` class reference below for details.
@rudyryk
rudyryk / HyperShortcuts.h
Created April 27, 2014 15:41
Objective-C and Cocoa shortcuts for iOS development
//
// HyperShortcuts.h
// Created by Alexey Kinyov on 27/04/2014.
//
// The MIT License (MIT)
//
// Copyright (c) 2013 Alexey Kinyov <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@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;
@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 / 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 / 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 / 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));
}
# 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: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