Skip to content

Instantly share code, notes, and snippets.

View Wilfred's full-sized avatar

Wilfred Hughes Wilfred

View GitHub Profile
@Wilfred
Wilfred / main2.py
Created February 9, 2014 23:14
RPython error on iterating over a bytestring.
from __future__ import unicode_literals
import sys
def entry_point(argv):
bytes_seq = b"abcdef1234!"
for byte in bytes_seq:
print byte.decode('utf-8')
@Wilfred
Wilfred / error.txt
Created February 7, 2014 22:21
Inspecting whether a file handle is open in RPython
[translation:info] Error:
[translation:info] File "/home/wilfred/projects/trifle/src/pypy/rpython/translator/goal/translate.py", line 318, in main
[translation:info] drv.proceed(goals)
[translation:info] File "/home/wilfred/projects/trifle/src/pypy/rpython/translator/driver.py", line 534, in proceed
[translation:info] return self._execute(goals, task_skip = self._maybe_skip())
[translation:info] File "/home/wilfred/projects/trifle/src/pypy/rpython/translator/tool/taskengine.py", line 114, in _execute
[translation:info] res = self._do(goal, taskcallable, *args, **kwds)
[translation:info] File "/home/wilfred/projects/trifle/src/pypy/rpython/translator/driver.py", line 283, in _do
[translation:info] res = func()
[translation:info] File "/home/wilfred/projects/trifle/src/pypy/rpython/translator/driver.py", line 320, in task_annotate
@Wilfred
Wilfred / llvm-mode.el
Last active January 2, 2016 15:59
llvm with proper headers
;;; llvm-mode.el --- Major mode for the LLVM assembler language.
;; Maintainer: The LLVM team, http://llvm.org/
;; Description: Major mode for the LLVM assembler language.
;; Updated: 2007-09-19
;;; Code:
;; Create mode-specific tables.
(defvar llvm-mode-syntax-table nil
@Wilfred
Wilfred / email_testing.py
Created December 24, 2013 16:17
unit testing django emails
from django.test import TestCase
from django.test.utils import override_settings
from mock import patch
# If we're sending emails asynchronously with Sentry, make it
# synchronous during tests:
@override_settings(CELERY_ALWAYS_EAGER=True)
class EmailTestCase(TestCase):
/*
* Placeholder plugin for jQuery
* @author Daniel Stocks (http://webcloud.se)
*/
(function($) {
function Placeholder(input) {
this.input = input;
if (input.attr('type') == 'password') {
this.handlePassword();
}
@Wilfred
Wilfred / flatten.py
Last active December 20, 2020 15:06
flatten an arbitrarily nested list in Python
from copy import deepcopy
def flatten_list(nested_list):
"""Flatten an arbitrarily nested list, without recursion (to avoid
stack overflows). Returns a new list, the original list is unchanged.
>> list(flatten_list([1, 2, 3, [4], [], [[[[[[[[[5]]]]]]]]]]))
[1, 2, 3, 4, 5]
>> list(flatten_list([[1, 2], 3]))
[1, 2, 3]
@Wilfred
Wilfred / behaviour of rpython version
Last active December 28, 2015 12:29
read_input.py works fine, but read_input_rpython_import.py writes a strange traceback to the console
$ PYTHONPATH=pypy python2 read_input_rpython_import.py
[platform:execute] gcc -c -O3 -pthread -fomit-frame-pointer -Wall -Wno-unused /tmp/usession-release-2.2.x-41/platcheck_0.c -o /tmp/usession-release-2.2.x-41/platcheck_0.o
[platform:execute] gcc /tmp/usession-release-2.2.x-41/platcheck_0.o -pthread -lintl -lrt -o /tmp/usession-release-2.2.x-41/platcheck_0
> ^C
Traceback (most recent call last):
caught keyboard interrupt
File "/home/wilfred/projects/baobob/pypy/rpython/tool/runsubprocess.py", line 39, in <module>
> operation = sys.stdin.readline()
KeyboardInterrupt
^C
@Wilfred
Wilfred / lexer.py
Created October 19, 2013 23:27
rpython complains about the type here
import sys
import re
WHITESPACE = 'whitespace'
OPEN_PAREN = 'open-paren'
CLOSE_PAREN = 'close-paren'
INTEGER = 'integer'
@Wilfred
Wilfred / example.sh
Created September 23, 2013 11:02
Installing Xapian in a virtualenv
ln -sv /usr/lib/python2.6/dist-packages/xapian $VENV_HOME/lib/python2.6/site-packages
@Wilfred
Wilfred / cached_instances.py
Created September 17, 2013 17:44
Ensure no class gets instantiated twice with the same arguments.
import copy
def make_hash(obj):
"""Make a hash from an arbitrary nested dictionary, list, tuple or
set.
"""
if isinstance(obj, set) or isinstance(obj, tuple) or isinstance(obj, list):
return hash(tuple([make_hash(e) for e in obj]))