Buy an overnight bus ticket at Arcade busstation in Chiang Mai to Nong Khai (border) Bus drops you at the Nong Khai busstation in the morning. (Some busdrivers are willing to drop you at the borderstation) if not: take Motosai taxi to the border. Cross the border into Laos. Take a minivan to Vientiane Consulate. Arrive there around 9-11 am. Apply for visa. Go back next day afternoon and pick up visa. Then go back the same way. Cheapest and easiest solution.
The counter is BEFORE the security bit on the second floor in the international departures building. And yes you can buy it there anytime. Bring money and pictures.