RSSAmplifier

Blog

galvanist

Recent content on galvanist

/RSS feed ↗48 posts

Latest posts

S.D.

Machinist, artist, adventurer, Polie, Australian, friend… has died. 
 Blossoming multitudes are paying tribute: those impressed by his skill, those who were welcomed and comforted by his friendly and generous nature, those who laughed at his humor, those who survived with him through hard winters, those who loved him, and those who tolerated his excessive consumption of British science…

Django SECRET_KEY generation

Generate django SECRET_KEY s on the command line using this “one-liner” (django not required) 
 Background 
 Django is a Python web framework with a lot of nice features including an exceptional ORM and high quality documentation . Most of my experience with django has been deploying and debugging other people’s projects - during the course of which I often want to…

macOS JavaScript for Automation (JXA) Notes

Overview 
 There is a macOS feature called the Open Scripting Architecture (OSA) which provides an infrastructure for intercommunication and automation of macOS software. One of the officially supported OSA languages is JavaScript and its use in this context is called “JavaScript for Automation” which is often abbreviated to “ JXA ”. 
 The idea is that instead of…

Security Resources for Your New Website

Establishing a reasonable amount of security for a website is a non-trivial unending job. Here are some notes and resources that I find helpful. 
 Web Server Config 
 Start with TLS 
 All public-facing websites need to be protected by Transport Layer Security (TLS). TLS is a technology which allows web traffic to be encrypted and this encryption helps to protect the privacy and…

macOS Text-to-Speech World Tour

When it comes to text-to-speech, macOS supports more than 50 languages/dialects. Many of these are voices from Nuance Communications . 
 $ say -v '?' 
 Alex en_US # Most people recognize me by my voice. 
 Alice it_IT # Salve, mi chiamo Alice e sono una voce italiana. 
 Alva sv_SE # Hej, jag heter Alva. Jag är en svensk röst. 
 Amelie fr_CA # Bonjour, je m’appelle Amelie. Je…

Better Documentation of Data with Markdown Tables

Documentation & Markdown Tables 
 Documentation is a vital part of almost any technical project. However, maintaining good documentation is hard for many reasons, one being that the time needed to document things is time you’re not spending on the “building / fixing / operating / assisting” aspects of your work – this is especially painful when you have lots of other…

Non-privileged Python Package Installs on OS X

Sometimes a virtualenv isn’t what you want. I often want my account to have a particular python package (like bpython), but I also like to keep things clean and compartmentalized. One answer is installing the package to a standard place within your user account’s home folder. Python is already setup for this, as you can see if you run python -m site . 
 sys . path = [ 
…

Giving Your Ancient Robot Arm A Storage Upgrade


 I’ve been hacking on a Giant Robot Arm at a great hackerspace called sudoroom . I’m doing so under the expert tutelage of an amazing genius or two . 
 The Enemy 
 Below you will see the YASNAC FC1 pictured. It is an incredibly slow of speed, minuscule of capacity, short of reliability, and large of footprint external floppy drive. It connects to the various robot brain…

Strip Time Machine ACLs

To strip ACLs from all files in the current working directory, run this: 
 chmod -R -N .
 You might want to do this kind of thing if you’ve restored files from a Time Machine backup by hand, preserving permissions. By default Time Machine backup files have this ACL for everyone: 
 deny write,delete,append,writeattr,writeextattr,chown
 Don’t change your Time Machine…

json2csv

Do you have a JSON file, like the staticsitegenerators.net list of static site generator software , which you want to convert into CSV format? I created json2csv for just this purpose. Check it out.

What Processes Are Listening On Your Ports?

lsof 
 On OS X you wanna use sudo lsof -nP -iTCP -sTCP:LISTEN . The output looks like this: 
 $ sudo lsof -nP -iTCP -sTCP:LISTEN
 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
 launchd 1 root 23u IPv6 0xf01241af1b915325 0t0 TCP *:5900 ( LISTEN ) 
 launchd 1 root 24u IPv4 0xf01241af1b91732d 0t0 TCP *:5900 ( LISTEN ) 
 launchd 1 root 28u IPv6 0xf01241af1b914ee5 0t0 TCP […

More Web Scraping with Phantomjs & CoffeeScript

I’ve been playing with Phantomjs and CoffeeScript a bit more. In this example I load the first page of google news, extract all the links and link text, and write them to stdout in markdown format. 
 # headlines: generate markdown-formatted output with just the headlines
 # and links from the main google news page (no sections, nothing fancy)
 page_url = 'http://news.google.com/'…

Switch Statement Emulation in Python

I’ve typically enjoyed having fall through switch statements in my programming languages. Not everyone loves em. They’re not always the right answer and they can be a bit dangerous; you miss a “break” and you “goto fail”. But they are easy to read and easy to understand – for me the switch statement is about readability (and to a lesser extent reducing the…

Javascript Duration Seconds to Years, Days, Hours, Minutes, Seconds

For a recent project I needed to express the difference between date objects as a string. Here’s an algorightm I’ve been using for a while. This time in JavaScript. JavaScript isn’t my best language, so if you have any suggestions for improvement, please let me know. 
 function fmt_duration ( seconds , detail ) { 
 // Return a string containing the number of years, days,…

Javascript Date from Python datetime string representation

In a recent project I needed to convert the string representation of a Python datetime.datetime into a Javascript Date object. Here’s what I came up with. JavaScript isn’t my best language so if you have any suggestions for improvement, please let me know. 
 function datetimeToDate ( datetime_str , use_utc ) { 
 // Return a JS Date object from the given python datetime_str…

Fixing bpython's delete

A guy named Shironoo found one solution ( which I read in english ) to a problem I’d been having with bpython over SSH. Namely that using the delete key ruins the world , or at least kills the current line. 
 My slightly modified (temporary) solution is to make this change: 
 
 in bpython/cli.py :
 
 in def p_key(self, key): 
 
 replace if platform.system() ==…

Your Mac's Serial Number via the Command Line

Here’s my first (admittedly ugly) attempt: 
 system_profiler SPHardwareDataType | grep 'Serial' | sed 's/^.*\:\ //' 
 Here’s a better one from stack exchange : 
 system_profiler SPHardwareDataType | awk '/Serial/ {print $4}' 
 Check your warranty status: 
 Update: Within a year or two of this post, Apple disabled direct URL links to hardware warranty checks, so the…

txtscan

I’ve created a small command-line program called “txtscan” for scanning the contexts of text files and reporting on the interesting characters and the line endings. It is useful for finding and identifying damage/garbage/exploit attempts in files that are basically just supposed to be ASCII. 
 “ txtscan ” is available on github.

wikitext

I’ve written a small command-line program that downloads the raw wikipedia markup text of the specified article. It does not download images or other supporting media. It does not follow links. 
 It is designed as a shortcut to using curl or wget in situations where you want article markup . For example, to get the raw markup for the “Abraham Lincoln” article, you’d…

taskpaper2busycal

I’ve created a small command-line utility called taskpaper2busycal for converting TaskPaper todo lists into BusyCal events. It’s incredibly small and easy because it leverages BusyCal’s nice URL handlers and OS X’s “open” command. It’s nice when things just work. You can find it on github (at the link above).

"Delete Above" for Inkscape

Just before Christmas, I created an Inkscape extension called “ Delete Above ” to help solve a problem that I was having converting a print-formatted map into something more suitable for a GPS app. The extension makes it easier to delete items and everything that appears to be on top of them while preserving what appears to be below. You can find it and more information about how it…

POSIX Testing my FUSE filesystem

I’m working away at my FUSE filesystem. I’ve found it incredibly helpful to run the Dawidek/Tuxera POSIX Test Suite on it. There are lots of interesting edge cases to account for. One helpful bit of info came from comp.file-systems.fuse.devel : 
 
 It seems that the options “allow_other, default_permissions, use_ino, attr_timeout=0, entry_timeout=0” fix this issue.…

Manpages in the GUI on OS X

Here’s a shell function to add to your profile that makes it easy to view man pages in OS X’s Preview.app: 
 pman () { man -t ' $* ' | open -f -a '/Applications/Preview.app' ; } 


OS X and the Unremovable File

I’ve been working on a Fuse filesystem project for quite some time. Now that OS X v10.9 is out, one of my major roadblocks has been removed. But I’ve still been experiencing some difficulty getting OS X to treat my filesystem like a first-class citizen. So to debug it I’ve been banging on it with Tuxera’s port of Pawel Jakub Dawidek’s POSIX file system test suite . 
…

OS X Quick Look Preview on the Command-line

The qlmanage command has a -p argument which lets you create Quick Look previews on the command line. So something like this can be nice to have in your shell profile: alias ql='qlmanage -p' . 
 I decided I needed something a little more featurey than an alias (because qlmanage -p README is useless). So, I made a quick python implementation of ql which has special treatment for README ,…

Revisiting Shell Concurrency (this time in ZSH)

I&rsquo;ve been thinking about concurrency in the command shell again. This was prompted by my ongoing transition from Bash to ZSH. I&rsquo;ve decided to re-implement my conc and xconc functions in a slightly different way. &#xA; Intro &#xA; Lets say you have 50 data files to compress. Here&rsquo;s one way: &#xA; % xz *.dat&#xA;<< completed in 2 minutes, 4 seconds >> &#xA;%&#xA; That&rsquo;s not…

/Users/Shared/adi

This is one for the search engines. &#xA; If you&rsquo;re running Mac OS X ~v10.8 (or later), you&rsquo;ve probably got a folder at the path /Users/Shared/adi . Like me, you might be wondering what it is. I did some googling and got nothing. I dug a little further and found (part of) the answer: It is used by the Mac App Store and the new iBooks app. &#xA; In case you&rsquo;re interested, here are…

Sort du intelligently

The du command is a nice tool for telling you the disk usage of your files: &#xA; $ du *&#xA; [...]&#xA; 1928&#x9;system.log&#xA; 136&#x9;system.log.0.bz2&#xA; 112&#x9;system.log.1.bz2&#xA; 0&#x9;uucp&#xA; 552&#x9;vnetlib&#xA; [...]&#xA; I find that adding the -h flag (which produces more human-readable output) is often very helpful for me: &#xA; $ du -h *&#xA; [...]&#xA; 964K&#x9;system.log&#xA;…

Solving The Secret Santa Selection &#34;Problem&#34;

My girlfriend&rsquo;s family does a variation of secret santa for Christmas every year instead of the more traditional American &ldquo;gift armageddon&rdquo; strategy. I&rsquo;m a fan because it encourages gift creativity and thoughtfulness while eliminating the crazy holiday consumerism that is prevalent here. &#xA; Every year the selection of giver-receiver pairs must be made and this can be a…

Direct SMTP Nagios Notifications

If you want nagios email notifications but don&rsquo;t want to run a local MTA (like postfix, exim, qmail, or sendmail), you&rsquo;ll need a command-line SMTP client. Such a program can connect to an SMTP server, authenticate, and generate a message based on input arguments and file handles. One such program is sendEmail (note, not &ldquo;sendmail&rdquo;). &#xA; I found myself wanting to use…

Tail-Recursive Function Transformation in Python

Intro &#xA; In 1986, Hal Abelson and Gerald Jay Sussman recorded some videos for their M.I.T. EECS course on the Structure and Interpretation of Computer Programs . Twenty-seven years later, these videos are still a great resource. But the language featured is the Scheme 1 dialect of Lisp and while I can/do follow along in &ldquo;edwin&rdquo;, sometimes it&rsquo;s nice to play in a (language (with…

The Birdometer v0.1a

The Birdometer v0.1a &#xA; Introduction &#xA; There&rsquo;s an old Russian proverb: &ldquo;Make a birdometer, it will be really fun.&rdquo; &#xA; So I did. &#xA; My amazing girlfriend and I like birds. We have some hummingbird feeders. We have two Arduinos . We want to start taking data about our bird guests. So, we bought some sensors from the amazing Al Lasher&rsquo;s Electronics Store in…

MapStack

In the San Francisco Bay Area, you have to write a bunch of code to even apply for I.T. jobs. It doesn&rsquo;t bother me because there is no time pressure and I usually get to work in a language I enjoy on jobs that have tidy solutions. &#xA; The annoying part is that your work just goes into the bit-bucket, even if (lucky you) you get the job. You can&rsquo;t just publish your solution because…

Arduino & OS X Notes

My girlfriend and I spent last weekend building Arduino -controlled devices. Here are some random notes about working with Arduino (in an OSX environment) &#xA; &#xA; splurge on a long USB device cable. also a breadboard and jumper wires &#xA; use stty to change baud & other settings on a device file - having access to the usual unix tools e.g. cat /dev/ttyUSB0 is a really nice thing &#xA;…

chroot jails on OS X

Recently my free time has mostly been dedicated to learning more about parallel computing. But I did take a little detour into the world of old-timey chroot(8) jails on OS X. They work, even on 10.8.4, even running a shell. The big trick on OS X is that you need to include the dynamic link editor /usr/lib/dyld in the jail . &#xA; Of course you also need to include the programs you want to run in…

Python Reverse Enumerate

I want to save this thing I came across for future reference&hellip; a nice way to enumerate over an iterable in python in reverse order while retaining the proper indexes. &#xA; Here&rsquo;s the issue. This code: &#xA; #!/usr/bin/python &#xA; &#xA; WORDS = [ 'zero' , 'one' , 'two' ] &#xA; &#xA; for index , string in enumerate ( reversed ( WORDS )): &#xA; print index , string &#xA; &hellip; prints…

Task Focus The Dock

The Problem &#xA; I was just thinking about my signal-to-noise ratio during coding and I noticed that my OS X dock has lots of stuff in it. I like this stuff. I want to keep this stuff. Also I hate a dock that hides. But I thought this: it would be nice to have an icon to click on that switches the dock between &ldquo;only show running apps&rdquo;-mode and normal mode.

Benchmarking Python Algorithms

I&rsquo;m trying to figure out a fast way to compare the speed of different implementations of a single python algorithm. One option is the timeit module . &#xA; I&rsquo;m not sure the best way to setup these comparisons, so I made a function for each implementation: divceil1 &hellip; divceil6 . Then, I made a function to run each and check its output: test1 &hellip; test6 . Finally, I&rsquo;m…

collect - a shell function

&#xA; In OS X&rsquo;s Finder, if you select some things then right-click you have an option called &ldquo;New Folder with Selection&rdquo;. ilikeitverymuch. So a while back, I though it would be alsonice to have something analogous in the command shell. I&rsquo;ve been using just such a command for about six months now and let me assure you that it is very alsonice. &#xA; What does it do, under…

Where Apple TTS Draws The Line (Numerically)

Apple&rsquo;s OS X text-to-speech supports reading some big numbers. But they have to draw the line somewhere, and that line is just before one hundred sextillion. You can hear for yourself using the handy OS X &ldquo;say&rdquo; command. &#xA; Bare digit strings &#xA; Numbering on bare digit strings stops at one million. &#xA; $ say 1000000 &#xA; You hear: &ldquo;one million&rdquo; &#xA; $ say…

Managed concurrency in the bash shell

Concurrency is all the rage these days. I started to wonder about using it in my command shell (which is regrettably still bash) because so much of the infrastructure for job control is already in place. I&rsquo;ve been using xargs -P for a while, but I wondered about doing it all in the shell. &#xA; &ldquo;conc&rdquo; &#xA; I came up with a super-simple function to do some experiments: &#xA;…

PIL/PIP/Homebrew Problems

I have PIL installed via pip. I have libjpeg installed via homebrew. I have the system python. &#xA; I was having problems with PIL&rsquo;s jpeg module. It was giving the error message: &ldquo; ImportError: The _imaging C module is not installed &rdquo;. It was installed, but it was broken. Telling python to import _imaging gave me the better message: &ldquo; Symbol not found:…

The VAX MTH$RANDOM Generator in Python

So I needed the ole&rsquo; VAX MTH$RANDOM for a puzzle. I like python. Here&rsquo;s what I came up with after reading some gsl docs : &#xA; def vax_rand ( seed ): &#xA; a = 69069 &#xA; c = 1 &#xA; m = 2 ** 32 &#xA; while True : &#xA; seed = divmod ( a * seed + c , m )[ 1 ] &#xA; yield seed &#xA; To use it (with a seed of 6), do this: v = vax_rand(6) and to get a number out of it, you could do…

Some Saw-Sharpening Python Resources

Some Saw-Sharpening Python Resources &#xA; I&rsquo;m coding more lately. This weekend I knocked off some rust using these resources on python hacking: &#xA; &#xA; &#xA; A &ldquo; Hidden features of Python &rdquo; question on Stack Overflow doesn&rsquo;t fit the site well but the answers are so much geeky fun. &#xA; &#xA; &#xA; The Hitchhiker’s Guide to Python is a work in progress, but is already…

VectorDesigner: The Resurrection

The Problem: VectorDesigner Dead &#xA; A few years ago I bought a vector drawing app called VectorDesigner and then I used it to make a bunch of stuff. Beautiful. Stuff. Then VectorDesigner and it&rsquo;s developer kinda disappeared from the Internet. Time moved on, MacOS 10.7 and 10.8 came out, and the old VectorDesigner app that I still have on my Mac stopped working. It would just fail to…

Easy JPEG Transcoding

2011-10-07 : Amundsen-Scott South Pole Station &#xA; The Independent JPEG Group is responsible for a C-based JPEG library that is used by lots of software. Their library distribution also includes the very useful binary executables &ldquo;cjpeg&rdquo; and &ldquo;djpeg&rdquo;. When combined, they can be used to transcode JPEGs. I&rsquo;ve used these programs gainfully to transcode JPEGs to 14% of…

Automating Unity

2011-09-22 : Amundsen-Scott South Pole Station &#xA; &#xA; So we upgraded from what could generously be described as ancient versions of Cisco Unity (and CallManager) to much more modern versions. Sadly my hopes for a more featured and streamlined UI on these apps were dashed. Version 8.x is nearly identical in appearance to 4.x. One change I did notice was that the Unity web interface migrated…

Disjointed & Rebound

2011-09-16 : Amundsen-Scott South Pole Station &#xA; &#xA; So I&rsquo;ve been at the South Pole for a while. In fact, it has almost been a year now. It has been a challenging winter in some ways and I&rsquo;m feeling more than a little &ldquo; toasty &rdquo;. I&rsquo;m not sure what else to say about it, so I&rsquo;m going to write about some other stuff&hellip; &#xA; I&rsquo;m switching from…

galvanist · RSS Amplifier