I would like secure single-sign-in across multiple hosts. An easy way to do this is with ssh-agent, however, ssh-agent is a bit limited. For example, the normal use of ssh-agent looks like this, $ ssh-agent SSH_AUTH_SOCK=/tmp/ssh-stSwW11394/agent.11394; export SSH_AUTH_SOCK; SSH_AGENT_PID=11395; export SSH_AGENT_PID; echo Agent pid 11395; You would need to set those environment variables to use […]
Author: timwarnock
python, finding recurring pairs of data
I would like to find all pairs of data that appear together at least 10 times. For example, given a large input file of keywords: >>> foo, bar, spam, eggs, durian, stinky tofu, … >>> fruit, meat, vinegar, sphere, foo, … >>> merlot, red, hearty, spam, oranges, durian, … >>> … “durian” and “spam” appear […]
python, analyzing csv files, part 2
Previously, we discussed analyzing CSV files, parsing the csv into a native python object that supports iteration while providing easy access to the data (such as a sum by column header). For very large files this can be cumbersome, especially where more advanced analytics are desired. I would like to keep the same simple interface […]
python, analyzing csv files, part 1
I would like to analyze a collection of CSV (comma-separated-values) files in python. Ideally, I would like to treat the csv data as a native python object. For example, >>> financial_detail = Report(‘financial-detail.csv’) >>> transactions = {} >>> for row in financial_detail: … transactions.append(row[‘Transaction’]) … >>> financial_detail.sum(‘Tax Amount’) Decimal(‘123456.10’) >>> Additionally, I would like to […]
python, unique files by content
I would like to retrieve a list of unique files by content rather than by filename. That is, if spam.txt and eggs.txt both contained the same contents I want only one of them to return. A very simple approach is to compute a SHA-1 checksum on each file, and build a dictionary with the checksum […]
python daemon
I would like to create a python daemon, completely detaching from the terminal or parent process, and yet retaining any log handlers through the python logging module. There is a wonderful example at cookbook-278731 of a well-behaved daemon, and see PEP 3143. Borrowing from these examples, here is a simple daemonize function that will retain […]
python logging
I would like customizable logging in python applications, and I would like to easily send log messages to multiple handlers without any modification of the application code. The built-in logging module provides a very robust and easy-to-use logging capability. In it’s simplest form, log messages will be sent to the console with minimal formatting, e.g., […]
HTML5 canvas Mandelbrot
I would like to create an animated Mandelbrot visualization using JavaScript on an HTML5 <canvas> element. The Mandelbrot set, popularized by BenoĆ®t Mandelbrot, is the set of complex numbers that remain bounded under the function zn+1 = zn2 + c. This is known as an escape function; that is, regardless of the size of n, […]
javascript keyboard buffer, part 4
Previously, we created a JavaScript keyboard buffer that can edit text in a static html page as well as play back each key as it was typed. I would like to combine all of this into a single JavaScript include called keylogger.js, and rather than specify each div that I want to edit I’d like […]
javascript keyboard buffer, part 3
Previously, we created a javascript keyboard buffer that can edit text in a static html page. Using those functions I’d like to add a buffer replay. I would like to add an onclick event to a specified div such that it will activate the keyboard buffer and leverage the previously discussed handleKey() event handler, as […]
javascript keyboard buffer, part 2
Previously, we created a javascript keyboard buffer and next I’d like to process that buffer to edit text in a static html page. Given the following simple html: <div id=”keyboardBufferTest”> Spam and eggs </div> I would like the keyboard buffer to modify the text inside that div element. The following JavaScript function will read the […]
javascript keyboard buffer, part 1
I would like to capture keystrokes in JavaScript, save them to a buffer, and play them back exactly as they were typed. There are three onkey events that can be assigned event handlers, these are, document.onkeydown = eventHandler document.onkeypress = eventHandler document.onkeyup = eventHandler When one of these events is triggered, the unicode representation of […]
javascript prototype
I would to extend the functionality of a JavaScript class, for example, to add utility functions to a specific Object. Object.prototype The prototype property can be used to add new properties and functions to any object, including built-in objects. For example, you could extend an Array as follows: // // extend Array objects, test if […]
sql, users not in group
I would like to find all users not in a specific group, given the following database schema: CREATE TABLE foobar_users ( user_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, username VARCHAR(20) UNIQUE NOT NULL ); CREATE TABLE foobar_groups ( group_id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, groupname VARCHAR(20) UNIQUE NOT NULL ); CREATE TABLE foobar_users_groups ( user_id INT […]
css opacity in javascript
I want register JavaScript events to toggle CSS opacity on selectable images. For example, given a div with a list of images like the following, <div id="foo_images"> <img src="foo.jpg" /> <img src="bar.jpg" /> <img src="baz.jpg" /> … </div> I would like these images to be 50% transparent but 80% visible during a mouseover. I would […]