Christian Perrier: Triaging and uploading samba
Yipee!
...and there was a distinct feeling of deja vu. At least
the procedure itself was nowhere near as long (under 2 hours).
On Thursday, Sarah had some day-surgery to have her sternal
wires
removed. The top one was causing her some discomfort because the skin there
was the thinnest (whether that in itself was related to any of the previous incision
complications remains uncertain).
The surgical team popped in to pre-op to autograph their work (seriously,
they initialled her chest) before they started, and asked if she wanted just
the top wire removed, or all of them. We consulted the Magic Eight Ball
application on my phone, and it gave a resoundingly affirmative response, so
she got them all removed.
Despite removing them all being a bit more surgically invasive, I think this
is for the best. It means none of the other wires can cause any problems
down the track requiring yet another trip to the operating room.
They also did some scar revision on the top part of the scar, where it was a
bit stretched (from the previous complications), so incisionally speaking,
she's had almost as much incision work done as the original heart surgery.
Ironically, this made the plastic surgery (laser treatment and steroid
injections) she had late last year largely redundant.
She took the dressing off the incision this morning, and we had our first
look at it. It certainly looks a lot better than before, so fingers crossed
it won't get infected this time, and the overall long-term result will look
better.
It will be a make-or-break year for Perl. If the Perl developers cannot either bring new life to Perl 5 or turn Perl 6 into something real, this language will, by the end of the year, have moved well down the road to "legacy" status.As can be imagined, that set them off all over again. The mental image I get is a big angry bull, frothing at the mouth, and ready to stomp that damn red cape. Here's the problem, though, guys: the cape isn't what's holding you back. Trust me, I know. Once upon a time, when people spoke of scripting languages, they talked about "Perl, Python and Tcl". No Ruby, no PHP, although both existed. I happen to like Tcl a lot, and it measures much worse than Perl on all the popularity charts... worse than plenty of other languages, these days. Lately, I don't use it so much, but once upon a time I dedicated a lot of mental energy to wondering why things weren't going better. And in that community too, there were people who consistently held their fingers in their ears and yelled "LALALALA there is no problem!". In the long term, it's not an effective strategy: it makes everyone but the other True Believers think you're going off the rails, because the evidence is plain to see that things weren't quite like they used to be, that there are problems. And it doesn't really address the problem in a constructive way, either. Long term, what works is to produce good code, and get it in people's hands. The most effective way of dealing with problems of this nature includes these points:
It will be a make-or-break year for Perl. If the Perl developers cannot either bring new life to Perl 5 or turn Perl 6 into something real, this language will, by the end of the year, have moved well down the road to "legacy" status.As can be imagined, that set them off all over again. The mental image I get is a big angry bull, frothing at the mouth, and ready to stomp that damn red cape. Here's the problem, though, guys: the cape isn't what's holding you back. Trust me, I know. Once upon a time, when people spoke of scripting languages, they talked about "Perl, Python and Tcl". No Ruby, no PHP, although both existed. I happen to like Tcl a lot, and it measures much worse than Perl on all the popularity charts... worse than plenty of other languages, these days. Lately, I don't use it so much, but once upon a time I dedicated a lot of mental energy to wondering why things weren't going better. And in that community too, there were people who consistently held their fingers in their ears and yelled "LALALALA there is no problem!". In the long term, it's not an effective strategy: it makes everyone but the other True Believers think you're going off the rails, because the evidence is plain to see that things weren't quite like they used to be, that there are problems. And it doesn't really address the problem in a constructive way, either. Long term, what works is to produce good code, and get it in people's hands. The most effective way of dealing with problems of this nature includes these points:
I recently converted most of the Debian packaging for Telepathy and related
projects from bzr to git, while changing the repository contents from just
the debian/ directory to the whole source tree. Here's the recipe, using the
latest one to be converted (pymsn) as an example.
mkdir pymsn
cd pymsn
git init
rename 's/^pymsn-/pymsn_/' *.tar.gz
rename 's/\.tar\.gz$/.orig.tar.gz/' *.tar.gz
git-import-orig to import them:
cd ../pymsn
ls ../tarballs/pymsn_*.orig.tar.gz
for v in 0.2 0.2.1 0.2.2 0.3.0 0.3.1 0.3.2 0.3.3; do \
git-import-orig --no-merge --no-dch --pristine-tar \
-u $v ../tarballs/pymsn_$v.orig.tar.gz; done
master branch in favour of using one we convert
from bzr later:
git checkout upstream
git branch -D master
#!/bin/sh
# index-filter.sh
if git ls-files -s grep debian; then
:
else
git ls-files -s
sed -e "s-\t-&debian/-"
GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info &&
mv $GIT_INDEX_FILE.new $GIT_INDEX_FILE
fi
~/.bazaar/plugins/fastimport/exporters/bzr-fast-export.py \
../pymsn-unstable git fast-import
git branch -m master debian-lenny
~/.bazaar/plugins/fastimport/exporters/bzr-fast-export.py \
../pymsn-experimental git fast-import
git branch -m master debian
git branch -D tmp
git filter-branch --index-filter $(pwd)/../index-filter.sh debian-lenny
rm -r .git/refs/original
git filter-branch --index-filter $(pwd)/../index-filter.sh debian
rm -r .git/refs/original
git checkout debian
git merge upstream/0.3.3
vim debian/control # and change Vcs-Bzr to Vcs-Git
dch "Move packaging to git"
debcommit -a
git checkout debian-lenny
git merge upstream/0.3.1
vim debian/control # and change Vcs-Bzr to Vcs-Git
dch "Move packaging to git"
debcommit -a
git branch debian-patches upstream/0.3.3
but there is one in the debian-lenny branch:
git branch debian-lenny-patches upstream/0.3.1
git checkout debian-lenny
cp debian/patches/00-fix-dns-resolution.diff ..
git checkout debian-lenny-patches
patch -p1 < ../00-fix-dns-resolution.diff
git commit -a
cd /git/pkg-telepathy
GIT_DIR=pymsn.git git init --bare --shared
GIT_DIR=pymsn.git git config hooks.mailinglist ...
vim pymsn.git/description
git gc --aggressive
git remote add origin git+ssh://git.debian.org/git/pkg-telepathy/pymsn.git
git push --all
cat > pymsn.git/hooks/post-receive <<EOF
#!/bin/sh
exec /usr/local/bin/git-commit-notice
EOF
chmod +x pymsn.git/hooks/post-receive
GIT_DIR=pymsn.git git symbolic-ref HEAD refs/heads/debian
cd ../pymsn-unstable
dch $'This repository is no longer used, instead please use git:\n'\
"git://git.debian.org/git/pkg-telepathy/pymsn.git" -c changelog
debcommit -c changelog
bzr push
cd ../pymsn-experimental
dch $'This repository is no longer used, instead please use git:\n'\
"git://git.debian.org/git/pkg-telepathy/pymsn.git" -c changelog
debcommit -c changelog
bzr push
cd ../pymsn
I'm going to re-do my blog sometime soon.The host my current blog is running on is going to retire "anytime soonish"
(I happen to be responsible for that, so I will know when). So I will need
to move my blog someplace else (I want to merge it into my regular web page,
too). Right now, it's based on an ancient version of Pyblosxom with a couple
of custom hacks, and is pretty much unmaintainable.So I'm also looking for an appropriate blog software, but I'm not yet sure
about my requirements, so I don't have a clear software favorite yet. I
don't need a browser based editor, and I'm not interested in interactive
features such as comments or trackbacks.Mnemosyne is one of
my favourites, because it's a rather low-level, bare-bones approach. Its
templating is XML-based (KID) and it's Python.Ikiwiki actually calls itself a "wiki
compiler", but I know that some people use it for their blogs. It also does
valid XHTML, although its templating isn't designed for XML safety.Features that I would like to have:
I'm going to re-do my blog sometime soon.The host my current blog is running on is going to retire "anytime soonish"
(I happen to be responsible for that, so I will know when). So I will need
to move my blog someplace else (I want to merge it into my regular web page,
too). Right now, it's based on an ancient version of Pyblosxom with a couple
of custom hacks, and is pretty much unmaintainable.So I'm also looking for an appropriate blog software, but I'm not yet sure
about my requirements, so I don't have a clear software favorite yet. I
don't need a browser based editor, and I'm not interested in interactive
features such as comments or trackbacks.Mnemosyne is one of
my favourites, because it's a rather low-level, bare-bones approach. Its
templating is XML-based (KID) and it's Python.Ikiwiki actually calls itself a "wiki
compiler", but I know that some people use it for their blogs. It also does
valid XHTML, although its templating isn't designed for XML safety.Features that I would like to have:
I received a SanDisk
Sansa e260 (v2) for my birthday. It was one of those presents that
acquired for myself on behalf of someone else because it worked out easier
that way. I bought it for cheap from Woot!
I thought I'd use it to play podcasts while I'm at the gym. We've been
listening to NPR for a while now, and
there's lots of excellent programming, and it's all available in download
for as well. Since I don't spend all that much time in the car, I'm not
listening to much of it.
The first mission was to upgrade the firmware. Getting the player into MSC
(instead of MTP) mode
with the original firmware was a little
tricky, but I got there in the end. Then I had to locate the firmware in
a Linux-installable format. I think I ended up resorted to using Windows,
but I later found the raw
firmware image without needing an installer.
I'm using Rhythmbox at
the moment to download the podcasts. I thought I'd try out its MTP support,
just because it actually had it, but either Linux 2.6.26 has a problem with
MTP, or the player is particularly flaky doing it with Linux, because I just
seemed to get a pile of USB errors when connecting the device in this mode,
so I'm sticking with MSC for now.
Oh, and I had to put a .is_audio_player file in the root of the
device to make it show up in Rhythmbox. I later discovered that it worked
most optimally if I put
audio_folders=MUSIC/ folder_depth=2in the file. I'm still trying to come up with an optimal way of managing the audio I want to listen to. It seems somewhat tedious to drag and drop all of the podcasts from Rhythmbox to the device. I kind of want some sort of plug and play auto-sync method. It seems I can't use a connection-triggered rsync, because some of the podcasts seem to get downloaded with non-FAT-filesystem-friendly filenames. Rhythmbox seems to take care of this by doing some sort of automagical renaming at transfer time. That said, not everything is showing up in the music list with sane names. There's a few things that have an unknown artist I think. That may be a deficiency in the ID3 tags of the MP3s themselves though... What I really want some way of getting home, hooking up the player and just getting what's new, without expending too much effort (at the time of hooking up the player, anyway. I'm happy to expend some effort getting to that point) The next weird thing is that the device wants to talk USB 1.1. I'm not sure what is at fault here, but I can, allegedly at least, make the device reconnect at USB 2.0 by removing and reloading the ehci-hcd module after connecting it. Here we have the device initially attached:
apollock@icarus:~$ lsusb -t
Bus# 5
-Dev# 1 Vendor 0x1d6b Product 0x0002
Bus# 4
-Dev# 1 Vendor 0x1d6b Product 0x0001
Bus# 3
-Dev# 1 Vendor 0x1d6b Product 0x0001
-Dev# 9 Vendor 0x0781 Product 0x7423
Bus# 2
-Dev# 1 Vendor 0x1d6b Product 0x0001
-Dev# 6 Vendor 0x413c Product 0x8103
Bus# 1
-Dev# 1 Vendor 0x1d6b Product 0x0001
lsusb says that bus #3 is ID 1d6b:0001 Linux Foundation 1.1 root hub
Then if I do a spot of presto-changeo...
apollock@icarus:~$ sudo modprobe -r ehci-hcd
apollock@icarus:~$ sudo modprobe ehci-hcd
apollock@icarus:~$ lsusb -t
Bus# 5
-Dev# 1 Vendor 0x1d6b Product 0x0002
-Dev# 3 Vendor 0x0781 Product 0x7423
Bus# 4
-Dev# 1 Vendor 0x1d6b Product 0x0001
Bus# 3
-Dev# 1 Vendor 0x1d6b Product 0x0001
Bus# 2
-Dev# 1 Vendor 0x1d6b Product 0x0001
-Dev# 7 Vendor 0x413c Product 0x8103
Bus# 1
-Dev# 1 Vendor 0x1d6b Product 0x0001
Bam! It's moved over to bus #5, which lsusb says is 1d6b:0002
Linux Foundation 2.0 root hub
Weird.
I wonder if I should try running Rockbox on it? Seems not, it's only for
v1 players. Oh well.
deb http://packages.kirya.net/dspam-community/ experimental main deb-src http://packages.kirya.net/dspam-community/ experimental main
gpg --keyserver wwwkeys.eu.pgp.net --recv-keys FBABB737 gpg --export -a FBABB737 apt-key add -
wget -O - http://packages.kirya.net/Kirya.netDebianpackagesVerificationKey.asc apt-key add -
America OnLine (AOL) killed their blogging service - actually, all their Hometown sites - last September and I only just noticed.
AOL didn t kill it cleanly. They could have offered 301 Moved Permanently redirects to users new hosting (good - maybe no interruption to users), returning a 404 Not Found with an explanation (OK - software like RSS readers would detect the serious problem) or even simply taking the hostname offline (bad, but better than what they did). Instead, AOL 301-redirected everyone to a page on their own journal (which hasn t closed down) to sincerely apologize for any inconvenience . It wouldn t have been so much inconvenience if it had been closed down cleanly.
I was only reading one journal there (Pripensulo) which I can t find anywhere else, but I m surprised by the incompetent webmastering. AOL s webmasters run managing massive (if bland) websites, after all, and if they re smart enough to do a 301 redirect to their apology, then they re smart enough to do a useful redirect or a 404 Not Found. Why didn t they? Don t they care about their users? Are they trying to take SEO points from all their users and give them to People Connection?
(this is something I've had "in production" for many months now, I just
haven't had the time or energy to do a proper write up about what I did)
We have a cat water bowl, it looks like this:
apollock@icarus:~$ telnet teevee 4000 Trying 172.16.0.9... Connected to teevee.andrew.net.au. Escape character is '^]'. ser2net port 4000 device /dev/rfcomm0 [9600 N81] (Debian GNU/Linux) waterbowl> s Water is present waterbowl> telnet> q Connection closed. apollock@icarus:~$The Wiring code running on the Arduino board is checked in here. Next, I wanted to monitor this with Nagios. One thing I found with the Bluetooth connection was that it wasn't all that reliable. Not every connection to port 4000 resulted in a connection with the water sensor. I elected to write some standalone code that submitted results to Nagios by way of a passive check, rather than having Nagios try to actively monitor it. Again, trying to conserve energy, I decided to only check the sensor once every 8 hours. So I wrote a Python daemon, which tried to be as robust as possible. If at first it doesn't make a connection on its 8 hourly schedule, it keeps trying until it does. Nagios itself has some freshness detection for this monitor, so if no passive result is submitted within 8 hours and one minute, Nagios alerts that something is possibly wrong with the sensor itself. (The original intent was to deal with the situation where the battery went flat) This is the Nagios service definition I've got. Some of it may be unnecessary or redundant:
define service
host_name teevee
service_description Cat water bowl
check_command check_stale!2!"Check water bowl monitor is on and reachable"
normal_check_interval 480
notification_interval 240
active_checks_enabled 0
check_freshness 1
freshness_threshold 28860
max_check_attempts 1
check_period 24x7
use generic-service
stalking_options o,w,c
contact_groups everyone
The code for the Python daemon is checked in here.
So everything was going swimmingly, apart from I couldn't get even 24 hours
of monitoring on my conservative 3 times a day schedule, and the Bluetooth
modem configured for all of its power saving options, and the water sensor
itself only being powered on when it was performing a check. There wasn't
much more I could do to try and reduce power consumption, at least with my
limited electronics knowledge. Perhaps using Zigbee instead of Bluetooth
would have helped, but I still think I'd have been going through 9 volt
batteries more quickly than I'd have liked.
I also had a brief foray into solar powering the board. I thought maybe the
lighting in the house would be sufficient to power the board. Of course this
didn't work out. I'd also have needed to make the code running on the board
more self-sufficient, and have it just provide a water status indication
whenever it had enough power to do so, instead of being a fairly dumb device
like it currently is. This all felt a whole level more complicated, and out
of my league, and I wasn't interested in attempting this sort of
remote-sensing exercise at this time.
The Arduino board can also be powered by USB, so as I already had some long
USB type A to type B cables (that had funky lights in them to boot), I
decided to just get a wall wart that had a USB type A receptacle, and
powered the Arduino board that way. So much for being completely "wireless".
(I could have also gotten a general purpose DC power supply that was capable
of spitting out 9 volts, but I doubted I'd get one with a sufficiently long
cable, which is why I went for the USB-powered option, as I already had a
cable long enough)
Speaking of wires, the most challenging part was the probes for the water
sensor. As they were going to be permanently in the cats' drinking water, I
didn't want to contaminate the water with them. I figured plain untinned
copper wire would be okay, since water pipes are copper. Finding untinned,
unstranded copper wire was a real challenge. I started out using some FM
antenna cable, but that was stranded, and the shielding was a nightmare to
strip. It was also reasonably difficult to make go where I wanted it.
What I really wanted was something more solid, that would flex and stay
where I put it. I cannibalised a spare IEC power cable, but it was also
stranded copper wire. I finally managed to obtain some solid-core CAT-5
cable from a hardware store, and this has worked exactly as I wanted.
I haven't done any further work on the setup since getting the CAT-5 cable
for the probe. Further improvements that I'd like to do at some point:
I just ran across Jordan Sissel's sysadvent project, where he posted one article about systems administration each day from the 1st of December to the 25th. Jordan has been a great communicator when we've exchanged mail (he's the author of xdotool, which i maintain for debian). Unsurprisingly, his posts in sysadvent are also excellent. He has a broad knowledge of what tools are available, clever insights in how to connect them together, an engaging and clear writing style, and sharp sense of what really should matter to a systems administrator. Definitely worth reading!
For a while I have been pondering over a problem that arises when your functionally written program has some state with cross references for example a list of users, each of which uses a number of computers, and a list of computers, each having an owner.
Implicit referencing
For doing queries on such data, it would be convenient if every reference is just the referenced object itself. Although we would visualize this as a graph, semantically, it is more like an infinite tree. This is possible in Haskell, due to laziness, and if you create the data structure cleverly, it even uses constant memory, no matter how deep you enter this infinite tree (a recent post of mine talks about this). A possible data definition would be:
data User = UserExplicit referencing But such a representation is very unsuitable for updates (at least I can t think if a nice way of updating such a graph without breaking the internal cross-references) and serialization, which is a must for a HAppS based application. So what one would probably start with is this data structure:
userName :: String,
uses :: [Computer]
data Computer = Computer
computerName :: String,
owner :: User -- references the Users
data State = State [User] [Computer]
testState = let user = User "Conrad" [computer]
computer = Computer "Z3" user
in State [user] [computer]
data User = UserI think the semantics of this are clear. Note that the referencing is currently not type-safe, but this can be provided by phantom types. Maybe I ll write more about that later. Now imaging you want to display the information about the first computer with your web application. You extract the information with let State _ cs = testState in head cs and pass that to your templating engine. But what if your template wants to display the name of the owner? It only has access to his userId. You would either need to know what information the template will ever need, extract that from the state beforehand and pass it along, or give the template access to the whole state. In that case, though, there has to be lookup-logic in your output code, which is also not nice. Woudln t it be nice if you could, in your application logic, work with the explicit references, which are easy to modify and store, but somehow turn that into the implicit referencing? Duplicated representation One way would be to have two unrelated sets of data structures, ExplicitState, ExplicitUser, ExplicitComputer, which use explicit identifiers to reference each other, and ImplicitState,... which are defined as the first representation of our state. It is then mostly trivial to write a function that converts ExplicitState to ImplicitState. The big disadvantage of this is that you have to maintain these two different hierarchies. It also means that every function on the state has to be defined twice, which often almost identical code. Clearly, this is not desirable. Annotated representation It would be more elegant if the state is stored in one data type that, controlled by a type parameter, comes in the one or the other representation. To do that, we need two types: One that contains a value, and one that contains just a reference:
userId :: Int,
userName :: String,
uses :: [Int] -- references the Computers
data Computer = Computer
computerId :: Int,
computerName :: String,
owner :: Int -- references the Users
data State = State [User] [Computer]
testState = State
[User 0 "Conrad" [1]]
[Computer 1 "Z3" 0]
newtype Id v = Id v deriving (Show, Typeable, Data)Then we need to adjust our data definitions, to make use of these. (I ll leave out the names, to keep the code smaller)
newtype Ref v = Ref Int deriving (Show, Typeable, Data)
data User ref = UserHere we introduce a type parameter ref , which will later be either Id or Ref. Note that now a reference also states the object it is a reference for, which greatly increases type safety. Functions on these data types that don t work with the references will be polymorphic in the ref type parameter, so only need to be written once. A User Id is a complete user with all related data, while User Ref is a user with only references. And a Ref (User Ref) is reference to a user, which contains references... Not so kind kinds Did you notice the lack of a deriving clause? Our data structures have the relatively peculiar kind ((* -> *) -> *), which makes it hard for the compiler to derive instances for things like Show. But we already know that we will only use Id or Ref for the type variable, so we can use ghc s StandaloneDeriving language extension and have these instances created:
userId :: Int,
uses :: [ref (Computer ref)]
data Computer ref = Computer
computerId :: Int,
owner :: ref (User ref)
data State ref = State [User ref] [Computer ref]
deriving instance Show (User Id)Toggling a type parameter The next step is to write the conversion function. It will have type
deriving instance Show (User Ref)
deriving instance Show (Computer Id)
deriving instance Show (Computer Ref)
deriving instance Show (State Id)
deriving instance Show (State Ref)
unrefState :: State Ref -> State IdFor that, and for later, we need lookup functions:
unrefUserRef :: State Id -> Ref (User Ref) -> Id (User Id)These expect a State (with implicit referencing) and a reference, and look up this reference. The function unrefState then looks like this:
unrefUserRef (State l _) (Ref i) = Id $ fromJust $
find (\u@(User i' _) -> i == i') l
unrefComputerRef :: State Id -> Ref (Computer Ref) -> Id (Computer Id)
unrefComputerRef (State _ l) (Ref i) = Id $ fromJust $
find (\u@(Computer i' _) -> i == i') l
unrefState :: State Ref -> State IdNote how we tie the knot in the let expression. This is the trick that ensures constant memory consumption, because every reference points back to the same place in memory. Satisfied already? So what do we have? We have no duplication of data types, we can write general functions, and we can resolve the explicit referencing. We can also easily write functions like unrefUser :: State Ref -> User Ref -> User Id, which transform just a part of the state. But writing unrefState is very tedious when the State becomes more complex. Each of the other unrefSomething functions are very similar, but need to be written anyways. This is unsatisfactory. What we want, is a generic function, something like
unrefState (State us cs) =
let unrefState = State (map (unrefUser unrefState) us)
(map (unrefComp unrefState) cs)
in unrefState
where unrefUser :: State Id -> User Ref -> User Id
unrefUser s (User i refs) = User i (map (unrefComputerRef s) refs)
unrefComp :: State Id -> Computer Ref -> Computer Id
unrefComp s (Computer i ref) = Computer i (unrefUserRef s ref)
gunref :: State Ref -> a Ref -> a Idwhich, given a state with explicit references, replaces all explicit references in the first argument (which could be State Ref or User Ref or anything like that) with implicit ones. This function can not exist, because we would not know anything about a and b. But maybe we can do this:
gunref :: (Data (a Id), Data (a Ref)) => State Ref -> a Ref -> a IdTypeable and Data Before being able to do so, we need to derive Data for our types. We can start with
deriving instance Data (User Id)but that will complain about missing Typeable instances. Unfortunately, ghc s deriver for Typeable (even the stand-alone-one), does not handle our peculiar kind, so we need to do it by hand. With some help from quicksilver on #haskell, I got it to work:
deriving instance Data (User Ref)
deriving instance Data (Computer Id)
deriving instance Data (Computer Ref)
deriving instance Data (State Id)
deriving instance Data (State Ref
instance Typeable1 ref => Typeable (User ref) whereeverywhere is not enough Turning to the documentation of Data.Generics, I notice with some disappointment that there is no function that is able to change a type they all seem to replace a value by another value of the same type. But the functions gfoldl and gunfold sounded like they could be used for this. Warning: What comes now is a very non-haskellish hack that subverts the type system, just to get the job done. Please read it with a healthy portion of distrust. If you know of a cleaner way of doing that, please tell me! Wrapped Data I want to do some heavy type hackery, so I need to disable haskell s type system. There is Data.Dynamic, but not even that is enough, as we need to carry a type s Data instance around as well. So let s wrap that up:
typeOf _ = mkTyConApp (mkTyCon "User") [typeOf1 (undefined :: ref ())]
instance Typeable1 ref => Typeable (Computer ref) where
typeOf _ = mkTyConApp (mkTyCon "Computer") [typeOf1 (undefined :: ref ())]
instance Typeable1 ref => Typeable (State ref) where
typeOf _ = mkTyConApp (mkTyCon "State") [typeOf1 (undefined :: ref ())]
data AData where AData :: Data a => a -> ADataThere is also a function that converts an AData back to a normal type, if possible. If it s not possible, then there is a bug in our code, so we give an informative error message. AData transformers Similar to everywhere, we want to have transformers that combinable. They need to have the change to convert an arbitrary value, but also signal that they could not convert something (and this something has to be recursed into). I came up with this:
instance Show AData where show (AData a) = "<" ++ show (typeOf a) ++ ">"
fromADataE :: forall b. Data b => AData -> b
fromADataE (AData d) = case cast d of
Just v -> v
Nothing -> error $ "Type error, trying to convert " ++
show (typeOf d) ++ " to " ++
show (typeOf (undefined :: b)) ++ "."
type ADataT = AData -> Maybe ADataADataT is the type for such a transformer. doNothing will not transform anything, and extADT can be used to add any function to the list of tried transformers, in the spirit of extT. The ugly part To apply such a transformer, I want to use this function, which I ll describe in the code comments:
extADT :: forall a b. (Data a, Data b) => ADataT -> (a -> b) -> ADataT
extADT at t a@(AData v) = case cast v of
Just x -> Just (AData (t x))
Nothing -> at a
doNothing :: ADataT
doNothing = const Nothing
everywhereADT :: forall a b. (Data a, Data b) => ADataT -> a -> bWhat a beast! But surprisingly, it works. Here are some examples. Note that I always have to specify the requested output type:
-- first check if we can transform this value already
everywhereADT f v = case f (AData v) of
-- if so, coerce it to the users requested type, which hopefully goes well
Just r -> fromADataE r
-- if not, we need to recurse into the data structure
Nothing -> recursed
-- for that, we first need to figure out the arguments to the
-- constructor. We store them in the untyped list
where args :: [AData]
(Const args) = gfoldl k z v
-- gfoldl lets us have a look at each argument. We wrap it in AData
-- and append it to the list
k (Const args) arg = Const (AData arg : args)
z start = Const []
-- We need the data constructor of the input data type. If the user did not want
-- it to be transformed, it will be the same
c = toConstr v
-- To give better error messages, we make sure that the outmost type constructor
-- of the requested type actually has the data constructor we were given. Otherwise
-- gunfold will complain in a non-helpful way
input_type = dataTypeRep (constrType c)
output_type = dataTypeRep (dataTypeOf (undefined :: b))
recursed = if input_type /= output_type
then error $ "Can not convert <" ++ show input_type ++ ">"++
" to <" ++ show output_type ++ ">."
-- the types match, so we assemble the output type, using gunfold
else snd (gunfold k' z' c)
k' :: forall b r . Data b => ([AData], b -> r) -> ([AData],r)
-- we start by reversing the input list
z' start = (reverse args,start)
-- then we call us recursively on the argument and feed the result
-- to the output constructor
k' ((AData a) : args, append) = (args, append (everywhereADT f a))
-- Used for folding (we don t need to retain the original constructor)
data Const a b = Const a
bool2Int :: Bool -> IntI hope this code does not inflict too much pain on any Haskell-loving reader. I know I violated the language, but I didn t know how to do it better (at least not without using Template Haskell). I also know that this is not very good performance wide: Every single value in the input will be deconstructed, type-compared several times and re-assembled. If that is an issue, then this function should only be used for prototyping. Almost done To apply this to our state, we only need to glue it to our lookup functions from above:
bool2Int False = 0
bool2Int True = 1
*Main> everywhereADT (doNothing extADT bool2Int) True :: Int
1
*Main> everywhereADT (doNothing extADT bool2Int) True :: ()
*** Exception: Type error, trying to convert Int to ().
*Main> everywhereADT (doNothing extADT bool2Int) (True,False) :: (Int,Int)
(1,0)
*Main> everywhereADT (doNothing extADT bool2Int) ([True,False],True,()) :: ([Int],Int,())
([1,0],1,())
*Main> everywhereADT (doNothing extADT bool2Int) ([True,False],True,()) :: [()]
*** Exception: Can not convert to .
*Main> everywhereADT (doNothing extADT bool2Int) [True] :: [Bool]
[*** Exception: Type error, trying to convert Int to Bool.
gunref :: (Data (a Id), Data (a Ref)) => State Ref -> a Ref -> a IdNow we have a generic unreferencer. I set the type a bit more specific than necessary, to make it safe to use (under the assumption that the list of lookup functions is complete and will not leave any Ref in the output).
gunref s w = let unrefState = gunref' unrefState s
in gunref' unrefState w
gunref' :: (Data (a Id), Data (a Ref)) => State Id -> a Ref -> a Id
gunref' unrefState = everywhereADT unref'
where unref' = doNothing extADT
unrefUserRef unrefState extADT
unrefComputerRef unrefState
*Main> testStateOh, and by the way, if you want to test this code, you ll need at least:
State [User userId = 0, uses = [Ref 1] ] [Computer computerId = 1, owner = Ref 0 ]
*Main> gunref testState testState
State [User userId = 0, uses = [Id (Computer computerId = 1, owner = Id (User userId = 0,
uses = [Id (Computer computerId = 1, owner = Id (User userId = 0, uses = ..
-# LANGUAGE DeriveDataTypeable, FlexibleInstances, GADTs,
FlexibleContexts, StandaloneDeriving, ScopedTypeVariables #-
Recently the Debian Administration website has been besieged by spammers submitting bogus comments.
I also run a couple of blogs which are constantly having random gibberish submitted to them - although it is less of a problem there because I approve them manually due to the offline nature of my blog, and the blog compiler I use.
Regardless I figured it was time to do something about it, in part because Chris Searle suggested that I should be able to query arbitrary text for spammyness due to my experience with fighting email spam. (As it turns out that is not so useful experience. Comments and emails are not the same. The same header-trickery you see in bogus email, false EHLOs, etc, are not useful concepts to carry accross.)
Anyway we were saying, I was going to do something? So I did. My solution? An XML-RPC server which you submit your comments to. This will return either:
| OK | The comment is clean. |
| SPAM:[reason] | The comment is spam, and the optional reason explains further |
A recent post by Adrian von
Bidder got me to reread the "Printing dialogs and GNOME" thread that
Linus started on the GNOME mailinglists a few years ago. I don't know
how or why I missed it back then, but I did see this little gem in a
post by Mike
Shaver:
You and I are not interesting GNOME users, in part because we already _are_ GNOME users. The interesting GNOME users are the ones that haven't tried it yet, and we need to figure out why they haven't. There are lots of things that I want in GNOME, but if they aren't going to bring a hundred thousand of my closest friends along as well, I would hope that nobody goes out of their way to do them.That is precisely what is wrong with the GNOME people. While encouraging new users to try and use GNOME certainly is a good and worthy goal, it is this mentality of 'only the new users matter, the existing ones can go f*ck themselves' which will ultimately drive away users. Of course this post is a few years old, and I'm not involved in GNOME development in any way, so this mentality might have gone away now; but I don't hold my breath.
So the failings of the GR result in just what everyone didn't need - a restarted discussion about the firmware issue without first releasing Lenny. Come on people, leave it alone and get Lenny done. Anthony, Thomas and Theodore (also in his blog) all seem to be missing the point(s):
1Password is a very powerful application for OSX to keep safe your passwords and identities. It works as a standalone application and as a series of plugins for several Internet browsers. It is capable of, among other things, autofill registration forms and save you a lot of time filling in the same personal information again and again. To autofill a login form, just click the 1P browser menu bar icon, choose a previously recorded identity and voila, 1Password logins in automagically with no further interaction.
All the harvested information is stored in a different keychain unlocked by a master key placed in the login keychain (See Keychain access.app for more information).
Macheist, in collaboration with Agile Web Solutions, is offering free licenses as a Christmas present here. You only have to create and account and click in the links below the tree to get your free license.
For various reasons (which in the end boil down to lack of manpower), we are quite late in the process of packaging GNOME 2.24. (This is almost finished now, I ll keep you informed.) Which is why I may sound coming a bit late on noticing this one, but I was really speechless.
The problem: session management has flaws
Currently, a session manager uses XSMP (the X Session Management Protocol) to talk to applications. What it means is that for applications supporting this protocol, it is able to do more than simply starting and killing them: it will also remember their state, and offer them a way to shut down gracefully. However, XSMP is really a shitty protocol I won t explain why here, you will find tons of better explanations on the intarweb.
The gnome-session developers, being quite aware of this issue, did what anyone interested enough would have done: they designed a new protocol, based on D-Bus, and implemented it. The new protocol is not considered stable yet, but it is simple, efficient and above all, reliable that s a giant leap forward. For this reason, I was very excited to see what gnome-session 2.24 would look like, since it brings major cleanups in the code.
The solution: remove session management!
When I first started it, it did not restore my saved session. I simply supposed that the format of the saved session had changed, and that writing a conversion tool would be in order. Wrong. Let s bring the session preferences:

static void
on_save_session_clicked (GtkWidget *widget,
GsmPropertiesDialog *dialog)
g_debug ("Session saving is not implemented yet!");
As for the check box on top of it, it sets a GConf value that is never read anywhere.
If you know the long term plans for GNOME, it makes sense: when gnome-shell replaces the panel and the window manager, it will also be responsible for starting the visible applications, while gnome-session will deal with what s happening behind the scenes. But gnome-shell is still far from ready, and you need something in the meantime for the basic requirements of a session manager!
Backwards compawhat?
The surprises don t stop here. I also noticed that logout was much faster instantaneous instead of the usual 2-3 seconds. The reason why logging out is this long currently is not because it takes long to kill applications; it s because the session manager kindly requests applications supporting XSMP to shut down before killing them. If a document isn t saved, an application will be able to prevent the logout process. Guess what? Now gnome-session completely ignores XSMP applications. Since it doesn t need them to register for saving the session, it also saves the time to ask them to close cleanly.
The result is that you will see a lot of such dialogs:

Next.