questions about URLs in tweets

7 views
Skip to first unread message

NM Public

unread,
Feb 1, 2008, 9:11:58 AM2/1/08
to twitter-deve...@googlegroups.com
I have a couple questions about URLs in tweets:

1] After some experiments, it seems that I can avoid tinyurl by
posting URLs that contain the scheme name, followed only by
alphanumeric, slash (/), and dot (.) characters. I'd like to
tweet everytime I post to my blog, but my blog URLs contain the
dash (-) character. It would be great if the Twitter backend also
allowed dashes in non-tinyurled URLs. Is there any plan for this?
If not, I'll probably tweet URLs like this:

<http://deflexion.com/2006/05/server.side.message.labels>

And then use Apache rewrite rules to redirect to this (the
actual URL):

<http://deflexion.com/2006/05/server-side-message-labels>

Does anyone have any thoughts about this? I have no desire to use
tinyurl and that is the main reason I don't use Twitter much. Any
workaround ideas (other than Apache rewriting) welcome!


2] I use JSON to display my last 2 twitters on my blog
<http://deflexion.com/> and I'd like to have URLs show up as
links on my blog. Currently the URLs are just plain text (not
links). Any tips for how to do this either via JSON or something
else?

Thanks very much,
Nancy
<http://twitter.com/nm>

Cameron Kaiser

unread,
Feb 1, 2008, 9:48:21 AM2/1/08
to twitter-deve...@googlegroups.com
> 1] After some experiments, it seems that I can avoid tinyurl by
> posting URLs that contain the scheme name, followed only by
> alphanumeric, slash (/), and dot (.) characters.

Or, just post short URLs. Not everything is tiny-urled. Thus, I have a
redirector on my own pages and I make meaningful trivial URLs to match.

> 2] I use JSON to display my last 2 twitters on my blog
> <http://deflexion.com/> and I'd like to have URLs show up as
> links on my blog. Currently the URLs are just plain text (not
> links). Any tips for how to do this either via JSON or something
> else?

You could use JavaScript to parse and rewrite the text with HTML
anchors. I can think of a couple regexes off the top of my head that
would do that.

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com
-- Immortality can always be assured by spectacular error. -- J. K. Galbraith -

NM Public

unread,
Feb 1, 2008, 11:12:23 AM2/1/08
to twitter-deve...@googlegroups.com
Sur 2008-02-01, Cameron Kaiser e'crit:

>
>> 1] After some experiments, it seems that I can avoid tinyurl
>> by posting URLs that contain the scheme name, followed only by
>> alphanumeric, slash (/), and dot (.) characters.
>
> Or, just post short URLs. Not everything is tiny-urled. Thus, I
> have a redirector on my own pages and I make meaningful trivial
> URLs to match.

I've thought of doing this, but don't really want to write my own
tinyurl service. Can you post the code you use? I've looked for
FLOSS [*] tinyurl-type code and so far haven't found anything I
like. I don't want to use MySQL or any database. FYI, I'm
collecting links related PURLs [**] and PURL-services here:

<http://del.icio.us/Deflexion.com/PURLs>


>> 2] I use JSON to display my last 2 twitters on my blog
>> <http://deflexion.com/> and I'd like to have URLs show up as
>> links on my blog. Currently the URLs are just plain text (not
>> links). Any tips for how to do this either via JSON or
>> something else?
>
> You could use JavaScript to parse and rewrite the text with
> HTML anchors. I can think of a couple regexes off the top of my
> head that would do that.

Code would be nice. Even nicer would be if this were just part of
the API as it is with the del.icio.us JSON API.

Thanks,
Nancy


[*] Free/Libre Open Source Software
[**] Persistent Uniform Resource Locator

Cameron Kaiser

unread,
Feb 1, 2008, 11:26:51 AM2/1/08
to twitter-deve...@googlegroups.com
> >> 1] After some experiments, it seems that I can avoid tinyurl
> >> by posting URLs that contain the scheme name, followed only by
> >> alphanumeric, slash (/), and dot (.) characters.
> >
> > Or, just post short URLs. Not everything is tiny-urled. Thus, I
> > have a redirector on my own pages and I make meaningful trivial
> > URLs to match.
>
> I've thought of doing this, but don't really want to write my own
> tinyurl service. Can you post the code you use?

My webserver is actually a custom job (http://httpi.floodgap.com/), so my
code would not help you much -- it's a module that simply rewrites the
URL off a list. However, Apache mod_rewrite could easily do something similar.

> > You could use JavaScript to parse and rewrite the text with
> > HTML anchors. I can think of a couple regexes off the top of my
> > head that would do that.
>
> Code would be nice. Even nicer would be if this were just part of
> the API as it is with the del.icio.us JSON API.

Don't you write any code yourself? ;-)

% cat homework.pl
while(<>) {
s#(http|gopher|ftp)://([^/\s]+)(/?[^\s]*)#<a href = "\1://\2\3">\1://\2\3</a>#g;
print STDOUT $_;
}
% perl !$
perl homework.pl
this has no URL
this has no URL
this:// has a bogus scheme
this:// has a bogus scheme
and http:/// is a malformed URL
and http:/// is a malformed URL
but http://www.floodgap.com is a URL
but <a href = "http://www.floodgap.com">http://www.floodgap.com</a> is a URL
and so is http://yer.random.blog.invalid/2008/tinyurl-would-eat-this-url-in-a-new-york-minnit
and so is <a href = "http://yer.random.blog.invalid/2008/tinyurl-would-eat-this-url-in-a-new-york-minnit">http://yer.random.blog.invalid/2008/tinyurl-would-eat-this-url-in-a-new-york-minnit</a>
^D

Conversion to JavaScript is left as an exercise to the reader, but this will
give you the general idea.

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com

-- Immigration is the sincerest form of flattery. -- Jack Paar ----------------

mcquee...@gmail.com

unread,
Feb 1, 2008, 12:10:18 PM2/1/08
to Twitter Development Talk
Ouch! I can't believe how ugly that regex is! I am still pulling
pounds and slashes out of my eyes!
> buthttp://www.floodgap.comis a URL
> but <a href = "http://www.floodgap.com">http://www.floodgap.com</a> is a URL
> and so ishttp://yer.random.blog.invalid/2008/tinyurl-would-eat-this-url-in-a-n...
> and so is <a href = "http://yer.random.blog.invalid/2008/tinyurl-would-eat-this-url-in-a-n...">http://yer.random.blog.invalid/2008/tinyurl-would-eat-this-url-in-a-n...</a>
> ^D
>
> Conversion to JavaScript is left as an exercise to the reader, but this will
> give you the general idea.
>
> --
> ------------------------------------ personal:http://www.cameronkaiser.com/--
> Cameron Kaiser * Floodgap Systems *www.floodgap.com* ckai...@floodgap.com

Cameron Kaiser

unread,
Feb 1, 2008, 12:26:38 PM2/1/08
to twitter-deve...@googlegroups.com
> > % cat homework.pl
> > while(<>) {
> > s#(http|gopher|ftp)://([^/\s]+)(/?[^\s]*)#<a href = "\1://\2\3">\1://\2\3</a>#g;
> > print STDOUT $_;}

> Ouch! I can't believe how ugly that regex is! I am still pulling


> pounds and slashes out of my eyes!

TMTOWTDI.

--
------------------------------------ personal: http://www.cameronkaiser.com/ --
Cameron Kaiser * Floodgap Systems * www.floodgap.com * cka...@floodgap.com

-- In memory of Werner Klemperer ----------------------------------------------

Reply all
Reply to author
Forward
0 new messages