photo
Jordan Sissel
geek. sysadmin. blogger.

Mon, 07 Jan 2008

Oniguruma - named capture example

For whatever reason, I decided to play with oniguruma tonight (a newish regular expression library). I'm considering an effort to port some of grok's functionality to C or C++ for speed reasons. Doing it in C++ would require me to re-learn C++.

The docs are pretty complete, but not very helpful with respect to examples. I wasn't able to find very many useful examples on google, but the API docs are quite good. What wasn't answered by the docs was answered by reading header files. Excellent.

The result of this adventure is this:

# regex: ^(?<test>.*?)( (?<word2>.*))?$
# input: "hello there"

% gcc -I/usr/local/include -L/usr/local/lib -lonig oniguruma_named_captures.c
% ./a.out "hello there"
word2 = there
test = hello
% ./a.out "foobarbazfizz"
word2 = 
test = foobarbazfizz

Download the code

Comments: 0 (view comments)
Tags: , , , ,
Permalink: /geekery/oniguruma-named-capture-example
posted at: 04:41

Sun, 06 Jan 2008

Soekris net4501 GPIO on FreeBSD 7.0

I finally picked up some small parts (leds, breadboard, leads, multimeter) from Fry's to start work on my universal remote project. Yes, I know you can buy universal remotes. I want to learn more electronics, so why not use this as a starter project?

Since my Soekris box is now free of it's router duties, I can use it for this project. To do this, I'll need two pieces: an infrared receiver, and an infrared emitter. I bought an infrared emitter led today, and I just need to buy a receiver online (they're like $2).

Before getting there, I needed to learn how to drive the GPIO ports on the net4501.

It was pretty simple to do, nd after hooking up a few wires I had an LED that blinked after a few hours of reading and hacking. The code itself was trivial to write, I just had to learn how to talk to the GPIO ports.

After writing the blinking code, I decided the next step was clearly to add fading to the LED. This is commonly done with PWM (pulse-width modulation). Apple made this technique famous with its "breathing" LED lights on the monitors and laptops when the devices were in sleep mode.

At any rate, I have successfully written code that makes both the error led and the PIO5 (GPIO 0) pin "breathe".

Download glow.c

Comments: 0 (view comments)
Tags: , , , ,
Permalink: /geekery/soekris-gpio
posted at: 06:54

Fri, 03 Aug 2007

Overriding shared library functions

Long story short...

File: 'connect.over' contains

#include <netinet/in.h>

override(`connect', `
  {
    // code to inject before the connect() call is actually made
  }
')
Output is 'connect.so' which overrides libc's connect function.
% LD_PRELOAD=./connect.so nc google.com 80
stream connect: fd=3 host=64.233.187.99:80
% LD_PRELOAD=./connect.so nc -u 129.21.60.9 53 
dgram connect: fd=3 host=129.21.60.9:53
% LD_PRELOAD=./connect.so ssh scorn           
stream connect: fd=3 host=129.21.60.26:22
stream connect: fd=4 host=109.112.47.115:12148
scorn(~) %
The output by nc was due to my function above outputting this.

The strange ssh connection on fd=4 above is seemingly due to ssh calling connect() on a tty? fstat says:

jls      ssh         3221    4 /dev        122 crw--w----   ttypd rw
inode 122 on /dev is /dev/ttypd.

Comments: 2 (view comments)
Tags: , , ,
Permalink: /geekery/overriding-shared-library-functions
posted at: 22:16

Wed, 27 Jun 2007

New keynav release available

This release of keynav adds necessary support for configuration files and the benefits obtained from dynamic configuration.

View the project page and/or download keynav-20070629.tar.gz

Update: 20070627 had problems with $HOME so I released a new version (0629).

Comments: 0 (view comments)
Tags: , , , ,
Permalink: /geekery/keynav-20070627-released
posted at: 04:08

Mon, 18 Jun 2007

xdo - do (keyboard or mouse) things in X

Yesterday, I talked about macros. I spent some time coding today and I now have a tool that will let you execute raw keyboard and mouse input into X using the XTEST extension.

The primary example I used was focusing firefox's URL bar without the mouse. The sequence was this: Switch to Desktop 2 (I press Alt+2), focus firefox's URL bar (using control+l) and clear it.

The result is a simple tool I'm tentatively calling 'xdo'. You can download the source here. Compile instructions are at the top of the file.

The top of xdo.c details the implemented commands, so let's cut to an example:

% echo 'key alt+2; sleep 1; key ctrl+l; key BackSpace' | ./xdo
It does exactly what you think. The 'sleep' command has values in milliseconds, and is only necessary to slow down so that events can propgate fast enough (window focus changes, etc).

Another reasonable example would be to say "firefox, open a new tab and load the URL in my clipboard":

# My clipboard contains a valid url, say, "http://www.google.com/"
(echo "key alt+2; sleep 1; key ctrl+l; key BackSpace;"
 echo "move 55 55; sleep 1; click 2; key Return") | ./xdo
Seems complex, but look at what's really happening: Go to desktop 2, focus urlbar, hit backspace (clearing it), move the mouse cursor to 55,55 (a point inside the urlbar for me), hit middle mouse button to paste.

Change "ctrl+l" to ctrl+k (unix firefox) to focus the "Search" box instead, and change the 'move' command to cursor over the search box to paste instead, and suddenly you can bind a simple keystroke to search for whatever is in your X clipboard. Useful.

One of the neater features is that you can 'type' text:

% echo 'type echo hello there; key Return' | ./xdo
echo hello there
% echo hello there
hello there

Comments: 5 (view comments)
Tags: , , , , , ,
Permalink: /geekery/xdo
posted at: 02:18

Thu, 17 Aug 2006

USB Mouse support in newmoused, working.

I've got my usb mouse working with the new moused. Most of the code in the module is ripped from usbhidctl(1). Now that I *actually* know how things work, I found that the read() wasn't actually one with side effects. Good.

You'll need the new moused framework for this module.

Basic instructions:

  1. Download my moused framework (newpsm project on this site)
  2. Recompile your kernel without "device ums"
  3. Build moused, build the usbmouse module.
  4. Run moused: ./moused -m usbmouse -d /dev/uhid0
If it doesn't work, let me know.

moused-usbmouse.tar.gz

Future plans:

  • Rewrite ugly bits
  • Port ums(4) hacks for broken mice
  • Test with more mice
  • Write uhid joypad support

Comments: 1 (view comments)
Tags: , , , ,
Permalink: /geekery/usb-support-in-newmoused-part-2
posted at: 01:34

Sun, 13 Aug 2006

USB Mouse support in-progress for newmoused/newpsm

I started working on usb (usbhid) mouse support for my newpsm/newmoused project. So far so good, I can probe /dev/uhidX devices and figure out if it's a mouse or not. Thankfully, usb hid is very easy. Unfortunately, FreeBSD (NetBSD's) implementation is somewhat crazy with the voodoo.

To see what I mean, look at: src/usr.sbin/usbhidct/usbhid.c.

Look near line 230 (the only read() call in the file). Notice the read() call, but 'dbuf' is NEVER used meaningfully. More specifically, the read is mostly ignored and a loop is done over the 'hids' list. Looks like read()s on usbhid devices pushes data to special places in memory which can be found by using hid_start_parse(). A read() shouldn't be doing this. This is the job for an ioctl() or something. read(), to me, says "give me data so I can use it" - not "update some magic places in memory, thanks"

Eek.

Comments: 1 (view comments)
Tags: , , , ,
Permalink: /geekery/usb-support-in-newmoused
posted at: 23:52

Sat, 25 Mar 2006

pam_captcha 1.2 updated

This update fixes a few potential bugs and cleans up some other issues. I removed the 'cowsay' requirement and made the math and dda captchas compile-time options.

Check out the project page for information on pam_captcha and downloading it.
pam_captcha

Comments: 0 (view comments)
Tags: , ,
Permalink: /geekery/pam_captcha-1.2
posted at: 14:29

Search this site

Navigation

Metadata

Home About Resume My Code (SVN Web)

Articles

ARP Security Dynamic DNS with DHCP OpenLDAP+Kerberos+SASL PPP over SSH SSH Security: /bin/false Week of Unix Tools Work Efficiency

Projects

fex firefox tabsearch firefox urledit grok keynav liboverride newpsm (FreeBSD) nis2ldap pam_captcha poor man's backup Solaris audio utility xboxproxy xdotool xmlpresenter xpathtool misc scripts

Presentations

Yahoo! Hack Day '06 Unix Essentials Vi/Vim Essentials

Tag Cloud

Calendar

< January 2008 >
SuMoTuWeThFrSa
   1 2 3 4 5
6 7 8 9101112
13141516171819
20212223242526
2728293031  

Friends

BarCamp Kent Brewster Tantek Çelik John Resig Wesley Shields Tyler Shields

Technorati