jorgenmodin.net - Blog
This is untested by me but it has a number of nice traits:
- It is open source, so you can tinker with the code
- It has intents that your own Android app can use, so you do not need to tinker with the source code
- If I understand correctly it should work with a standard USB cable between the phone and an Arduino Uno R3. I have not checked this.
jeppsson/Arduino-Communicator - Let your own Android application receive data from Arduino by listening to the "primavera.arduino.intent.action.DATA_RECEIVED" intent.
Old HP server featuring last Dual Pentium (architecture wise actually the first Core 2 duo):
This machine benchmarks at 57471.3 pystones/second
Laptop with i5-4200u 1.6GHz with turbo to 2.6GHz (no idea if it it turbo'd):
This machine benchmarks at 185771 pystones/second
Raspberry pi B+:
This machine benchmarks at 3831.42 pystones/second
So in this particular benchmark, my laptop is about 3 times as fast as my old server. And the Pi is about 15 times slower than my server and 48 times slower than my laptop.
A python library that lets you chain together functions with dots into pipelines. Looks like jquery to me, is actually taken from Scala:
from functional import seqseq([[1, 1], [2, 3], [5, -1]]).flat_map(lambda x: x).sum()
To use ScalaFunctional, you need only include: from functional import seq. seq is a function which takes as argument a list and returns a wrapper on that list that provides the extensions for functional programming using Scala style.
I wonder how it handles errors in the chain...
List of supported functions
List to List
- init: get everything except last element
- tail: get everything except first element
- inits: get subsequent inits
- tails: get subsequent tails
- drop: drop first n elements
- drop_while: drop first elements using f
- take: take first n elements
- take_while: take first elements using f
- map: map f onto sequence
- filter: filter sequence by f
- filter_not: filter sequence by not f
- reverse: reverse sequence
- distinct: return set of unique/distinct elements
- enumerate, zip_with_index
List of (Key, Value) to List
List to Value
- head, first: get first element
- head_option: get first element or None
- last: get last element
- last_option: get last element or None
- reduce: reduce sequence using f
- count, len, size: get count of sequence
- all, for_all
- max, max_by
- min, min_by
- string: similar to mkString
Conversion to other types
This from the below linked page worked for me. Adjust /dev/ device to where your Arduino is. Mine is a Uno R3 clone.
To fix it, enter the command:
$ sudo usermod -a -G dialout
$ sudo chmod a+rw /dev/ttyACM0
My current rules for creating a web application in python
Summary: No exceptions, no classes, no frameworks.
Framework fatigue A framework is a mode, a global pragma on how to express the code in your application. In order to be efficient you need to understand how that framework works and it is unlikley that its modus operandi covers all the things that you want to do in a way that is flexible enough to match standard python. Instead use libraries, that gets hooked into your code, and only have a local impact on syntax and configuration.
Coming from the Zope/Plone world, it is very nice to throw all frameworky stuff to the wind and just express things in pure python. Now, frameworks do have their place, when you are solving something that many people have already solved for you, such as a content management system. But the moment your customer starts suggesting/dreaming up unique features you start fighting the framework. I chose to go with the bottle micro framework (which technically is a framework), that mostly stays out of the way and the module in my code that uses bottle is as thin as possible, and isolates the rest of the code from it.
Exceptions break the flow of the code, and it is harder to follow the execution of it. Furthermore in a web application you sometimes want to communicate several errors to the user, and not just the first one. Currently I use an extra return value in the form of an error object, that contains info if there is an error, some text that describes the error in a human readable way, and sometimes a recommendation of what url to redirect to.
class Status: def __init__(self): self.error = False self.redirect_address = None self.messages =  def add_message(self, message): self.messages.append(message)
..and used in a function:
status = Status() user_info = session.get_user_info_from_session(session_id) if not user_info: status.error = True status.add_message("Please log in.") status.redirect_address = '/login' return (None, status)
In this way I can add error messages, and then return from a function when enough error messages have been added. That is, I can add errors that are not caused by each other, before returning. This works well with server side validation, where you can list all the things that need to be corrected back to the user, and not just the first one you test for (although obviously you do client side validation too, for usability reasons. But you still need to untaint the input).
Using an explicit return value for error or success is used in the Go language instead of exceptions. Idiomatic scala uses the entire result you get back with a return value. The latter would be highly magical in Python, so a separate status value is used.
Objects are in practice highly unpredictable in when it comes to how you're supposed to interact with them, and get data in and out of them. In practice, objects forces you to learn a mini configuration language for each class, expressed as methods, parameters and whatever state changes happens as a result of those method calls. With pure functions that complexity is confined to the parameters going in and the return values coming out. I have heard from Java programmers that the complexity of how to interact with objects is less of a problem if you have declared interfaces and an IDE that can tell you what's going on with inputs and outputs. However there is still way to much freedom to express yourself as a class author when it comes to how you go about performing a task.
Objects all the way down can make for something akin to a Rube Goldberg machine:
But it is also a question of how to do simple things such as setting a configuration value. Is that done by just setting an attribute, or calling a setter, or using a configuration object that somehow interacts with something?
Objects are often used to store state, which if it is mutable also messes up scaling up the application, and makes testing more difficult. In a web app pure functions also automatically makes your application scalable, since http is sessionless and each request needs to retrieve its state anyway from cookies, urls and server side stored data.
I actually did end up using some objects, as can be seen from the Status object in one of the code listings above.
EU integration means you should be able to move and work anyway you want within the European Union. One obstacle to this is that it can get quite expensive to use your mobile phone once you get out of your own country. EU is trying to change this but there is some resistance.
The site above lists a couple of providers that can get you €10 - €20 per gigabyte EU-wide today. That is a pretty good deal.
Found via the the Europe subreddit at reddit.com: eugay comments on So the EU in the form of its various institutions is dragging its feet with regulation of roaming. But since we live in the single market, which providers offer cheapest roaming in the EU/EEA?
Sammansvärjningsteoretiker, putinister, kommunister och annat löst folk tror jag har en sak gemensamt: Man anser att världen fungerar, eller borde fungera, med relationer istället för med regler och fakta.
I mindre sociala sammanhang är relationer viktiga: Man litar på att en annan person ser ens problem och rättar till dem, man gör något för någon annan eller behöver uppenbart hjälp och blir sedd och får det man behöver i gengäld.
På större skala fungerar inte relationer så bra. Istället har vi parlament, en kakafoni av yttrandefrihet och marknader. Alla dessa är regelstyrda i sin funktion mer eller mindre och de lämnar inte utrymme för så mycket individuell empati och uppmärksamhet. Man skulle kunna kalla dem pluralistiska system.
En del personer upplever detta som problematiskt och vill att den stora världen ska fungera med relationer istället. Man är obekväm med de pluralistiska systemen och kanske till och med hatar och föraktar dem. Och det tror jag ligger bakom mycket av vurmandet för kommunism, eller för en stark ledare. Vad gäller konspirationsteoretiker är man dessutom övertygad om att allt redan är relationer på hög nivå över hela världen. Dvs marknader och parlament är bara kulisser för vad de stora grabbarna snackar sig samman om, i sina relationer med varandra.
Jag undrar om detta kan vara en grundläggande sak i människans psyke och om vi i så fall får dras med dessa åsikter och föreställningar, eller om en kulturell innötning av pluralistiska system kommer att balansera bort dem.
Insåg just att tätt kopplade globala finansiella system med stor hävstång (high leverage) är ytterligare ett exempel där man använder relationer på alldeles för stor nivå.
Sometimes you feel the need to pass judgement on a problem: You look at the facts, and reach a conclusion. But later another piece of fact turns up, or a previously asserted fact turns out to be false and everything gets turned upside down and you realise you were completely wrong. In short you are faced with a problem where what the apparent solution is changes, sometimes several times, as more information is known.
I call such problems whodunit problems, after crime stories where it is not clear until the very last page who actually did the crime.
The reasons why can be varied: It may be a war situation where a lot of disinformation is bandied about or it can be a problem where you need a heck of a lot more information than you previously thought in order to pass a correct judgement, or it might be a problem whose outcome seems pretty much random. It may be as simple as a leading question or a propaganda piece that sets you off in the wrong direction.
Ability, opportunity and intent is a triad used for assessing if someone is a threat to you. With Russia, strike out watching for intent.
It is impossible to know the intent due to the Russian regime playing games, but also because the Russian regime is truly unstable. Pretty much any behavior or intent can manifest itself - including cruel or bizarre ones - depending on the outcome of power struggles and of outright mistakes.
Furthermore many of the things Russia says it wants to achieve would be of no material importance to it and would likely not make it happier.
Instead, focus on opportunity. With a firm policy response, consisting both of military, diplomatic and economic means, opportunities for destabilizing Europe or for that matter Russia, will be scarce.