Skip to content

Instantly share code, notes, and snippets.

View metatoaster's full-sized avatar

Tommy Yu metatoaster

  • Auckland Bioengineering Institute, University of Auckland
  • Auckland, New Zealand
View GitHub Profile
$ echo an input | python test_raw.py
Please entire a line of text: ttyinput
ttyinput
('an input\n\n', '')
$ echo an input | python test_setsid.py
('', 'Traceback (most recent call last):\n File "tty_toy.py", line 1, in <module>\n ttyin = open(\'/dev/tty\', \'r\')\nIOError: [Errno 6] No such device or address: \'/dev/tty\'\n')
ones = ('', 'hen', 'do', 'tri', 'tetra', 'penta', 'hexa',
'hepta', 'octa', 'nona',)
tens = ('', 'deca', 'icosa', 'triconta', 'tetraconta', 'pentaconta',
'hexaconta', 'heptaconta', 'octaconta', 'nonaconta',)
hundreds = ('', 'hecta', 'dicta', 'tricta', 'tetracta', 'pentacta', 'hexacta',
'heptacta', 'octacta', 'nonacta',)
thousands = ('', 'kilia', 'dilia', 'trilia', 'tetralia', 'pentalia', 'hexalia',
@metatoaster
metatoaster / tagthing.hs
Created March 2, 2014 11:23
Babby's first haskell webapp
module Handler.Tag
( getTagsR
, getTagR
, getTagAddR
, postTagAddR
)
where
import Import
import inspect
import functools
def arg2attr(clsins_init):
@functools.wraps(clsins_init)
def initattrs(self, *a, **kw):
# build default dict from default args, in reverse order due to
# the definition syntax is designed.
@metatoaster
metatoaster / bootstrap.py
Last active August 29, 2015 14:05
CellML API buildout with cgrspy
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
@metatoaster
metatoaster / gist:322b84289f2be660f6f2
Created November 27, 2014 11:02
What the fuck is this shit?
top's Config File (Linux processes with windows)
Id:i, Mode_altscr=0, Mode_irixps=1, Delay_time=1.500, Curwin=0
Def fieldscur=¥&K¨³´»½@·º¹56ÄFÅ')*+,-./0128<>?ABCGHIJLMNOPQRSTUVWXYZ[\]^_`abcdefghij
winflags=192564, sortindx=18, maxtasks=0, graph_cpus=0, graph_mems=0
summclr=1, msgsclr=1, headclr=3, taskclr=1
Job fieldscur=¥¦¹·º(³´Ä»½@<§Å)*+,-./012568>?ABCFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghij
winflags=163124, sortindx=0, maxtasks=0, graph_cpus=2, graph_mems=0
summclr=6, msgsclr=6, headclr=7, taskclr=6
Mem fieldscur=¥º»<½¾¿ÀÁMBNÃD34·Å&'()*+,-./0125689FGHIJKLOPQRSTUVWXYZ[\]^_`abcdefghij
winflags=163124, sortindx=21, maxtasks=0, graph_cpus=2, graph_mems=0
@metatoaster
metatoaster / mod1.py
Created October 9, 2015 02:34
Python closures are funny
def decorator(arg1, arg2_=None):
def d(f):
arg2 = arg2_
if arg2 is None:
arg2 = 'default arg2'
print('arg1 = %s' % arg1)
print('arg2 = %s' % arg2)
@metatoaster
metatoaster / python_closure.md
Last active January 19, 2023 23:37
Python closure fun

This is most certainly a bad idea, but what you want to do can be done in some extent, and this is going to take a lot of time to explain. First off, rather than thinking of decorators as a syntax sugar, think of them as what they really are: a function (that is a closure) with a function that exist inside it. Now this is out of the way, supposed we have a function:

def operation(a, b):
    print('doing operation')
    return a + b

Simply it will do this

>>> hi = operation('hello', 'world')

doing operation

@metatoaster
metatoaster / test_exportimport.py
Last active November 16, 2015 03:25
Test can be added to plone.app.registry to show schema validation on broken plone.supermodel
Failure in test test_import_list_choice_field_vocabulary_usage (plone.app.registry.tests.test_exportimport.TestImport)
Traceback (most recent call last):
...
File ".../plone.app.registry/plone/app/registry/tests/test_exportimport.py", line 1073, in test_import_list_choice_field_vocabulary_usage
self.registry['test.registry.field'] = [u'One', u'Three']
...
AssertionError: WrongContainedType not raised
return chain(
[(
'/'.join(module_frags + mod_path.split(sep))[:-len(JS_EXT)],
module_base_path,
mod_path,
) for mod_path in (
relpath(path, module_base_path)
for path in glob(join(module_base_path, '*' + fext))
)]
for module_base_path in module_base_paths