Archive for category Programming

Using JSON between Javascript and Python

JavaScript can’t access local files; this makes it troublesome to work with databases and files without including someone’s “black box” and risking all manner of compatibility and security issues you have no control over.

Required Skillsets


You need to be familiar with both Javascript and Python, and their typical execution environments, for this information to be useful to you. Both are easy languages to learn, and the web is replete with tutorial sources aimed at providing that familiarity. Database use with Python can be with SqLite, or PostgreSQL, or MySql. Again, plenty of resources out there to help with learning SQL.

Python, on the other hand, has no such problems. It can handle files and databases directly, and you have every opportunity to keep things safe and secure. Python is readily available on your typical server; Javascript is built into most browsers.

So here is a skeletal example of how to get data from JavaScript to Python and back again that doesn’t require any extra JavaScript components, and therefore puts you in complete control of whatever risks you face, including resolving any bugs without having to depend on anyone else.

You can use this to build your own communications, adding all the security and reliability tweaks you desire, or none, for private, off-net use.

If, in pursuit of the kind of inter-language linking I demonstrate here, you’re thinking “Database!”, then I would also point you to my SqLite simplifier and PostgreSQL simplifier projects.
Read the rest of this entry »

Tags: , ,

Why I Target OS X 10.6.8

OS X has come a long way since OS X 10.6.8; among the pluses: better multiple monitor handling, considerably improved memory management (part of which was fixing the leaks in the color management pipeline that OS X 10.6.8 exhibits) repairs to the bugs in 10.6.8′s CUPS printing system, and so on.

So why, then, target OS X 10.6.8?
Read the rest of this entry »

Tags: , , , , , , , , , , , , , , ,

Introducing the SJW language

Mellow greetings, special butterflies
 

Today (not to disrespect those on the other side of the national dateline – when I say today, I mean everyone’s today!) I (with full credit to everyone everywhere, of course) would like (this is not a statement of exclusion for things I don’t like) to introduce SJW, the language you can share without fear (not that fear is wrong, of course.)

SJW:

• No insert() function: Instead, we have crafted a flawless nomeansno() function
• Fully complementary yesmeansno() and maybemeansno() functions
• No try:, because every function generates an exception!
exit() has been replaced with aloha().
• Procedure calls have been replaced with the respectful request paradigm, which obey the global mood settings
• 100% private internal assumption for all functions; offering data requires guessing if the function will take it or crash (exceptions guaranteed)
• Every access from within a function to another function must be embedded in a call to politewrapper()
politewrapper() implements infinite recursion by use of counters instead of ever returning up a level
• Every function ends with a sequence of calls to apologize(), cleanup() and washreturnvalue()
• All programs will be created equal: all code is treated exactly the same and does exactly the same thing, which is apologize for running.
• All programs are required to check their privileges before running.


Apology

I apologize for saying “national dateline” when clearly I should have said “international dateline.” I am sorry for any consternation caused to nationalists, internationalists, jingoists, and timekeepers. In addition, I apologize to anyone I failed to mention. I will now enter into a voluntary two-week exclusion from mentioning time in any form. I also apologize for violating that two week exclusion with the previous sentence. Also, as “previous” is a timewise reference, I also apologize for that. I’m sorry. Truly sorry. Which is not to offend those of you who are more sorry about other things. I fully respect that, I swear. Not in an offensive way, of course.


A Cautionary Wail

First they came for the aggressors, and I did not speak out—
Because I was not an aggressor.

Then they came for the micro-aggressors, and I did not speak out—
Because I was not a micro-aggressor.

Then they came for the nano-aggressors, and I did not speak out—
Because I was not a nano-aggressor.

Then they came for me—and I meekly submitted.

Tags: , , , , , , , ,

Linux and OS X console: Are you working too hard?

Recently, I had a friend, a serious Linux aficionado, come over and we had occasion to sit in front of my machine while I was doing some console work. I do a lot of work under OS X using the GUI, and previously that is what had been on-screen when he had visited. This time, however, I had some consoles open to one of my web servers.

I did a few things during which he was uncharacteristically silent. During a pause in my typing, he spoke up with a note of real interest: “That’s unbelievably awesome. What is that?”

“Midnight Commander”, I told him.

Now he uses Midnight commander too. All the time. I thought I’d tell you why.
Read the rest of this entry »

Tags: , , , , , , , , , , , ,

aa_counter.py — pre- and post-increment and decrement in python

Screen shot 2015-05-24 at 3.36.42 PMI like Python. A lot. But it has its limits, and short of forking a new version of Python for myself, sometimes it is just best to implement some kind of work-around. In this case, for pre- and post increment and decrement operations on counters, which Python regrettably lacks.
Read the rest of this entry »

Tags: , , , ,

aa_webpage.py — awesome and easy web pages with Python

I do a lot of generating web pages using Python. Python because I think Python 2.7 is awesome, and web pages because I do lots of work with various web sites that require dynamic results. Python is a very useful tool for me to get those dynamic results. It’s server-side (at least, the way I use it, it is, because I really try not to embed client-side resource usurping things), it is fast and efficient, and it is what I am comfortable with.

The thing is, web pages — generally speaking — aren’t all that simple if you really do them right. You can’t just throw a few tags together, test them on one browser, and hope you’re golden. Because you won’t be, I can pretty much promise you.
Read the rest of this entry »

Tags: , , , , , , , , ,

aa_dbo.py — Simplified PostGreSQL use from Python

Screen shot 2015-05-04 at 3.00.37 PMHere’s a Python import library that, working in conjunction with the PyGreSql project, makes using PostGreSQL from within Python super, super easy. Complete with examples. You need PostGreSQL installed and running (obviously, I hope), and you’ll need to install the PyGreSQL Python module as well.

Click here to download the import library.

Revision Changes
1.0.1 Initial Release
1.0.0 Internal Version

Tags: , , , , , , , ,

Making Python’s sqlite3 import easy as 1 2 3

Lurking within the normal Python 2.x distribution is the sqlite3 import, which is an amazingly powerful, no-server-required, mostly SQL compatible database engine that can be used in any project without restriction.

That’s the up side. The down side is, as a fairly complete database, there are many options and varied ways it can be used, and managing actual database transactions isn’t all that simple — to do it right, even a single query takes about sixteen lines of code. And yes, if you want maximum flexibility and the ability to use every feature in sqlite3, that’s how you should do it.

But. Most database operations are very straightforward. You want to issue a single command to the database, or a query. Perhaps you want to write a bunch of data and then commit it all at once so that the database doesn’t contain part of the data from a more complex transaction. You need to know if something went wrong, and if it did, what it was. Those are by far the most common use cases for me, and I suspect that’s true for others as well.

Frankly, it’s difficult enough dealing with the SQL query language itself. Why make actually using it harder than it has to be?
Read the rest of this entry »

Tags: , , , , , , , , , , , , , ,