Time for another in my series of occasional posts over-explaining simple programming tasks that took me longer to figure out than they should have.
Here’s the simple HTML:
With jQuery, you fade an element out by first selecting the particular element. which you can do by putting its ID in quotes and prefixing it with a #:
$("#fader"). Then you tell that element what method you want to execute, which in this case is the jQuery “fadeOut” command, with a duration expressed in
microsecondsmilliseconds. Put ‘em together and you get the simple-but-powerful jQuery statement:
$("#fader").fadeOut(500);. Likewise for the
If you’re me, the first thing you’ll try will be:
Click here to give it a try on the following sample text:
So here’s a way that works. (Note that I’m not saying it’s the best or right way. If it’s worse than that, if it’s actually the wrong way, please leave a comment and I’ll link to it at the top of his post. Thanks!)
Click here to to try it on the text below:
The difference is that the second way adds a function to the jQuery’s fadeOut command that is invoked only after the fadeOut is completed. That function changes the text of the element and fades it in.
(Click here to reset both examples.)
(PS: I created the tables for the code by pasting it in here.)
Tagged with: jquery
Date: August 17th, 2014 dw
Sarah Parmenter has posted about just how ugly it gets for women in tech. She recounts a horrifying story about how as a speaker at a tech conference she was methodically assaulted online. I want to believe that this was a rare and random act, but apparently it happens more than we know because it’s not something generally the victims want to get yet more publicity about.
Thanks to the rise of feminism, the change in behavioral norms over the past 50 years has eliminated many of the superficial, public expressions of misogyny. Not all, of course, but in the circles that I’ve moved in, the change has been noticeable. There are many fewer casual male expressions of discomfort around women, many fewer belittling or sexually objectifying comments. That’s good, but it doesn’t tell us if private expressions have changed, and, more important, how thoroughly the disempowering assumptions and structures are being undone. (And, yes, I know that I must certainly be blind to my own pernicious assumptions.)
For example, I remember in the late 1990s going on a media call to the Boston Globe with a group of male developers with whom I worked. The reporter had some cutting questions about the utility of the software and about competitive threats. The five of us walked quietly back to our car, but as soon as the door was closed, the guys had a good time dismissing the editor’s comments because “she must be on the rag.” Also, she was attractive and several of the lads expressed a desire to relieve her of the stress that brought her to under-appreciate our offering. Needless to say, not only were the editor’s comments perceptive and accurate, had they come from a man we would have taken them as a conversational challenge to which we would have risen, rather than as dismissing them as carping by a bitchy, hormonally-prejudiced girl.
These were young techie men who I’m sure sincerely supported gender equality policies. The degree of their discomfort and, yes, loathing of women had never manifested itself before. This was not acceptable banter, any more than, say, racist comments would have been. Yet when the door was closed and it was just us guys, it might as well have been 1950. I was shocked.
I have to say that I haven’t seen that sort of behavior among men with the doors closed since then. I don’t know if that incident was anomalous, or if I happen to travel in circles that don’t tolerate that type of sexism, or at least don’t tolerate the overt display of it. Or maybe as I’ve become old, my presence drives all the boyish “fun” out of the room — you can’t really talk about girls when Dad is in the room. I’d like to think we’ve changed. But it’s so hard to know what goes on behind closed doors.
Until someone opens them, even at personal cost. So, thank you, Sarah.
Tagged with: gender
• sarah parmenter
Date: February 19th, 2013 dw
This is really basic, but it drove me crazy. Suppose you want to add a row of data to a MySQL database, but not if there’s already an entry in it with the essence of that data. For example, suppose you have a table of notes and the titles they’re clustered under, and don’t want to allow the same note to appear more than once for any particular title. Assume also that that table is also recording an identifier of which book the note is about.
Here’s a SQL statement that works (line breaks don’t matter):
INSERT IGNORE into
With the exception of the mysterious “IGNORE” (see below), this is a straightforward command that inserts a row into the table “playlistentries” with a series of values (‘fiction’, ’1234′,’5678′) mapped to the series of fields (title, noteid, bookid). If there’s already a row with those title and noteid values, the table will be left unchanged. Otherwise, a new row will be added.
But, this will not work unless you set up your MySQL table so that it has a unique key based on the fields you’re testing for (title and noteid in this example). That way when you go to insert a row that has an already-existing title and noteid, it will be automatically rejected. The “IGNORE” in the SQL statement means it will be rejected without creating an error message that just gets in the way.
To set up your table so that it has the right unique key, use a SQL statement like this:
ALTER TABLE playlistentries
ADD UNIQUE KEY noteidtitle (noteid,title(100))
This tells MySQL to create a unique key (named “noteidtitle”) based on the fields noteid and title. The “(100)” is there to tell MySQL that it should only look at the first 100 characters of the title field; if you’ve set up your table with that field as “text,” you’ll get an error unless you put a limit on it. A hundred characters is probably 75 more than I need.
Note also that you only run the “alter table” command once in the lifetime of your database.
Finally, please note that there is a high probability that what I’m telling you is wildly inefficient, non-robust, and suboptimal. On a scale of 1-100, I am about 3 points past raw beginner. But these commands work for me, and I am assuming as always that if you’re reading this, you are an amateur like me engaged in some small project designed primarily for your own use. Improvements and do-overs will be gladly accepted.
Tagged with: mysql
Date: October 30th, 2012 dw
Some little apps I’ve written for myself over the years refused to work on a Mac with Lion that I’ve started using at work. The problem was that any php invoked via Ajax would return only itself — that is, the return value would be the lines of the php script itself. This is not helpful.
I poked around a lot on the Net and couldn’t find anything relevant. The closest was the observation that this can happen if you begin your PHP scripts with just a <? instead of <?php, which seems awfully persnickety. Unfortunately, my scripts didn’t begin with the abbreviated form.
After getting some help by posting at Stackoverflow.com, it seemed that the machines that my scripts have worked on have PHP v.5.3.8, whereas my Lion computer for some reason was at PHP 5.3.1. So, I upgraded the php to 5.4. This page has easy instructions for doing so: http://php-osx.liip.ch. (If you want to know what version of PHP you have, in a terminal window type “php -v”.)
I’m not 100% sure that it was the PHP upgrade that did it and not some random other change or a change in the phase of the moon. But it’s working. And if you’ve been having the same weird problem with PHP, maybe it will work for you.
Tagged with: lion
• os x
Date: August 22nd, 2012 dw
Rick Klau points [g+] to a feature of Google Docs spreadsheets I didn’t know about (although I’m far from a spreadsheet maven): It can automatically include a table from any HTML document accessible on the Web. It turns out it can also include the contents of lists.
It’s not the most intuitive feature. Into a cell you type:
Except you put in the HTML page’s url instead of [URL], “table” or “list” instead of [query], and which the number of the tables or list you have in mind instead of [index]. For example:
gets the first list (ul or ol) on Joho The Blog (this page you’re reading), which turns out to be the one on the left called “Other Stuff.” If you ask for 2 instead of 1, you’ll get my blogroll.
Or, to use Rick’s more useful example:
That imports AccuWeather’s table of weather for Anchorage (where Rick is headed for vacation.)
The data updates every time you open the spreadsheet.
ImportCVS does the same for CVS data. And Kingsley Idehen explains how you can update your spreadsheet with Linked Open Data by going through SPARQL. (SPARQL lets you query a database for linked data.) (Yes, it’s over my head.)
Wouldn’t it be useful to be able to import a single element into a Google spreadsheet, even if it’s not in a list or a table? For example, suppose I want to get the headline of the first posting at, say, DailyKos.com. That element has an id of “article-1″. (I know this because I looked at the source.) So, why not let me specify the url and the id, and plop the contents into a cell in the spreadsheet? Or suppose I want the content of one particular cell of a table?
No, we’re never satisfied.
Two seconds after I pressed the “Publish” button, Rick Klau responded to my questions on the Google Plus thread where he talks about this feature. He suggests importXML for grabbing an item by its id. And to get a frozen copy of the data, copy and paste it. He also points to a post from 2007 about these features. (Oh, yeah, you can trust Joho to stay on top of the news!) In fact, that post gives an example of how to obtain the latest headline from the NYT:
=GoogleReader (“http://graphics8.nytimes.com/services/xml/rss/nyt/HomePage.xml”, “items title”, “false”, 1)
It still works. Cool!!
Tagged with: html
Date: July 27th, 2012 dw
If I have time this weekend, I’m going to give it a try scraping the weekly Berkman Buzz post. Until a couple of weeks ago, I was fairly routinely posting the Buzz on this blog, because I had written a little scraper and formatter that let me go from the email version to the blog markup I prefer. But then those bahstahds at Berkman went all HTML on the weekly email, which completely broke my scraper. But the Berkman page that lists the Buzz looks like it’s ripe for trying out the ScraperWiki tools. Looking forward to it…
Tagged with: scraping
Date: January 15th, 2012 dw
In the recent — and probably unabated — unpleasantness attending the launch of the update of this blog’s look, I have learned a little about Quirks mode. I learned this because Internet Explorer 9 was not displaying rounded corners or laying out divs (blocks of content) the way Firefox and Chrome were. Once I switched off Quirks mode in my blog pages, it worked much better.
There’s a good explanation and some very detailed info here. But as I “understand” the story, quirks mode was introduced to handle the problem that different browsers were expecting different sorts of markup (particular for CSS style information). Then, once the browsers realized it would be helpful to everyone if they agreed to support truly standardized standards, they had to decide what to do with the old code written in the particularities of each browser. So, they agreed to allow the HTML developer to specify whether the page she’s created should be interpreted according to the modern standardized standards, or if it’s quirky and ought to be interpreted according to the idiosyncratic expectations of the various browsers.
You, the HTML developer, specify your intentions in the DTD declaration at the very beginning of your HTML pages. This page will help you figure out exactly how that line should read.
Meanwhile, the shame and humiliation the launch of the new look of this blog has brought upon me only deepens, for I have given up on controlling the placement of divs by getting my floats in order. Screw it. I’ve plunked them into a table. Yeah, I’m CSS-ing like it’s 1995.
Tagged with: css
Date: December 30th, 2011 dw
I’m posting this so I’ll remember, and in case someone else is googling around for it.
A little research showed that x-frame-options are set at the server to prevent people from capturing your pages in their own evil iframes (e.g., inserting your blog posts into their spammy site), either by preventing anyone from doing so, or preventing anyone from inserting into a page that isn’t from the same site as the source page.
I couldn’t figure out how to unset those options. But Chason C., at MediaTemple.net — my hosting company — got back to me within 24 hours with the answer. It turns out that MediaTemple isn’t setting that option; WordPress is. The solution is explained in this blog post, which Chason found for me.
The irony is that the blogpost with the answer has actually captured and embedded the original blog post by Igor at KrazyWorks, which you can find here.
Tagged with: iframes
Date: September 12th, 2011 dw
You don’t have to fully understand these two brief videos from 15 years ago (I don’t) explaining solutions to tech problems building a 3D game (3D as in Quake, not as in putting on the funny glasses) to be reminded how hard it can be to do things that seem simple, and how damned clever our tech is.
Tagged with: games
Date: January 9th, 2011 dw
I’m excited. On the plane ride today, I got Linux loaded onto a USB stick which I then used to boot my Acer One netbook into Linux. Nothing special about that, but because Linux saves onto a 4G section of my USB stick, I now have a tiny, portable OS that saves the stuff I download and create.
My netbook comes loaded with Windows XP on one partition and Android on another. But it’s a particular sucky version of Android, and I’ve found I’m not using it for anything. But I’d rather not be running Windows when I don’t have to. So, the portable USB-ized Ubuntu is perfect for me.
It took me a few tries to get it so that the USB saves the stuff I create while running Linux, and I’m not entirely sure why the slider that sets up the save area was grayed out. Eventually I booted into Linux off of another USB stick, and then used Linux’s own “create startup disk” feature to erase (and format?) the USB stick, which then, at last, let me set aside a save area.
Unfortunately, I have not yet found a way to tether the netbook to my Droid so I can avoid the $15/day Net access charge at the hotel while running Linux. So, for now I’m booting into Windows and using the fabulous PDAnet app.
Tagged with: android
Date: May 28th, 2010 dw
Next Page »