“Why does Windows think my keyboard is a toaster?”, or “the case for generic code samples: expect users to copy, paste and ship”
“Why does Windows think my keyboard is a toaster?”, or “the case for generic code samples: expect users to copy, paste and ship”
My first puredata patch: Canoner! A cross between a delay and a looper, this patch allows you to play canons solo.
Hit Start/Round as you start playing, then again at a round point, and the patch will continue to play what you played with that delay until you hit Stop.
Extending the canoner to support n>2 part canons is left as an exercise for the reader.
Patch code:
#N canvas 405 217 363 240 10;
#X obj 26 34 tgl 40 0 empty empty empty 17 7 0 10 -204786 -1 -1 0 1
;
#X obj 26 84 route 1 0;
#X obj 214 201 delwrite~ round 10000;
#X obj 214 176 adc~;
#X obj 26 117 timer;
#X obj 26 148 delread~ round;
#X obj 26 198 dac~;
#X floatatom 165 149 5 0 0 0 - - -;
#X floatatom 129 149 5 0 0 0 - - -;
#X obj 26 174 *~ 0;
#X obj 101 34 bng 40 250 50 0 empty empty empty 17 7 0 10 -260097 -1
-1;
#X text 13 15 Start/Round;
#X text 106 14 Stop;
#X text 249 176 Input Stage;
#X connect 0 0 1 0;
#X connect 1 0 4 0;
#X connect 1 1 4 1;
#X connect 1 1 8 0;
#X connect 3 0 2 0;
#X connect 4 0 5 0;
#X connect 5 0 9 0;
#X connect 7 0 9 1;
#X connect 8 0 9 1;
#X connect 9 0 6 0;
#X connect 9 0 6 1;
#X connect 10 0 7 0;
There’s something incredibly satisfying, if a little masochistic, about poring over PIC datasheets and manpages, and tinkering with low-level code you only half understand, when it all actually works and you get two devices to talk to each other (in this case a PIC16F886 and a Raspberry Pi, via I2C)
Javascript has no real Set or Dictionary implementation, which for someone spoiled by python’s set
and dict
s is rather frustrating. However, in leiu of the poorly supported js Set
type, plain old objects can be massaged into acting as both sets and dicts:
// Python: d = dict()
var d = {};
// d['key'] = 'value'
d['key'] = 'value';
// d.get('nonexistent', 'fallback')
d.hasOwnProperty('nonexistent') ? d['nonexistent'] : 'fallback';
// d.keys()
Object.keys(d);
// s = set()
var s = {};
// s.add(1)
s[1] = true;
// 1 in s
s.hasOwnProperty(1);
// Accessing all values in set:
Object.keys(s);
Notes: the in
operator can be used to test membership, but will incorrectly return true for __proto__
, as well as all properties up the prototype chain, i.e. all properties and methods of Object
. hasOwnProperty
is much safer to use.
Similarly, the use of the ternary operator for get-item-with-fallback could in theory be replaced with d['item'] || 'fallback'
, unless of course the value stored was falsey, in which case the or will incorrectly return a truthier fallback.
First PuSH subscription ping successfully received! Yay!
Slowly getting a PuSH subscription service working. It should be fairly easy to turn it, once finished, into a layered library so people can either bolt it onto a Silex/Symfony app and have it all just work, or use the lower level client and logic in other frameworks.
@tommorris wow, the Werkzeug debugger looks fantastic, going to try that out on some django projects today
Considering the possibility that preferring to use spaces over tabs for code indentation is indicative of excess complacency with the status quo of using complex text formats to express behaviour, and of the viewpoint that code is a static, inflexible material (think raster images vs vector)
When using #django to send content-disposition: attachment
responses, you MUST explicitly set the response encoding (charset) otherwise windows will assume the response is in whatever-weird-encoding-windows-uses, rather than UTF-8 (you are using UTF-8, aren’t you?).
CSV example code:
response = HttpResponse(utf_8_encoded_csv_text, status=200, mimetype="text/csv; charset=utf-8")
response['Content-Disposition'] = 'attachment; filename=data.csv'
It seems that some weird old applications like SPSS need a BOM in there as well, even though UTF-8 doesn’t have a BOM. Add that like this
response.content = '\xef\xbb\xbf' + response.content
before sending the response
return response
Apparently, making sure a directory exists is an exceedingly complicated task: stackoverflow.com/questions/273192/create-directory-if-it-doesnt-exist-for-file-write
Trying to learn about #bluetooth development on mac, preferably with python or go, but can’t find much information or working libraries — any tips?
@thatEmil that should work fine — one thing to bear in mind is that by default they both treat redirects differently. IIRC, cURL doesn’t follow redirects by default whereas file_get_contents
will.
New in this version of #taproot:
The local maximum has been overcome, for now. There is still much to do.
@w03_ thanks, I have indeed heard of Noflo! Haven’t experimented with it much yet due to their focus on the backend framework. I’m working on a similar thing, focused completely on experimenting with programming UI: waterpigs.co.uk/intertubes
psysh.org is the #php REPL shell we have been waiting for. How to start an interactive shell with a given context:
<?php
require 'vendor/autoload.php';
$app = require 'src/app.php';
Psy\Shell::debug(['app' => $app]);
Supports readline, pcntl, registering custom commands, automatic semicolon insertion, clean+concise string representations of evaluated values. Amazing work Justin Hileman!
Had many basic software development lessons hammered in by personal experience over the last couple of years: hierarchy bad. side effects bad. many moving parts bad. undue complexity bad. inconsistency bad. SQL databases fragile. always be reducing.
It’s amazing just how seductive complex, unproductive tools can be. Successfully overcome+abandoned:
PHP remains productive and speedy (with composer, delightful dependency management), python nice with some irritations. jQuery useful when absolutely necessary, plain #js with small libraries loaded via requirejs handle most progressive enhancement concisely. node.js nice for some things, preferring go’s approach to async programming but still not much everyday need for it.
Avoiding middlemen: LESS, SASS, Coffeescript. Unnecessary for most of my work, and more moving parts is bad.
Now bothering me is the frameworky nonsense accumulating in #taproot. Need to cleanse.
What’s the best way of exchanging realtime data between applications on the same machine? Specifically, I want one application to be able to publish and many subscribe.
I get a little annoyed at #python every now and again (grr package management) but then I come across things like nested tuple unpacking which are just so lovely they make up for it:
for i, (key, value) in enumerate(list_of_tuples):
print i, key, value
Are there any languages with datatypes with built in version control? Would be pretty great for debugging.
Musing on why we only turn to natural language for defining the behaviour of out applications instead of the business logic itself.
Rough ideas: gist.github.com/barnabywalters/6188240