Skip to content

Instantly share code, notes, and snippets.

View spookylukey's full-sized avatar

Luke Plant spookylukey

View GitHub Profile
@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:
#
// See http://www.reddit.com/r/programming/comments/as759/hey_reddit_out_of_these_4_programmers_who_would/
using System;
class MainClass {
static int Main(string[] argv) {
foreach (string s in new string[] {"hello", "λ", Char.ConvertFromUtf32(0x1D161)}) {
Console.WriteLine(s);
Console.WriteLine(Reverse(s));
}
# 100% code coverage, with an obvious type level bug that is not caught - Bar
# does not define method2 and do_it will fail for some values.
class Foo(object):
def method1(self, arg):
return arg + 1
def method2(self, arg):
return arg + 2
#!/usr/bin/env python
# Quick and dirty script to convert ktimetracker.ics files
# into TimeCult files.
import os.path
import sys
import time
import uuid