Skip to content

Instantly share code, notes, and snippets.

@freakboy3742
freakboy3742 / voctestapp.py
Last active Sep 5, 2021
An Android app written in Python
View voctestapp.py
from android.util import TypedValue
from android.view import ViewGroup
from android.view import Gravity
from android.widget import LinearLayout
from android.widget import TextView
from android.widget import EditText
from android.widget import Button
from android.widget import ScrollView
from android.util import Log
@ehazlett
ehazlett / gist:38ba224ae8bba348da2e
Last active Mar 28, 2019
Using NFS with boot2docker
View gist:38ba224ae8bba348da2e

NFS Server

OS X Host

Note: you will need sudo access. Add the following to /etc/exports

/Users -alldirs -maproot=root:wheel -network 192.168.99.0 -mask 255.255.255.0

Restart NFS:

@readevalprint
readevalprint / serializer.py
Created Sep 25, 2013
django-haystack SearchResultSerializer from django-rest-framework
View serializer.py
==== SNIP ====
class DistanceSerializer(serializers.Serializer):
km = serializers.FloatField()
m = serializers.FloatField()
mi = serializers.FloatField()
ft = serializers.FloatField()
class SearchResultSerializer(serializers.Serializer):
View mysql_to_postgres.txt
Maybe the closest analogue to this is the PHP "debate":
(http://www.codinghorror.com/blog/2012/06/the-php-singularity.html)
(http://me.veekun.com/blog/2012/04/09/php-a-fractal-of-bad-design/)
Basically, MySQL works and you can definitely use it to build and run successful applications. Facebook uses it. But the point is that Postgres..... is better. That's the point. How and why? There are numerous articles out there for you to google up but [here's one] (http://www.youtube.com/watch?v=1PoFIohBSM4) that gives you a resaonable breakdown, by example.
So if you're currently a still running MySQL why not give Postgres a go, especially if you're starting a new project. Hell, why not use it even on existing projects which are using MySQL? Maybe because you have existing MySQL databases full of data and tables that you'd need to convert over to PostgreSQL? True this is a barrier, but it's by no means insurmountable. Which is what this post is about: easy conversion of your existing MySQL databases (schema and dat
@codeinthehole
codeinthehole / comparison.py
Last active Mar 20, 2019
Comparison of three ways of assigning excluded fields to a model when creating via a form
View comparison.py
# Question - how best to handle model fields that are excluded from a form's
# fields.
# ------------------------------------------------------------
# Option 1: assign fields to instance before passing into form
# ------------------------------------------------------------
# views.py
instance = Vote(review=review, user=request.user)
form = VoteForm(data=request.POST, instance=instance)
@dankrause
dankrause / _hover_example.py
Last active Sep 6, 2021
Example code to use the (unofficial, unsupported, undocumented) hover.com DNS API.
View _hover_example.py
import requests
class HoverException(Exception):
pass
class HoverAPI(object):
def __init__(self, username, password):
params = {"username": username, "password": password}
r = requests.post("https://www.hover.com/api/login", params=params)
@mastbaum
mastbaum / custom_directive.py
Created May 10, 2012
Example of a custom ReST directive in Python docutils
View custom_directive.py
'''Example of a custom ReST directive in Python docutils'''
import docutils.core
from docutils.nodes import TextElement, Inline
from docutils.parsers.rst import Directive, directives
from docutils.writers.html4css1 import Writer, HTMLTranslator
class foo(Inline, TextElement):
'''This node class is a no-op -- just a fun way to define some parameters.
There are lots of base classes to choose from in `docutils.nodes`.
@maxim75
maxim75 / set_loc.py
Created May 22, 2011
Setting GPS location EXIF tags using Python script and pyexiv2 library
View set_loc.py
#!/usr/bin/env python
import pyexiv2
import fractions
from PIL import Image
from PIL.ExifTags import TAGS
import sys
def to_deg(value, loc):
if value < 0: