January 2018

S M T W T F S
  123456
78910111213
14151617181920
21222324252627
28293031   

Style Credit

Expand Cut Tags

No cut tags
Tuesday, November 2nd, 2010 02:25 pm
Today's hack is up. It's to the flashlight app again; now the UI stays in portrait orientation no matter how you rotate the phone. This prevents the pause/resume/create cycle that was killing my Activity and causing the light to go out. Most of yesterday's code is no longer needed and has been taken out again, but that's a good thing, right? :-)

Sideload the app (if you care - HTC Sense has such a thing built-in) from here.

Anyway, the way you do this is by adding the attribute android:screenOrientation="portrait" to the activity element in your manifest. This tip came from this StackOverflow post: I tried the more complicated "add a configChanges attribute and override onConfigurationChanged" approach described there, but that resulted in the LED wedging in whatever state it was in when you rotated the phone and not accepting any further changes. God knows what was going on there.

By the way, does anyone use git add -p much? I tried the "edit this hunk" feature a couple of times, but it told me that it my patch wouldn't apply cleanly, and then rejected the whole thing. Also, I'm having trouble uploading files to GitHub's "download" section.

Edit: and I've had a documentation patch accepted into Idris. Go me!
[identity profile] mark dominus (from livejournal.com)
Tuesday, November 2nd, 2010 03:18 pm (UTC)
But I have never gotten "edit this hunk" to work. I suspect either a fundamental misunderstanding on my part.

I just checked with my co-worker:

<\mjd> rjbs: Have you ever used the "edit this hunk" subfeature of git add -p?
<rjbs> yes, often
<\mjd> Every time I do it, git rejects my edited patch, saying it won't apply cleanly.
<rjbs> huh
<rjbs> I don't think I've ever had that happen

I'll ask around and let you know if I find out anything.

Tuesday, November 2nd, 2010 07:01 pm (UTC)

I’m a huge fan of git add -p; in fact, I’ve gone so far as to git config alias.p 'add --patch'. I also recommend git config interactive.singlekey yes, which means you don’t need to hit return after indicating the disposition for each hunk.

I agree that the “edit patch” feature can be a little hard to get to grips with. But I use it frequently, and I estimate that my edited patches apply cleanly at least eight times out of ten. I don’t know that there’s a trick to it, but I find it helps to bear in mind the preimage that the patch will be applied to, and make sure the (edited) context matches it.

As it happens, I used the “edit patch” feature about ten minutes ago, and I got the “Your edited hunk does not apply” error. But once I’d hit y to reedit, it was clear where I’d garbled the context. Pozorvlak, feel free to ask me for help any time it isn’t behaving the way you want.

Wednesday, November 3rd, 2010 07:27 pm (UTC)
Do you need to muck about with the context line at the top?
Wednesday, November 3rd, 2010 07:49 pm (UTC)

You mean, the hunk header with the @@ and the line numbers? If so, then no, but then I use Emacs’s diff-editing mode, which automatically keeps hunk headers correct as you edit. However, I’ve just tried env EDITOR=vim git add -p, and edited a patch in a way that changes the number of lines added and removed, and Git seems to have handled it fine.

(Sorry to nitpick the terminology, but I think that’s what you mean, and for diffs, “context” usually means the space-prefixed lines that show surrounding unchanged code, and that can be used to apply patches even when the line numbers match only fuzzily.)

Wednesday, November 3rd, 2010 08:11 pm (UTC)
Yes, that's the thing I meant: I didn't know the name for it. Thanks!
Tuesday, November 2nd, 2010 03:44 pm (UTC)
I've had all sorts of git peculiarities happen. But that's probably just me. I got my head round darcs, and then discovered it couldn't deal with projects as complex as mine, switched to git, but then never really got my head round it...
Tuesday, November 2nd, 2010 04:26 pm (UTC)
The process of migrating between darcs and git is complicated by three factors:

1) they're really quite different under the hood,
2) they use similar terminology for different things,
3) they use different terminology for similar things.

Fortunately for you, I plan to write a Darcs/Git rosetta stone post soon (in preparation for my talk on this subject to Glasgow.pm next Tuesday... gulp!)

How complex is your project, by the way? I know they still use darcs for GHC, but then they're Haskell hackers, and probably don't mind the occasional enforced period of hard thinking :-)

[To be fair to the darcs team, the recently announced darcs 2.5 includes many speed improvements, including some which lower asymptotic complexity.]
Tuesday, November 2nd, 2010 04:37 pm (UTC)
The terminology thing got me, as did the whole "different philosophy" thing. Particularly as I'd got my head round distributed repos, and had nowhere to put a central repo, so kept forgetting which one of my repos I was designating as the "central" one...

The project was/is huge, in terms of total file size - I can't remember how huge, and I can't check it atm, due to job move chaos. But basically, it was too big for darcs, and I hit some sort of out-of-memory or infinite loop issue. That's why I went for git - my project was huge but not as huge as Linux ;)
Tuesday, November 2nd, 2010 04:51 pm (UTC)
Particularly as I'd got my head round distributed repos, and had nowhere to put a central repo, so kept forgetting which one of my repos I was designating as the "central" one...

What you need to do here is set the origin remote up so that git remembers the central repo for you. See here (http://help.github.com/creating-a-repo/) and here (http://help.github.com/remotes/).

I think that git probably has equal ability to handle distributed repos, but darcs certainly makes it easier.
Tuesday, November 2nd, 2010 04:01 pm (UTC)
*discovers an LED on the back of his Nexus One*. Coo!
Tuesday, November 2nd, 2010 04:27 pm (UTC)
I'd love it if you could try out my app and let me know how you get on with it.
Tuesday, November 2nd, 2010 04:47 pm (UTC)
Hm. I download the package, select it in the notifications pull-down, select "OK" to install it, and then it says "Application not installed". Downloading it to my mac, plugging the phone in and running "adb install LEDFlashlight-0.3.apk" results in the following:

482 KB/s (14166 bytes in 0.028s)
pkg: /data/local/tmp/LEDFlashlight-0.3.apk
Failure [INSTALL_PARSE_FAILED_NO_CERTIFICATES]


I have non-Market installations enabled on the phone, and I can install apps that I've compiled myself.
Tuesday, November 2nd, 2010 05:11 pm (UTC)
I didn't realise you needed to sign apps before other people could use them - d'oh! It should be fixed now - try it again?
Tuesday, November 2nd, 2010 05:24 pm (UTC)
Works very nicely. All you need now is a nifty icon. :-)
Tuesday, November 2nd, 2010 05:40 pm (UTC)
More precisely, I need fifteen nifty icons, conforming to the extensive design guidelines (http://developer.android.com/guide/practices/ui_guidelines/icon_design.html). A job for tomorrow, I think :-)
Wednesday, November 3rd, 2010 12:28 am (UTC)
Go you indeed! Er, what's Idris?

The Android app looks very cool indeed. I'll see if I can install it and give it a trial in a suitably dark place...
Wednesday, November 3rd, 2010 09:42 am (UTC)
Idris is a dependently-typed systems programming language. Which means

1) it looks a lot like Haskell,
2) but types can be parametrised by values, not just other types (think "vector of length n" or "kg^1 m^1 s^-2")
3) you can do the sort of low-level bit-twiddling necessary for network stacks or operating systems.

I've been wanting to learn about dependent typing for a while, but AFAICT most such languages are afterthoughts tacked on to proof assistants - when I asked some Epigram guys if their language could be used to write web apps, they reacted with horror and disgust. Whereas Idris is all about writing actual programs, to see how useful dependent typing actually is. Easy choice, as far as I'm concerned.

Plus, I know the author :-)
Thursday, November 4th, 2010 09:01 am (UTC)
Interesting! At that level of explanation I get it, but the Wikipedia article reduced me to blank incomprehension (dependent typing as an axis of the lambda cube from simple lambda calculus to the calculus of constructions? wtf?) which is probably not good for someone studying computer science.

Is there a functional language you'd recommend for learning about the paradigm?
Thursday, November 4th, 2010 12:26 pm (UTC)
Yeah, I've tried and failed to read that article myself a few times. I'm actually learning Idris in the hope of learning about the paradigm, so I guess I'd recommend that. I previously tried learning Coq (which is much more mature), but found it frustratingly underdocumented. Plus it's more of a proof-engine with programming language attached rather than the other way around.

[As you probably know, the Curry-Howard isomorphisms mean that type-checking is equivalent to proving logical statements: the more sophisticated your type system, the more complex the logical language in which you're doing proofs. If your type system has dependent types, then the related logic is complex enough that finding proofs is no longer computable, so you need to provide some kind of human-directed proof assistant. But now you can use your programming language to write programs which calculate proofs, so the whole thing goes round in circles :-)]

Another interesting choice might be Epigram, though I've never tried it and the syntax looks frankly barking.
Wednesday, November 3rd, 2010 10:19 am (UTC)
Backstory on the flashlight app:

About four years ago, I won a Sony-Ericsson K750i in a competition. It was a lovely phone. The LED flashlight was one of about four features I actually used on it (the others being phone, text, and camera). Then it died, as all SE phones tend to (damn the physical joysticks!). I couldn't get another K750i, but there was an "upgraded" version - but it lacked the torch! It was also too big, pig-ugly, and not coincidentally the last SE phone I've used. So I've been jonesing for a torch on my phone ever since. When I discovered that the FroYo API supported such a thing, but that there was no built-in app for it on the N1, well...