Subscribe: OneAndOneIs2
Added By: Feedage Forager Feedage Grade B rated
Language: English
function  google  hard  head tail  head  john smith  list  make  pair head  pair pair  pair  tail  test pair  test 
Rate this Feed
Rate this feedRate this feedRate this feedRate this feedRate this feed
Rate this feed 1 starRate this feed 2 starRate this feed 3 starRate this feed 4 starRate this feed 5 star

Comments (0)

Feed Details and Statistics Feed Statistics
Preview: OneAndOneIs2


Dominic's blog


The joy of Just Works

Sun, 15 Jan 2017 17:55:00 +0000

I've been making do with Linux running from cheap laptops or in a VM for a fair number of years now. I finally had enough of it: I wanted a proper desktop again. It's been years since I last built a PC. Possibly over a decade. An IDE hard disk, an Athlon XP CPU, 512MB of RAM, powered by a 350W PSU. It was a very capable machine for its time. But it had its faults: An Nvidia graphics card that would break regularly courtesy of the binary blob nonsense. Wifi only via a USB dongle. And it no longer booted, or even POSTed. So, I could have built a machine that would meet my meagre needs very cheaply. But after so long making do, I was willing to go over-spec to make sure I ended up with a machine that could do what I needed comfortably, quietly, and would be easy to upgrade if necessary. So, my requirements: Multiple core CPU, mostly because I want to play with Erlang; solid-state hard drive for the system files to live on, for performance; a big hard drive for the home partition, since that can cheaply be in the TB range; dual monitor output; decent wifi. Most importantly of all, everything had to Just Work with Linux - no binary blob, third-party nonsense. That actually simplified a lot of things. Easiest way to have Linux-friendly graphic stuff is to stick with Intel - given that I have no need of gaming or whatnot, this is no hardship and a big cost saving. Intel is *the* way to have hassle-free graphics under Linux. Sadly, the motherboard I settled on didn't have wifi onboard, so I did have to rummage around for a wifi card, but a bit of poking around found me what seemed a suitable option. RAM was fairly easy - I always buy Crucial, and I went for a single 16GB stick since it would make it easy, should the need arise, to add more RAM up to a 64GB max. The case and PSU was also pretty simple: I like Antec, and soon found a nice roomy case. I splashed out a bit on a PSU that's way more than I need, because it added so little to the final cost. The CPU I ultimately went for seemed to be the best bang-for-buck processor available at the time, and again I went with a CPU that was way more than I needed since it wasn't really that big a cost. A new HDMI monitor completed the list, to go along with my existing VGA one. Building it took up most of my free time on a Saturday, and I was struck by a few changes since my last build: I remember when CPU heatsinks were optional. My first PC had a heatsink that was barely more than an aluminium plate with a little fan on it. The mass of copper pipes and monster fan of this things's sink seem way over the top to my aging brain :) The PSU had detachable cables, instead of the rat's nest of the past. So I only needed as many cables as it took to power the hardware. So much nicer! SATA has triumphed over IDE everywhere, even on optical drives. This is awesome, IDE cables were a PITA! Those silver plates that come with your motherboard to be fitted to the case where all the output sockets go: WHAT is the point of them? All they ever do is get in the bloody way and make alignment awkward! Argh! Everything feels just a little more polished and thought-out. Like the little doohickey for the HDD lights and reset/power buttons etc. - on my old build, this was just a lot of faffing around directly on the motherboard. This mobo came with a little separate part that you plugged all the case switches and lights into, which then in turn went into the board - so much easier! On Sunday, the moment of truth came: The first time I turned it on. To my surprise and joy, it Just Worked - no wires to adjust, no settings to change. On it came, up came the UEFI screen. And that's a big change, given my last build had a BIOS. It was all very nice, and well-featured: Told me all about my case fan speed and CPU temperature and the like. It seemed happy it had detected all my hardware: Two HDs and a DVD; 16GB RAM, etc. All the temperatures seemed to be holding at pleasantly-low numbers. I plugged in my Ubuntu USB stick and attempted to boot off it. Once again, joy and surprise! It just boot[...]

Thinking in functions

Fri, 04 Nov 2016 16:05:00 +0000

AKA "When you're been reading so much Lisp that it starts to affect your brain" A while ago I did a talk on functional programming. As my example, I showed how to impliment linked lists using closures instead of the built-in data structures. Recently, as I was reading some Lispy code, it suddenly dawned on me that there was one step further I could have taken that hadn't occurred to me. So I sat and had a play, and sure enough it worked. So here's the process, for anyone who wants it :) I've put it in Javascript, since it makes it easy for anyone to try via the browser. Firstly, the specified task: We want a new data structure, "pair", which can hold two values. From this, we want be able to build linked lists. We want all access to be handled via functions: Create a pair with pair(), get one value with head() and the other with tail(). The quick, easy, obvious approach is to use a built-in data structure under the hood. Such as an array. So: function pair (head, tail) {return [head, tail] } function head (pair) { return pair[0] } function tail (pair) { return pair[1] } This is a full implementation of the desired "pair" functionality. A quick test will bear this out: > var test_pair = pair("the_head","the_tail") undefined > test_pair [ 'the_head', 'the_tail' ] > head(test_pair) 'the_head' > tail(test_pair) 'the_tail' All good! Works perfectly. So.. we're done? Not quite. This obeys the letter of the law, but falls foul of the spirit. Firstly, it's too easy to bypass the abstraction and access the data directly, instead of through our accessor functions. Secondly, it's all too easy for somebody to shunt more data into the array and make our "pair" hold more than the desired two values. > test_pair[0] 'the_head' > test_pair[2] = "sneaky misuse of pairs!" 'sneaky misuse of pairs!' > test_pair [ 'the_head','the_tail', 'sneaky misuse of pairs!' ] Not good. We must fix this! Let's switch away from arrays, and go instead to closures: function pair (head, tail) { return function (fn) { return fn(head, tail) } } function head (pair) { return pair( function (head,tail) { return head } ) } function tail (pair) { return pair( function (h,t) { return t } ) } If you're not used to closures, this may seem a little abstract. Let's break it down! pair() now returns a function. That shouldn't be a surprise in this day & age, functions are first-class objects in most languages. Let's call it the p1 function. The p1 function is a very simple function, as all it does accept another function (call it p2) as its argument and call it. Very simple. The important thing is that p1 still has access to the original arguments pair() was called with, via the magic of closures. So both the head and tail are available to p1, which means when you pass a p2 function into p1, p2 is called with the original head and tail. So now the p2 function can decide what to do with them. In the case of head(), it passes in a function that accepts the head and tail, and returns the head. Tail is identical, except for which value it returns. Once you get used to closures and functional programming in this style, it all makes perfect sense. I appreciate it can make the eyes glaze a little at first though. Let's test that it works: > var test_pair = pair("the_head","the_tail") undefined > test_pair [Function] > head(test_pair) 'the_head' > tail(test_pair) 'the_tail' So, we have continued to fulfill the specification as stated, and now we have a data structure that can ONLY be used to hold our head and tail values - no sneaky extras, and no way to view the data directly. Onwards, then! We want to use pairs to implement a linked list. In this implementation, a list of, say, (1,2,3) could be implemented by pair(1,pair(2,pair(3))). The head of a pair contains a value, the tail contains the rest of the list. Let's see how that works: > var list = pair(1,pair(2,pair(3))) undefined > list [Function] > head(list) 1 > head(tail(list)) 2 > head(tail(tail(list))) 3 Oka[...]

The perfect compromise

Sat, 25 Jun 2016 16:01:00 +0000

So, the biggest vote of a generation has been and gone. It came after a campaign painfully lacking in useful information on either side, and it departs leaving nobody really looking good. The Prime Minster, David Cameron, whose best answer to the huge responsibility of deciding how to handle an enormously complicated political decision was to say "Fuck it, you decide, I'm not going to", has made it clear he'll be continuing with his abdication of responsibility by handing in his notice rather than deal with the results himself. Everybody is therefore asking "What happens next?" with a certain amount of trepidation. Well, there's a lot of uncertainty, of course. But I think I have the answer. It's based on something once said by the great philosopher, Calvin: One of the most notable lacks in the Leave campaign was its answer to "What's the plan for after the vote?" which was famously answered with "lol, dunno!" by the head of UKIP. Slightly more useful answers cited examples of other non-EU countries that we could emulate. My argument is that the proposal of the Norweigian model is not just good, but the best possible answer, and here is why: The original referendum back in the 70s was to join the common market. A persistent complaint from Leave was that the EU was "not what we voted for" and it's perfectly true. So we could satisfy both referendums by leaving the EU and staying in the single market. So far so good. But there's more! The Norway model gives access to the single market via the EEA - the European Economic Area. The UK could continue to trade with the Europe pretty much as it always has. This would settle the markets and ease the fears of the international corporations that are suddenly finding London a less-attractive base of operations. Even better, as all informed voters will be aware, the House of Commons indicated long before the vote took place that it would use it's (roughly) 3:1 pro-Europe majority to block any attempt to take us out of the EEA. So it would actually be very difficult for our leader (whoever that turns out to be) NOT to go with the Norway model or something very close to it. But what makes it the ideal solution is this: Membership of the EEA not only gives unrestricted access to the single market. It also requires that members: abide by EU regulations regarding the market; allow free movement of workers; and pay the EU for membership - to the tune of something like £200 million a week. The Leave campaign never ceased to talk about reclaiming control of our borders; and the (wrong) amount of money we pay into the EU each week was even emblazoned on the side of Boris Johnson's Leave campaign bus. The Norway model would mean nothing changes on either front. And that's what makes it so perfect! Everybody who voted Remain - the 48% - gets to feel pissed off because they didn't get what they voted for. Everybody who voted Leave - the 52% - gets to feel pissed off because they got EXACTLY what they voted for. Just not what they actually wanted. The entire population thus gets to come together, unhappy but united again in our common hatred of our politicians, who always, ALWAYS get it wrong. And the politicians? It's ideal for them, too: They get to answer every problem with their tried-and-tested approach of blaming everything on the immigrants they can't stop from coming here; and the lack of cash they have to work with because it all goes to Europe. Life would quickly settle back to normal. The Europeans already here could stop worrying about being thrown out, the Brits abroad likewise. Trade would continue much as it always did before. The UK stops having to worry about EU policymaking because it no longer has a say in it. The entire population settles down and resigns itself to not having got what it wanted, as usual, and the whole thing is over.Original post blogged on b2evolution.[...]

Slides for my talk

Mon, 14 Dec 2015 09:56:00 +0000

On Saturday, I attended the London Perl Workshop - an annual event that's totally free to attend and has plenty of useful stuff even for people who don't know Perl.

I even did a talk myself - an introduction to Functional Programming for beginners. Nobody fell asleep, so I called it a success. As requested, I'm also making the slides available. I'm using Dropbox because meh, it's convenient.

It's Powerpoint rather than Open/Libre Office because, basically, that's what happens to be installed on my laptop already. If you weren't at the presentation and want to read the slides to get the content, I advise "notes view" because there were a few worthwhile points that didn't get turned into bullet points on the slides.

Download here

If you have any problems getting the file, tweet me or something and I'll see what I can do about it. I'm not turning comments on here because I get spammed to hell if I do that, sadly.

Tablet keyboards

Mon, 10 Aug 2015 15:49:00 +0000

So I got sick of some things on my Android tablet. The crappy privacy settings, the unrelenting stream of adverts in youtube, and so on. So I figured it was time to try out the alternative: Cyanogenmod, an open-source fork of Android. A lot went well. Things that were broken by latest Android switching away from the Dalvik runtime sprang back into life with a switch to CM and leaving it set to Dalvik. Such as YouTube AdAway (See previous post for more on that) Also, CM has privacy settings that let me say "Yes, install the Facebook app, but NO, don't let it know where I am, thankyouverymuch" and profiles so I can have it automatically mute when I'm at work and regain sound when I get home. And I lost far fewer files in the transition than I expected, which was good. There was just one little niggle. And it's to do with keyboards. For most tasks, I like to use the standard Android keyboard. It's a pretty good kb. But when I use the ConnectBot ssh client, I *need* a full keyboard, with keys like Ctrl, Alt, and Esc. No problem, Hacker's Keyboard to the rescue! But when I'm in Firefox, I want the LastPass keyboard so it can enter my username & passwords for me. So depending on what app I'm using, I might be desiring one of three keyboards. And it's a pain to have to switch them manually. No problem, because Tasker to the rescue! An app that can watch for context changes, like switching to an app, and automatically apply specified actions. Except that the UI isn't the easiest to get your head around, but eventually I was pretty confident that it wasn't me being an idiot: The option to change keyboard just wasn't there. But it had to be, because I'd used it before... A bit of Google-fu, and the answer came to light: Keyboard-switching power isn't exposed in the normal course of things. You can only get at it if you install the Secure Settings app. Which I did. But that didn't work either. A bit more poking around, and I found that it needed me to install the System+ Module to allow it to expose the functionality I wanted. No problem, it has a button that does exactly that. But I clicked on "Enable" and it failed to grant the permissions. I checked the SuperSU logs, and was told that I'd need SuperSU *Pro* to access that feature. Motherfucker! So I threw a few quid their way, and got SuperSU Pro installed & running. (You have no idea how many reboots I'm leaving out of the story here, by the way :( Tried again, saw a failure in the logs but needed to enable expanded logging for a more useful answer. Enabled it, tried again, finally got a useful error: [1]: pm: not found But *why* isn't pm found? It's in the /system/bin/ directory, with correct 755 permissions. Fscking hell. Maybe I'm missing something? Switch away from my Linux VM and back into OS X because that's where all the Android SDK stuff is installed. Open up an iTerm, and fire up adb. Which fails to find my tablet because (a) it's not plugged in at the moment, and (b) I turned off USB debugging. Fix those two problems, and *now* I can get a shell. One quick confirm on SuperSU Pro later, and I have a root shell. Can I run the pm binary? Yes. Okay, clearly there's a problem in the installer preventing it from using the correct $PATH to find the binary that's right where it fucking should be. It *can't* be that many commands to run to install this fecking module, right..? And I already know the first one from the error logs. It's pm grant com.intangibleobject.securesettings.plugin something something something So, let's dump that command into google and see if anyone has been helpful enough to list the *other* commands that are needed..? Yes! pm grant com.intangibleobject.securesettings.plugin android.permission.WRITE_SECURE_SETTINGS pm grant com.intangibleobject.securesettings.plugin android.permission.CHANGE_CONFIGURATION That's all it needs! Just those two commands! So I run those from adb where pm is[...]


Tue, 09 Dec 2014 14:42:00 +0000

That old chestnut, internet advertising. Still causing problems after all these years... The problem is clicks. When advertisers came to the Web, they realized they could make their adverts clickable. Unfortunately, this single fact caused their brains to melt. You see, no form of advertising ever has relied on "See ad, buy product". That is an approach that has never worked. It's well known that advertising works on a subtle, slow-and-steady approach: The first half-dozen times you see an advert, you don't even register it. Then the next half-dozen, you vaguely remember having seen it before. Then the next few times, you wonder briefly about the product. Then a few more exposures and you start to think about buying the product. A few more, and you resolve that you WILL buy the product. A few more still, and you finally take action and actually buy the product. And that's the best-case scenario. Sure, sometimes you'll see an ad that reminds you you already meant to buy a product and you might seem to do "See ad, buy" but those are exceptional edge-cases, not brilliant advertising. So the whole industry was based around ensuring you saw a product advertised many times, because it was repeated exposure that did the magic. And everybody knew that. A never-ending stream of subtle nudges that ultimately resulted in a purchase. Nobody ever said "We put up a billboard by the road that says 'Buy cola!' and the drivers didn't immediately pull over and dive into a shop for a cola. Clearly, the advert has failed." That would be nonsense. Advertising doesn't work like that. Internet advertising should have been just another form of exposure: A reminder of a product, which was linked to a site where you could buy it solely to make your life easier if this happened to be that one-in-a-hundred exposure that caused you to buy the product. Instead, the entire industry threw out everything they knew about how adverts work, and began a years-long scream of "CLICK ON OUR FUCKING ADVERTS YOU BASTARDS!!!" Simple text ads not getting clicked? Make them brash colours! Still not enough clicks? Bright, flashing colours! Still not enough? Animations! Dancing monkeys! Still not enough? Full-on movies! Still not enough? Movies with sound! And so on.... And so adverts became bigger, brighter, louder, and in every way possible harder to ignore. They even over-shadowed the content people were actually trying to view. And so the ad-blocker was born - a desperation move by people who just wanted to read the content they had clicked on without seizure-inducing movies screaming at them from all sides. I've used Abdblock Plus in my browser for years. For a while, I tried to maintain my own list of sites to be blocked, but it became harder and harder to stay on top, so ultimately I caved and signed up for the auto-updating filters it offers. And it eliminated the vast majority of obnoxious ads for me, and still allowed harmless ads through: the ones that were just simple text, or static banner. And that was fine, and indeed still is. But I also started using a tablet. And ads soon made their unwelcome appearance on that, too. Beyond obnoxious: Simply opening a web page sometimes saw me suddenly finding myself in the Play store being asked to okay the installation of an app. WTF?!? Not just obnoxious, this was becoming a genuine safety hazard. Something had to be done! And I discovered my old friend, Adblock Plus, had an Android app. Installed on a tablet you have root on (Which I do), it blocks ads not just in Firefox, but across all applications. Win! For a while, all was well. But then a couple of problems: Firstly, ABP had a tendency to crash and need a manual restart, which was annoying. Secondly, YouTube started using HTTPS. This is a problem, because ABP works by being a proxy, diverting all network traffic through it. This works beautifully for filtering out known advertising servers, like double[...]

An experience

Mon, 03 Nov 2014 17:32:00 +0000

I don't have an addictive personality. I can't relate to people who talk about it being hard to give things up. I once read an article about the popularity of Thai green curry, and the author (a real fan) stated that if she went too long without eating the stuff she started to get mild anxiety attacks. I can't comprehend the idea of being that attached to a food. Or smoking: When somebody says they can't stop, I get visions of a cigarette spontaneously igniting itself, leaping into the air and forcibly jamming itself between their protesting lips. This actually makes more sense to me (on a certain level) than the idea that not doing something is somehow difficult. If you want to give up smoking, just don't put a cigarette in your mouth. Simple. Intellectually, I understand why this isn't the case. I understand that habits are hard to break; I understand that drug addictions are hard to overcome; I understand that psychological attachments to a habit or routine can be hard to suppress. It all makes perfect logical sense. But that's the only level on which it makes sense. I understand, but can't relate. If you don't appreciate the distinction, try this: I can understand that to a male shark, a female shark is a desirable mate. But I can't actually relate to the concept of wanting to mate with a shark :) On the few occasions when I've had to give something up for some reason, I've never found it hard: I just stopped. Whether it was a habit like chewing nails; or a food that I had to cut out; or whatever; it just wasn't a problem. So when I recently found myself facing the prospect of dieting, I was actually quite looking forward to it: Although it's not exactly addictive per se, food is something that it's clearly not easy to go without. And I do have a fondness for sweets and savory snacks. Here, it seemed, was my chance to experience the challenges of going without. At last, I might be able to find a way to relate to the difficulties people report. My motivations for going on a diet in the first place were a little different than most, I should explain. I was by no means obese: I didn't expect anyone to notice any difference, and sure enough, nobody did. So what was the point? Well, having spent the last year or so working hard on overcoming the damage done by a motorbike accident followed by a car crash, I'd spent a lot of time in the gym. The enforced inactivity for months due to severe whiplash had weakened my back to the point of uselessness: Returning strength and flexibility was a slow process. One piece of advice you'll see on most fitness fora is that an important factor in building strength is fueling it: Eat plenty. Naturally, if you eat a lot, your body will be prone to putting some of it aside as fat rather than muscle, which leads a lot of people to adopt a "bulk/cut" cycle: Eat a lot to build muscle; then cut back to burn off the fat. It's a chore, sure, but it's easier to over-eat then under-eat than it is to stay at a "sweet spot" where you're doing neither. I'd done the "eat lots" part, and it certainly helped fuel my time at the gym. But I was starting to have difficulties here and there: A twist hold I do each morning was starting to put pressure on my gut; and I was making next to no progress with pull-ups. Since arms are nowhere near as strong as the legs, being able to use them to lift your entire body weight is quite a challenge. Although I was able to do 18 in a morning workout, I was struggling. And the main advice to make progress with pullups is to ease the burden: Reduce the bodyfat. I was also curious to see what was involved in cutting back to fat levels that would result in visible abs - something I've never had, but aspire to someday. Probably not realistic to do it all in one go, I figured, but at least finding out what weight loss is like should give me some idea of how big a chore it would be. Starting with a bit of [...]

The right to be forgotten

Mon, 20 Oct 2014 13:28:00 +0000

tl;dr: The right to be forgotten means that if John Smith gets a page removed from Google, it is only removed from searches for "John Smith" - it remains findable from any other search I'm so sick of the "Right to be forgotten" ruling being misrepresented by journalists. For anyone who didn't hear about it: an EU court ruled that Google (and others) must remove links to stories about people that contain outdated or incorrect information. A simple example of why this is needed: John Smith gets taken to court and convicted of a crime. This makes headlines. He then appeals, and the conviction is quashed: He is found innocent. This doesn't make headlines. Somebody googles "John Smith" and the first result is a link saying he was convicted of a crime. It's not hard to see how this could have negative repercussions on a person. So the EU court ruled that in such circumstances, Google (et al) must remove the links from their search. The two big lies that we keep being force-fed by the news services are: Google is now obliged to remove any links that people don't like - e.g. if John Smith's conviction never got overturned in the above example, he could still get it removed so nobody knows about it. This isn't true: Information has to be irrelevant or inaccurate, and Google is entirely at liberty to refuse the request until a court insists that the link must be removed. Far more importantly: Even if Google decides the request is valid and removes it, this does not cause the link to be removed from Google's results. That might seem contradictory, but it's very simple: What Google has been obliged to do is remove the specified links from the results for a search for the person, not to remove them entirely. To go back to our imaginary "John Smith", it means that if you google for the search term "John Smith", you will no longer get the page referring to his court conviction in the results. If, however, you do any other search that would turn up that page, such as maybe "man convicted of crime", then it will still turn up as always. I'm so utterly sick of articles like this framing the matter as "Google cast me into oblivion", or claiming that pages "will no longer be findable when searching on Google in Europe." Bullshit. It's a total lie. Prove it for yourself: Click on the link that it claims has been "cast into oblivion" and you'll find it's a page with the headline "Merrill's Mess" Put those two words into a Google search, and what is the first result? A link to the fucking article that he claims has been erased from Google. The right to be forgotten has not erased one single page from Google. It has not removed a single thing from the Internet's "memory". It does not allow terrorists, corrupt politicians, paedophiles, or any of the other "usual suspects" trotted out in these stories, to cleanup their past by removing any links to pages that say bad things about them. The pages are still there, still linked, and still findable. And Google should only be reacting to "right to be forgotten" requests that meet the criteria of the court. So a corrupt politician who's still in office, a criminal whose conviction was never quashed, etc. etc. - they don't have any standing to have their links removed. If you're going to have an opinion on the "right to be forgotten", at least make sure you're basing on what it actually entails, instead of the "argh, mass-censorship!" bullshit that some journalists are trying to make you think it is. Because I'm sick of this shit. Thank you.Original post blogged on b2evolution.[...]