Skip to content

Instantly share code, notes, and snippets.

View spookylukey's full-sized avatar

Luke Plant spookylukey

View GitHub Profile
// Example using official client (condensed)
require_once('apiclient/pmapirequest.class.inc');
require_once('apiclient/pmapiauthnone.class.inc');
require_once('apiclient/pmapiauthtoken.class.inc');
$request = new PMAPIRequest(new PMAPIAuthNone());
$response = $request->token->post(array('username' => 'my_api_user@example.com',
'password' => 'my_strong_password'));
@spookylukey
spookylukey / gist:9412489
Created March 7, 2014 14:32
linux mint error
The following NEW packages will be installed:
ghc libbsd-dev{a} libffi-dev{a} libgmp-dev{a}
0 packages upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 26.2 MB of archives. After unpacking 295 MB will be used.
Do you want to continue? [Y/n/?]
Get: 1 http://debian.linuxmint.com/latest/ testing/main libbsd-dev amd64 0.6.0-1 [157 kB]
Err http://debian.linuxmint.com/latest/ testing/main libffi-dev amd64 3.0.13-4
500 Internal Server Error
Get: 2 http://debian.linuxmint.com/latest/ testing/main libgmp-dev amd64 2:5.1.2+dfsg-3 [581 kB]
Get: 3 http://debian.linuxmint.com/latest/ testing/main ghc amd64 7.6.3-5 [25.3 MB]
-e git+https://github.com/pashinin/fabric@p33#egg=Fabric
-e git+https://github.com/paramiko/paramiko/@python3#egg=paramiko
@spookylukey
spookylukey / gist:589f9d3f05be56351fec
Created May 28, 2014 12:51
How not to do currncy exchange...
def exchange(self, price):
#default = Currency.objects.get(iso4217=DEFAULT_CURRENCY)
try:
rate = self.exchangerate_set.all()[0]
return Decimal(str(float(rate.denominator) * float(price)))
except IndexError:
return price
@spookylukey
spookylukey / gist:eb6029bc48ab8410227b
Created May 28, 2014 12:52
How not to do currency exchange...
def exchange(self, price):
#default = Currency.objects.get(iso4217=DEFAULT_CURRENCY)
try:
rate = self.exchangerate_set.all()[0]
return Decimal(str(float(rate.denominator) * float(price)))
except IndexError:
return price
Firefox dev console:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://avosapi.delicious.com/api/v1/account/public/profile/spookylukey?_=1413809903947. This can be fixed by moving the resource to the same domain or enabling CORS.
Chrome dev console:
XMLHttpRequest cannot load https://avosapi.delicious.com/api/v1/account/public/profile/spookylukey?_=1413809942129. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://delicious.com' is therefore not allowed access. The response had HTTP status code 503.
@spookylukey
spookylukey / gist:36acb563acd54fc3ddf0
Created December 11, 2014 15:44
Bug with Django migrations - migrations created with Python 2 need 'fixing' when run with Python 3
$ mkdir bugtest
$ cd bugtest
$ virtualenv --python=python2.7 env_p27
Running virtualenv with interpreter /usr/bin/python2.7
New python executable in env_p27/bin/python2.7
Also creating executable in env_p27/bin/python
Please make sure you remove any previous custom paths from your /home/luke/.pydistutils.cfg file.
Installing setuptools, pip...done.
$ source env_p27/bin/activate
@spookylukey
spookylukey / gist:fc9fa268de67fd19a567
Last active August 29, 2015 14:22
How to post code snippets (especially Python) into comment systems that don't preserve whitespace
#!/usr/bin/env python
# How to post code snippets (especially Python) into comment systems
# that don't preserve whitespace.
# Save this as a script called 'convert_leading_spaces_to_nonbreaking'
# in your PATH and do "chmod +x" on it.
#
# In Linux, you can then use it by installing xsel and doing:
#
@spookylukey
spookylukey / two_forms_one_view.txt
Created June 29, 2016 10:49
Two forms one view
# Views
def two_form_view(request):
context = {}
if request.method == "POST":
question_form = QuestionForm(request.POST)
answer_form = AnswerForm(request.POST)
success = False
if 'q_button' in request.POST and question_form.is_valid()
question_form.save()
@spookylukey
spookylukey / stackoverflow_docs_no_thanks.rst
Last active January 31, 2017 12:31
Stackoverflow docs no thanks (at least for Django)

I'm talking about this: http://stackoverflow.com/documentation/django

Compared to well written documentation, this kind of documentation is pretty bad. Yes, many projects have terrible documentation, and for them it might be an improvement, but for many that have good docs, this is a major step backwards.

Good documentation requires serious effort and organisation. It can't be achieved by throwing together lots of examples.