Showing posts with label learning. Show all posts
Showing posts with label learning. Show all posts

Friday, January 2, 2015

Innovation is not a hotdog

Once upon a time


You would walk in a supermarket, buy hot dogs and hot dog buns. It was a pretty straightforward process. Sausage pack, check. Buns, check.

Then, someone had the idea of making a bun length sausage. Hmm, ok, except that different brand of "bun length" sausages and buns all have different metrics. But hey, that's ok, it was a valiant effort.

More is more


Some time passed, and somebody thought, "hey, let's make a sausage longer than the bun!". Of course, all readers will be quick to point out that there never was a sausage exactly the length of a bun, they were either slightly shorter, or slightly longer. It was just a "more is more" marketing.

What's next


You are probably expecting a sausage to appear on the market "shorter than the bun!". And the circle will be complete. But, which one is the better design? Which one innovates? Same answer to both question: the original design for sausage, which dates back to at least the 9th century BC. Anything beyond that is in the presentation (the marketing).

Tech innovation


Now, back to technology. Let's take the phone, for example. Clearly, going wireless was an innovation. Going pocketable was an innovation. Touchscreen. Haptics. Innovations. But the same tech, just in a different (bigger and bigger, a.k.a. "more is more" marketing) package, is not innovation (*cough* apple *cough* samsung). In fact, one could say there is a clear regression in that field (phones used to have battery life expressed in weeks, could fit in your pocket, even in jogging shorts, could be dropped multiple times on rock hard surfaces without any problem etc)

You can do it


So, why am I talking about all of that? Well, it's my yearly encouragement to truly innovate (see last years post here). But you can't do it in a vacuum. Engage in your local community. If you haven't done so yet, make it a goal this year. Your local programing user groups (Python, Java, Javascript, whatever), maker space or hacker space, robotics, raspberry pi or other creative group, you local coworking, STEM/STEAM school groups etc. Not only will you benefit from attending, by growing your network and your knowledge, but you'll contribute something back to your community, to the society.

Before I sign off for the day, do read my post on innovation in general and personal scale innovation from last year.

@f_dion

Monday, February 3, 2014

Python tip[8]

Tip #8

Always use a good bit of data to test your data driven apps. Don't rely only on nose testing. But where to get data? Fake it. Never underestimate the power of import random. But when you need more than numbers:

pip install fake-factory

You can also take a look at faker, faker.py, ForgeryPy (and many more on pypi.python.org). Then there is fake-data-generator. Or if you want a csv or sql, try mockaroo.com

What it does: Although you could use real data, sometimes you don't have any. In fact, more than likely you probably wont be  able to generate a significant amount of data for weeks after going live with your web application. Or perhaps it is a desktop application and you'll never see the generated data. So just fake it. You need volume, and it's easy to create.

Another point to keep in mind is that using real data might be risky, depending on what it is. For sure you do not want real credit card numbers floating around on development instances.




François
@f_dion

Sunday, January 26, 2014

Python tip[7]

Tip #7

Today's tip is quite basic, but will require time and effort to master:

Master the shell environment

What it does: Mac, Windows, Linux, BSD or Unix (or even something else). Whatever your operating system, become really good at using the command line, the shell. Bash, Powershell, ksh93 etc. Learn it. Else, it's like learning a bunch of words in a new language, but never learning the correct constructs. You might be able to communicate, but it'll never be very efficient. So go and find tutorials.

And then find the tools that'll make your life easier.

For example, *nix users, are you familiar with autojump (plus it's written in python)?

Windows users, did you know there is an equivalent Jump-Location for powershell?


François
@f_dion

Saturday, January 25, 2014

How projects nights are enablers for innovation

Project nights


Do you attend project nights organized by your local maker group, hackerspace, python user group, raspberry pi user group or other similar tech meet?

No? Why not, is it because there are none? Suggest it, then. Or perhaps it is because you do not have anything to present, or do not need help with any projects. Having said that...

Innovation

Is not inventing something brand new from scratch. It's about standing on the shoulder of giants (a true, if somewhat overused metaphor). Taking many different things and bringing them together into a coherent entity, either a finished good, a software, a consumable or a building block for something else, in a new, innovative way.

It is not easy to achieve that. Are you familiar with all the bleeding and leading edge stuff happening in the tech space, in you area of expertise? Outside your area of expertise?

By attending project nights, and exchanging with people with different backgrounds and fields of expertise, the probability is much higher that you will come up with a solution, or even a new idea. But, more than that, it's at a personal level that you may benefit...

Personal scale innovation

While we all (well, a majority) would like to create the next big thing that will revolutionize the well being of mankind, truth is, what is more likely is to innovate at a personal level, household level or local community level. And your innovation or discussion may trigger another one, that is, if you are involved in some way in your community.

As an example, PYPTUG had a recent project night. One project was exploring the python picamera module. What started as that ended up creating two new projects, one based on Pi NoIR, the Raspberry Pi camera with no IR, as a way to detect heat loss (we'll see how well that works), and the other, as a helper to solder SMD devices.

Each month, there are many such moments of personal scale innovation. Perhaps not iPhone or Pebble (or Raspberry Pi) worldwide game changing innovation, but personal and local scale innovation.

François
@f_dion

Monday, January 20, 2014

Python tip[6]

Tip #6

Today's tip is in response to a great question on a local Linux user group:

python -m cProfile myscript.py

What it does: It'll give you a breakdown per line of how much time each operation takes to execute. Normally, profiling is best done with something like dtrace, to minimize the impact on the run time, but the original question was about figuring out the time for each operation in a python script running on the Raspberry Pi (no dtrace...).

Assuming the following script (we'll use sleep to simulate different runtime, and not call the same function either, else each would be collased under one line on the report):
from time import sleep

def x():
    sleep(4)

def y():
    sleep(5)

def z():
    sleep(2)

x()
y()
z()
print("outta here")
we get:
python -m cProfile script.py
outta here
         8 function calls in 11.009 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   11.009   11.009 t.py:1(<module>)
        1    0.000    0.000    4.002    4.002 t.py:3(x)
        1    0.000    0.000    5.005    5.005 t.py:6(y)
        1    0.000    0.000    2.002    2.002 t.py:9(z)
        1    0.000    0.000    0.000    0.000 {method 'disable' of '_lsprof.Profiler' objects}
        3   11.009    3.670   11.009    3.670 {time.sleep}



François
@f_dion

Tuesday, January 14, 2014

Python tip[5]

Tip #5


Meet the triumvirate  of python interactive sessions:

help(), dir(), see()

So no doubt you use help, and probably dir, but you are probably wondering about see()... That's because it has to be installed first:

pip install see

What it does: Unless you speak native dunder (double underscore), dir's output can be a little overwhelming. For example, a dir on an int object (everything is an object in python...) gives us:

>>> dir(1)
['__abs__', '__add__', '__and__', '__class__', '__cmp__', '__coerce__', '__delattr__', '__div__', '__divmod__', '__doc__', '__float__', '__floordiv__', '__format__', '__getattribute__', '__getnewargs__', '__hash__', '__hex__', '__index__', '__init__', '__int__', '__invert__', '__long__', '__lshift__', '__mod__', '__mul__', '__neg__', '__new__', '__nonzero__', '__oct__', '__or__', '__pos__', '__pow__', '__radd__', '__rand__', '__rdiv__', '__rdivmod__', '__reduce__', '__reduce_ex__', '__repr__', '__rfloordiv__', '__rlshift__', '__rmod__', '__rmul__', '__ror__', '__rpow__', '__rrshift__', '__rshift__', '__rsub__', '__rtruediv__', '__rxor__', '__setattr__', '__sizeof__', '__str__', '__sub__', '__subclasshook__', '__truediv__', '__trunc__', '__xor__', 'conjugate', 'denominator', 'imag', 'numerator', 'real']


>>> from see import see
>>> see(1)
    +           -           *           /           //          %           **
    <<          >>          &           ^           |           +obj
    -obj        ~           <           <=          ==          !=          >
    >=          abs()       bool()      divmod()    float()     hash()
    help()      hex()       int()       long()      oct()       repr()
    str()       .conjugate()            .denominator            .imag
    .numerator  .real


A little more human readable, no? Oh, I'm about to hear the complaint about typing from see import see everytime you start up python. Time to go and check tip #2...


François
@f_dion

Friday, January 10, 2014

Python tip[4]

Tip #4


I was mentioning cppcheck on twitter, for those of us who also code in C/C++. I must admit I didn't start using it until I saw Alan (Coopersmith) using it on Xorg about a year ago. So, what do we have for python? Today I'll make a quick mention of Pylint. Install is simple, along the line of (adjust to your package manager):

sudo apt-get install pylint

Then you can go into a python project and do:

pylint your_filename.py

What it does: "Pylint is a tool that checks for errors in Python code, tries to enforce a coding standard and looks for bad code smells", according to pylint.org. It also gives your code an overall mark. It's a good idea to at least run it and look at the suggestions it offers.

Bonus: pylint includes pyreverse which allows one to generate a package and class diagram (UML) from source code. This works ok as long as the code is straight forward.


François
@f_dion

Tuesday, January 7, 2014

Python tip[3]

Tip #3

As you install new modules (say, with pip install) to support your Python application, add them to a requirements.txt file and do the same for your tests, as test_requirements.txt. Installation is then a simple:

pip install -r requirements.txt

What it does: It allows you to keep track of what packages are needed if you share your code, deploy it to other machines, or if you somehow have to rebuild your computer. You can also quickly test that the list is up to date by creating a virtualenv --no-site-packages, and then using a pip for that virtual environment to do the install.


François
@f_dion

Wednesday, January 1, 2014

Python tip[2]

Tip #2

In your home directory, in a file named .env.py put the imports you want to always have preloaded in python interactive mode:
from some_module import something
In your .bashrc or .profile, add:
export PYTHONSTARTUP=$HOME/.env.py
What it does: When you login and open a terminal, the environment variable PYTHONSTARTUP will be set, and when you execute python (or bpython, too), the python interpreter will load whatever scripts are in PYTHONSTARTUP and be ready for you to use them without having to type them everytime. In this example, I could use functionality something of some_module right away.


François
@f_dion

Tuesday, December 31, 2013

Python Tip of the [day, week, month]

PTOTD

Starting tomorrow, I'll post a Python tip on a regular basis. I cant promise a PTOTD, but it'll be more often than once a month, so that identifies the boundaries.

Ok, I lied, I'll start with one right now:

Tip #1

python -i script.py
What it does: At the conclusion of the execution of script.py, instead of exiting, the python interpreter stays in interactive mode, with everything ready to be printed or debugged.

François
@f_dion

Thursday, August 22, 2013

From Java to Burma

Hands on Python


This month at our local Python user group (PYPTUG), I'll do a hands on session. Could have been in a workshop, code dojo or project night, but it'll be part of the normal monthly meeting.

Attributes, Properties and Descriptors


A lot of people learned C++ or Java in school and some of the normal patterns for these languages are regularly seen in the wild in languages such as C# and Python. Having coded in all of these, and many more, I appreciate greatly some of the features of a given programming language. And when it comes to Python (as Roger Sessions said, paraphrasing Einstein), that "everything should be as simple as it can be, but no simpler".

 The hands on will focus on attributes, and how to keep it simple. And of course, how to get out of trouble, because you have to do something not so simple later, using properties and descriptors.

I will be posting to my bitbucket pyptug repository some material related to the talk, including a log of the interactive session we will be doing.

Audience will be ranging from people who have never coded, to people who have programmed in other languages, to python experts. I love a challenge.

François
@f_dion

Sunday, August 18, 2013

200000th visitor




Raspberrypi and Python


In February 2013, this blog reached the 100,000th visitor milestone. Tonight, it just past the 200,000th.

This little experiment has been ongoing for almost a year now. As I had mentioned before, I didn't expect a lot of visitors due to the specificity of the blog, but it was something I had to do. Most projects I do for business, I cant talk about, so I've made up some projects specifically for this blog.

The Raspberry Pi has continued on the road to popularity, and this has exposed many people to embedded computing, to software development and electronics, and that is a good thing. Some other subjects that have been popular over the year have been Brython, ZFS and dtrace.

I've seen people I've introduced to the Pi, to electronics or to replicators (ie. CNC, 3D printers, laser cutters), to Python or Brython come up with some really cool stuff in the past year, and that is ultimately quite rewarding.


The visitor 

So, where is this 200,000th visitor from? Surprisingly from the town of Sanford, NC. I say surprisingly because it is only an hour and a half away from Winston Salem by car.

Sanford, NC


François
@f_dion

Friday, August 2, 2013

A python interactive console in my blog

Brython modes

I had prepped a presentation on Brython for a Python conference and didn't want that to go to waste, so now, dear reader, you get to see all kinds of exclusive material I had made for it. (Don't worry, I'll have plenty more material for PyCarolinas 2013).

The difference is that this is a blog, not a talk, so it will be a good bit more non linear. I'm starting tonight with something very hands on, one of Brython's mode of deployment.

The Brython interactive mode

The brython.js script itself is not included in this page, so it is a hosted interactive mode. We will simply include an iframe to load an interactive console directly from brython.info. This is still quite experimental, as it is found under the tests/ section. It is now using most of my iframe box (was fixed some days back). But it does work pretty well already.

This is basically a zero install, just add the following in your web page and you'll get a brython interactive session (Edited 3-26-2014 to point to new location):  

<iframe src="http://www.brython.info/console.html" width="98%" height="400">Sorry... your browser doesn't support iframe. Time to upgrade or go to <a href="http://www.brython.info/console.html">http://www.brython.info/console.html</a> in a separate tab.</iframe>






So you should see a console above (wont work trough news aggregators). At the >>> | prompt, type:

x = input("yo")

Type the word me in the prompt dialog that will open. Make sure you type exactly that. So what do we have in x? Type the following:

print(x)

me - Ok, that's all nice, but not very exciting. So it does behave like a console. What else can we do?

import webbrowser

So now we have loaded the module webbrowser from the brython standard library (we will come back to that in a future article). Yeah, I know, mind bending, since we are client side. Let's use the module. Type the following:


webbrowser.open("http://en.wikipedia.com/wiki/internet_" + x*2)

Nice! All your base are belong to us, obviously. So, it does take a minute to get the brain wrapped around this concept, but once you do, the world's your oyster. You just have to:

doc <= "think"
:)

Alright, enough geek puns, but it is a friday night afterall. So go and check it all out at http://brython.info . There is documentation in english, french, spanish and portuguese. Feel free to contribute your own translations in markdown format through bitbucket.

If you've been following my blog, you already know about the <= (left arrow) operator. If not, check it out here: http://raspberry-python.blogspot.com/2012/12/brython-browser-python.html

In the early days, brython didn't have a print() keyword. So I had cooked up a quick webprint() that used the <= operator. Of course, 8 months later, we no longer need webprint(). Print works like it should, with stdout. For the interactive mode, it is redirected. Look at the (python) code to see how you can do that by right clicking on the iframe and doing a view frame source (hint, lines 48 to 51).


François
@f_dion


Thursday, July 25, 2013

Of videogames, arduinos and 10 year olds

Vpython

That's Mr. Visual Python to you (the visual module, that is). At the last PYPTUG meeting, Aaron Titus gave a talk on Visual Python. I think it was about writing (well, mostly playing) videogames under the veneer of learning physics. :)

All joking aside, it was a really great talk. It was also the first time we were using Google+ Hangout to help some members to check the presentation. And particularly a father and daughter who would not have been able to make it in time for the meeting. More on that further down.

Pyfirmata lightning talk


So I gave a lightning talk on Pyfirmata and Arduinos. It was part of my talk at PyCarolinas last year but didn't have time to go into the code detail (plus another talk earlier that day had covered really extensively serial communications). And it's really about serial communications (be it USB, bluetooth or plain old RS-232/rs-422) and microcontrollers (it's not just for the 'duinos). I ran the python code on a Raspberry Pi, but you could use pretty much any computer that can run python.

The protocol is firmata: http://firmata.org

The python module is Pyfirmata: https://github.com/tino/pyFirmata

To install, you can use :
pip install pyfirmata
or
easy_install pyfirmata

Since both pip and easy_install automatically install dependencies, that's all there is on the host computer side.

Or from source using setup.py, but you will have to install the serial module.

You dont have to handle the serial stuff yourself, just point to the right /dev/ (serial, usb or bluetooth), start an interator and start using read(). Pyfirmata handles the serial itself and sending/receiving the sysex bytes (Firmata is a MIDI inspired protocol).


To install the firmata firmware on the Arduino, start the IDE and go to:

http://lizarum.com/assignments/programming/images/pd/arduino/standardFirmata.png

The bitbucket repository for my talk (presentation and simple example that reads values from analog port 0 on the arduino) is at:
https://bitbucket.org/fdion/pyptug

 

The young coder

"After watching the stream, this morning I left my 10 year old building spheres and boxes in VIdle.  She'd never done programming of any kind before last night." -- Ryan

I think this speaks volume about Python and the visual module. And that's what PYPTUG is all about. Now we just got to get her a Raspberry Pi.

François
@f_dion

Sunday, July 21, 2013

Trip to the bookstore


Community 


Part of a good local technical community is having local technical schools, hackerspaces, computer stores, electronics parts distributors, libraries and book stores with good technical books, and of course user groups.

For PYPTUG community news, I try to always make a note of Python related things wherever I go so I can share it with fellow community members in the Piedmont Triad.

This is suspiciously easy


Python is easy to get into. In fact, here's something on the back of a book I saw at the local Barnes And Nobles (Hanes Mall, Winston Salem, NC):


Hello! Python



Couldn't help but to share that with my wife. It is on the back of the book Hello! Python by Anthony Briggs.

And that too


Using the Raspberry Pi in various projects is also quite easy, and having tutorials or a guide makes it that much easier. Of course I have plenty of tutorials on my blog, but if you are looking for a Raspberry Pi book you can hold in your hands, there are a few available now, and if you are in the Winston Salem area, you can pick these up without having to wait for the postman:

Raspberry Pi User Guide by Eben Upton


Getting Started with Raspberry Pi


Programming the Raspberry Pi

Nice to see this on the bookshelves.

Adding Arduino to the mix


And speaking of Raspberry Pi, tomorrow I'll be doing a lightning talk on something I had talked about back in 2012 at PyCarolinas. I was going to get into more details at PyOhio, but as you've no doubt noticed, I'm not on the speaker list, so instead I'm covering this locally at PYPTUG.

So what is it? A super easy way to interface with microcontrollers, including the Arduino, using Python. Did I say super easy? Suspiciously easy :)

François
@f_dion

Thursday, February 7, 2013

sudo ./laserpulse.py

Tron, Laser, Lissajous, RaspberryPi


Am I throwing together random words for titles now, in a weird captcha induced moment? No,  just condensing my interest in lasers in a few words.

You might have seen the laser digitizer in Tron: Legacy


However, in my case, what triggered my interest in laser, was the original Tron laser digitizer


A few years later, I had the chance to play with a good old HeNe red laser, pumping a mighty 5mW (well, in the 80s, it was impressive) in the college lab. One of the things I did with it was to draw Lissajous figures (or curves) on a wall (a large wall outside, at night - even cooler), using two little speakers and mirrors I had brought (the lab was set up to only do prism and mirror experiments).

Googling, I see a nearby school (Appalachian State) has one such kit in their physics dept:
http://www1.appstate.edu/dept/physics/demos2/oscillations/3a80_40.html


Anyway, fun stuff, making math and physics a lot more interesting...

Electronica


There was the artistic connection that also further fueled my interest in lasers. There is a lot to talk about here, since I've composed and performed electronic music for many years (still write some) and hosted a radio show for about 10 years etc, so that'll be for another time.

I will bring up one point right now though: you cant talk about lasers in music shows, without mentioning Jean Michel Jarre.

Jean Michel Jarre, Houston TX 1986
From his incredible live outdoor shows with lasers, lights and fireworks (one, a tribute to oceanographer Cousteau, had an attendance of over 2 million people in France in 1990) to his laser harp. Jarre without lasers wouldn't be the same.

On the road


The Raspberry Pi has a lot of appeal by itself, but I figured that it would probably be a good idea to add a laser in the mix. Since I had a presentation at PyCarolinas, I figured I'd write a script with Python (laserpulse.py, hence the title of this article) and build a little rig to project interesting patterns on the wall behind me.

My 50mW laser rig (also 500mW for day use)

The code for the pulsing is basically what is found in the RPI.GPIO dot dash article, and for the motor, in the 2bit H bridge article and PWM article.

So, using a laser in presentations, does it work? Well, at PyCarolinas, I got a lot of feedback on this, both during the presentation, after the presentation and even during other talks (heard during another talk "so we've learned today that lasers are cool")

In the audience: "I just want to say that this is the coolest command, ever."

On twitter:

Calvin Spealman
@ironfroggy
sudo laserpulse.py with actual lasers! #pycarolinas
08:45 PM - 21 Oct 12

And so on and so forth. The conclusion is this: Science needs some showmanship. But please, be careful when playing with lasers!


Video


So I'll leave you with a video of my little rig above controlled by the Raspberry Pi, going to the music of a very British band, doing a cover of the theme of a very British TV show. Very apropos, since the Raspberry Pi is a very British computer, afterall.





Youtube video (Music by Orbital, Doctor? live at BBC)

[edit] I fixed the youtube link



François
@f_dion

Saturday, November 17, 2012

Python Speak Hint

A hint for our current python challenge:

$ sudo apt-get install espeak

or

import pycairo

Depending which challenge you picked... The answer will probably vary if you try it under Raspbian versus Debian, it is all in the library.

Wednesday, October 31, 2012

MagPi

I just received a printed copy of The Mag Pi #6, from the folks at ModMyPi.
I do have the PDFs for #1 to #6 but when I heard somebody was printing it at a commercial printer, I figured I had to get a copy. Although it is #6, it is the first copy to be printed on paper.

It reminded me of the good old magazines I would get as a kid such as InCider, Compute etc. BTW, digging in my old magazines, I saw that Compute was published on Wendover Ave in Greensboro, NC. That's interesting to me because that's not too far from where I'm at.

And speaking of this area, if you live near it, I would like to suggest you check out PYPTUG. We'll be having a workshop with Python and the Raspberry Pi on November the 10th.

Anyway, back to The MagPi:

#6 October 2012
QR Code, even

And speaking of ModMyPi, I ordered a "surprise" color mix case. It's the cheapest option they have, but you never know what colors you'll get. Red and Black, I think that worked out well for me:

Replacing the white case of my RISC OS laptop

Color contrast works well with my Motorola LapDock RISC OS machine.

Wednesday, October 24, 2012

Pocket Mini Computer kit

On my previous post, Blue Screen Of Basic, I was showing the output of a computer mini kit I just built.

What

The Pocket Mini Computer is a simple kit that can be put together in an evening. Just like the Raspberry Pi, it is a bare board (quite like the Apple I). You then need a keyboard (PS/2), monitor (VGA) and power supply (5V, mini USB).

It is not a competitor to the Pi, particularly based on spec and price. It wont run Linux. At any rate, you are probably anxiously waiting on your backordered Raspberry Pi and Gertboard, so that'll give you something to do, hehehe.

Rather, it's something to learn soldering on (or in my case, have fun building stuff, like people do puzzles or crosswords), and play with Propeller Basic and SIDCOG, an emulation of the SID chip including filters using one of the 8 "cogs" (core) of the "processor".

I should really say microcontroller. It runs on a Parallax Propeller microcontroller QuickStart board which is included in the $39 price tag (and that is less than what Radio-Shack sells the P8X32A by itself!)

The box



The bags


  

The parts


Bonus

While supplies last, Jeff includes a laser cut acrylic reference block for the P8X32A GPIOs.

Now, let's build this.

Sunday, September 16, 2012

En francais

Je vois que j'ai des visiteurs du Canada et de France. Je ne vais pas faire comme SolarisDesktop que j'ai aussi ecrit en francais et en espagnol. C'est trop de boulot d'ecrire trois blog a chaque fois. Mais plutot, je vais alterner entre les differentes langues et couvrir des sujets differents.
Ca me permettra aussi d'y aller en Portugais et Russe et d'ameliorer mon niveau de communication dans ces langues.
Alors, lecteurs, je vous passe la parole, que voulez-vous savoir sur le Raspberry Pi? Laissez le moi savoir en commentaire.
Oh, et soit dit en passant, il y a un forum pi en francais sur le site officiel. On le retrouve ici: raspberrypi.org forum en Francais