Fixing missing dropdown button in Chrome date input

If you’re running the current version of Chrome (25.0.1364.97 as of this writing) you might find that the dropdown button is not showing properly on date input fields.  What’s actually happening is that the dropdown is getting rendered below the date input, which can make it invisible if your control isn’t big enough.

Here’s the CSS workaround I use to correct this:

input[type=date]::-webkit-calendar-picker-indicator {
 display: inline-block;
}

input[type=date] {
 min-height: 24px;
 vertical-align: top;
 white-space: nowrap;
}

 

Rendering HTML as PDF in Python

Weasyprint is the best python tool I’ve found to convert HTML to PDF.  Well-maintained, frequent releases, great documentation, with a solid rendering engine.  But for some reason they’re really hard to find when doing a google search for “python html pdf converter”.  So here’s my best effort at giving them a little googlejuice: use Weasyprint!

Ironically, the top hit for the search “python html pdf converter”, xhtml2pdf, is a real mess. Poorly maintained, unclear ownership, sparsely documented.

There’s no reason to use anything except Weasyprint to convert HTML documents to PDF from Python!

LDAP group membership not updating?

If you are new to LDAP, and you are compelled to set up an LDAP server for your organization, then you may find that sometimes you will make changes on the server that do not appear when you query from your client.

For instance, maybe you’ve defined a set of POSIX groups and have begun adding members to those groups with the memberUid attribute.  And then when you go to one of your LDAP clients and run ‘groups’ or ‘id’ or ‘getent group’ you don’t see the group membership you just set up.

Check if you’re running nscd.

ps -ef | grep nscd

If you are, restart it.

sudo /etc/init.d/nscd restart

Much better, right?

Producer/Consumer pattern with ZeroMQ

If you’re using ZeroMQ to distribute jobs across a bunch of worker processes, keep in mind that the examples given here…

…don’t include any flow control.  Therefore, if your producer is producing messages much faster than your consumers can consume them, the messages will buffer.  And buffer.  To the point that you will either run out of memory, or your workers will start to page out and their performance will degrade badly.

The good news is, there’s an easy fix for this.  Use ZMQ’s “High Water Mark” feature to implement blocking on PUSH- and PULL-type sockets.  In pyzmq, use the method:

socket.setsockopt(zmq.HWM, LIMIT)

On the sockets for both the producer and consumers.  Where LIMIT is the maximum number of outstanding messages.  I’ve set PRODUCER_LIMIT to be n*CONSUMER_LIMIT where n is the number of consumers, seems to work pretty well.

Updated RTree Implementation

I’ve updated my Java R-Tree implementation on github.  These changes fix a couple of bugs:

  1. Ensure that the bounding boxes are tightened properly when nodes split.
  2. Correctly calculate new dimensions in tighten()
  3. Ensure that a non-leaf root node always has at least two elements.
  4. Added implementation of QuadraticPickSeeds, QuadraticPickNext.

Also updated the test suite.  There are no known bugs in the current implementation; please get in touch if you find any problems.

Simple Pulse Animation with jQuery

The simplest way that I could think of to implement a “pulse” effect in jQuery. I know there are plugins that will do this. Not sure that any of them will do it in 12 lines of code.

1 2 3 4 5 6 7 8 9 10 11 12 13
function pulse(elem, duration, easing, props_to, props_from, until) {
elem.animate(
props_to,
duration,
easing,
function() {
if ( until() == false )
{
pulse(elem, duration, easing, props_from, props_to, until);
}
}
);
}

I use it to animate an HTML5 drag-and-drop target, wired up to the dragenter event like this:
1 2 3 4 5 6 7 8 9 10 11 12
function drop_target_enter(e) {
var $dt = $(context.target_id)
$dt.addClass('dt-entered');
pulse($dt,
500,
'linear',
{opacity: 0.25},
{opacity: 1},
function() {
return $dt.hasClass('dt-entered') == false;
});
}
view raw drag-enter.js This Gist brought to you by GitHub.

Update: demo at  http://newbrightidea.com/demos/pulsar

Setting compiler options with SBT

There’s a lot of misinformation out there re. how to set javac and scalac compiler options in sbt. You might see stuff about defining a custom Build object in a .scala file. Or a custom Project object. It’s all nonsense. I guess it applies to previous versions of sbt. In sbt 0.11.2, you set javac and scalac compiler options as shown on the sbt examples page here:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
name := "TCP Server Build Configuration"
 
version := "0.1.0"
 
scalaVersion := "2.9.1"
 
javacOptions ++= Seq("-Xlint:unchecked")
 
scalacOptions ++= Seq("-unchecked", "-deprecation")
 
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
 
libraryDependencies += "com.typesafe.akka" % "akka-actor" % "2.0"
 
libraryDependencies += "com.mongodb.casbah" % "casbah_2.9.0-1" % "2.1.5.0"
view raw gistfile1.txt This Gist brought to you by GitHub.

Trivial Non-Blocking Echo Server (Scala+Akka)

Akka is a framework for asynchronous messaging and IO in Scala. A colleague of mine gave it a good recommendation so I thought I’d check it out. It looks very promising although its low-level IO API is not as intuitive as I’d hoped. But, it was very easy to build a simple echo server, the “Hello, World!” of network programming.

Of course, it’s pretty easy to build a blocking socket server in pretty much any language. What I love about Scala+Akka is how easy it is to hide the fact that all of this IO is non-blocking.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
import akka.actor._
import java.net.InetSocketAddress
 
class TCPServer(port: Int) extends Actor {
 
override def preStart {
IOManager(context.system) listen new InetSocketAddress(port)
}
 
def receive = {
case IO.NewClient(server) =>
server.accept()
case IO.Read(rHandle, bytes) =>
rHandle.asSocket write bytes.compact
}
}
 
object TCPServer extends App
{
val port = Option(System.getenv("PORT")) map (_.toInt) getOrElse 8080
ActorSystem().actorOf(Props(new TCPServer(port)))
}

To run:

scala -cp .:/home/rweeks/projects/akka-2.0/lib/akka/akka-actor-2.0.jar TCPServer

To test:

rweeks@foxbat:~/projects/scala-test$ telnet localhost 8080
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
You go first.
You go first.
No, You go first!
No, You go first!
Bye
Bye
^]
telnet> close
Connection closed.

libmicrohttpd mingw gotcha

Let’s say you want to build a nice tiny cross-platform web server using libmicrohttpd and mingw.  So for static content you’ll probably convert the URI to a path (safely! watch out for nasty clients playing tricks with “../”) and call open(3) on the path, and call MHD_create_response_from_fd with the file descriptor.

Sounds good, except on Windows you’ll see some very crazy errors whereby you actually read past the end of the file.  This is because Windows may decide to open the file as a text document, which will convert all your newlines to newlines + carriage returns.

The fix is to add the “O_BINARY” option to the open(3) call.  So,

1 2 3 4
#ifndef _WIN32
#define O_BINARY 0
#endif
int fd = open(path, O_RDONLY | O_BINARY);
view raw gistfile1.c This Gist brought to you by GitHub.