Bernhard Häussner
Tags: Artikel mit dem Tag «lang:en» durchstöbern

Howto: Start using Subversion

31.01.2010, 14:46
Subversion

Subversion

Sometimes you want to start using Subversion code control with an existing project. This tutorial explains the steps required to create a repository and add the files of the existing project.

Start by creating a repository:

svnadmin create /dir/to/store/repo/repository-name

This will create a directory „repository-name“ containing the database of files and revisions.

Then let's add some internal directories to our repository:

svn mkdir file:///dir/to/store/repo/repository-name/trunk \
 -m "Creating repo directory structure"

Now that you have created the repo-directory that should contain all the files, import the existing project files. Start by checking out the empty repo-dir to into your project dir. This will make your project dir a working copy (that is: create a dir named „.svn“ containig some internal info) but won't change anything else.

cd /existing/poject/dir
svn checkout file:///dir/to/store/repo/repository-name/trunk .

Then go on adding (or planing to add) all the files:

svn add *

This command will list all the files that will be loaded into the repository. You can always look at the planned changes with svn st.

You probably want to exclude some files such as configuration files, runtime data. You just have to revert the add-command again:

svn revert runtimedata # exclude whole dir
svn revert config/my.ini # exclude single file

Then apply the changes to your repository (commit it):

svn commit \
-m "initial import"

And that's it. You project is added to the repository without extra files. That can be crucial if your runtime data has a huge file size. If you're paranoid or just curious check the repository for success:

svnlook tree /dir/to/store/repo/repository-name

This should show the imported directory tree. Now you can start making changes to your files and commit them as usual.

vim app.cpp
svn commit -m "typo"
svn log -r 1:HEAD #show full revision history

If you ever got stuck, you may use the built in help:

svn help #list commands
svn help commit #list options
svnlook help tree #works too

I will start using subversion for everything... soon.

Kommentare: 4 Einträge

Twitter - What am I doing?

27.09.2009, 16:13

Everyone is writing about twitter now, everyone is thinking he's missing things going on at twitter, newspapers report about eyewitnesses tweeting things and twitters user count and press representation is was rapidly growing. So what's that all about? It's about a microblogging service that started in 2006 as a small project of Biz Stone and Evan Williams, who wanted their colleagues to answer the simple question "What are you doing?".

I have been a member of Twitter since March 17, 2007 and have tweeted 439 times since then until now (actually not too many updates). Anyway I mentioned a slight change in how people use twitter. This usage history resulted in a rich variety of uses of twitter. Here are some behaviours I collected "through the years":

The What-are-you-doing-guys

There are some users that nearly only answer THE question when it comes to twitter. You are likely to find mostly tweets like "@having breakfast" or "preparing lunch" in their profiles.

It's really funny to follow one of those What-Are-You-Doing-Guys and then meet her. You won't have anything to say, because you do already know (nearly) everything about your fellow tweople.

Also you do really have a log about all the small things you did in life. This might be very interesting some years later.

The Chatroommates

These tweople that only use twitter like a chat are a bit incompatible to the others. They have evolved in the SMS times, when twitter was THE way to text your friends. You might find many senseless tweets like "ok pals I'm off" or "@yomama sure".

The 140-Excited

Some people seem to not want to tell everyone what they are doing and don't have too many friends on twitter, so they don't really have to use twitter. But everyone does, so do they. This is why they seem to focus on (bad?) jokes, proverbs and short quotes.

The Newsfeedorz

When you have found a stream with only headlines and links or 6 of 7 tweets starting like "new blog post: " you know you have found a Newsfeedor. They use twitter only for posting "news". There are famous ones like CNN and rather not too famous ones. And of course many advertisers have fount their new channel at twitter. The very bad thing about them: It's usually not original content and it's most of the times better available through RSS.

The Readers

This group is a bit underrepresented. Some of them don't even have a twitter account. They are reading through someones profile (subscribing their stream as RSS) or using one of the services that aggregates twitter messages, like delicious.com. Or they use twitter as a real-time opinion-of-the-tweeting-world search engine. I think the twitter makers had a good reason to change their homepage to a mere search page.

The Retweeters and Answerers

A phenomenon at twitter is retweeting. If you want to pull the attention of your readers to a statement of someone else you retweet that (you just tweet it again putting RT @name in front of it). Or you tell everyone your opinion about it (like: opinion (via @name)) or as direct answer (@name blaaa). Now some tweople only do this. If you look through their stream you will find dozens of answers and you don't get what it's all about. This is a true Retweeter/Answerer.

The Trendy

This is by definition a very popular behaviour: Commenting on the trending topics on twitter. Some "answers" are really funny - and of course it's a cool way to share personal experiences. It's a kind of very fast global FB. Just don't overdo it. (And don't just write "#iamsinglebecause it's trendy". )

So what's correct?

As always - nothing. So what do I do? Simple: Mix. I retweeeet what I like or want others to know, I answer questions, I keep a log of some things I did, I stay informed about my friends, and I post stuff I put into the cloud.

You can always find new scenarios where you can use a 140-char-messages-posting-page. For example I have started to collect new/strange/biased/funny (German) words. And sometimes I post cryptic messages. For example this one related to the sense of life, a movie, Alice in Wonderland and the time I arrived at school that day.

And because it's always 140-character limited you can display your twitter status e.g. on your website. I do that through my lifestream. My homeserver that serves as a very neat clock too also shows my twitter status to my family.

Kommentare: keine

My MySQL API onion for PHP

26.07.2009, 17:42
MySQL Onion

MySQL Onion

A huge part of web applications is usually the interaction with the SQL database. This is why I want as little work as possible connecting, escaping values, getting the right tables an so on in PHP. But it should stay simple and allow modular approaches. Therefor I'm using some nested APIs for doing queries easily:

PDO

The very fist thing I am using is PDO. It can handle many RDBMS, but I am most of the times using MySQL or SQLite. By using PDO as an API for the following layers I can make sure most of the code will work for many RDBMSs. PDO even simplifies transactions and prepared statements. Here's some sample PHP code using PDO:

$pdo=new PDO('mysql:host='.$host.';dbname='.$db, $user, $passwort);

$pdo->exec('UPDATE test SET foo="bar" WHERE id=4');

$satement=$pdo->prepare('SELECT * FROM blogeintraege WHERE id=:id');
$satement->bindValue(':id',3,PDO::PARAM_INT);
$satement->execute();
$data=$satement->fetchAll();

PDO Simplifier

The next layer is a class that will hold a MySQL database Connection (a PDO Object) and offer some simple functions for doing e.g. a simple prepared statement. Instead of binding each values manually, you can throw an array in.

It also includes a cache, if you want to run statements more than once. It can append a prefix to all queried tables and checks dynamically inserted tables for validity to avoid SQL-injections and MySQL errors. It is used like that:

$res=$db->sql("SELECT * FROM blogeintraege");
$res=$db->sql(
  "SELECT * FROM #test WHERE id=:id",
  array('id'=>$id),array('id'=>PDO::PARAM_INT),
  array('test'=>'blogeintraege'),
  array('limits'=>array(0,$l),'buffered'=>false)
);

For one array element this does not look too tiny, but the more values are bound, the more useful it gets. And it is very useful if you already have your values in an array, like $_GET.

Note that nearly everything is optional. The table array can contain more tables, for example you can have an array of tables for different languages, if they are in different tables. The bind-types don't need to be specified too. You can even leave out everything except the query as shown in the fist line of code. The Result will by default be returned as a nice array (the GROUP_CONCAT fields are array'ed too) but you can use all other PDO fetch types.

This layer follows a rather functional approve, so I needed another layer for accessing the central sql()-Function in an OOP manner. This should avoid some runtime errors and you can modify the SQL in a modular system.

Statement builder

So I created a wrapper object, that holds a pointer to the database and will construct the parameters for sql(). This comes in handy as more and more optional parameters are added.

The PDO Simplifier has a method to build such statement-objects called sqlO(). This is how the wrapper is used:

$db->sqlO('INSERT INTO blogtaglinks SET ##,type=3')
   ->setSet(array('ID_tag'=>$lasttagid,'ID_entry'=>$id))
   ->exec();
$res=$db->sqlO("SELECT * FROM #test WHERE id=:id")
        ->setData(array('id'=>$id))
        ->setDataTypes(array('id'=>PDO::PARAM_INT))
        ->setTables('test'=>'blogeintraege'),
        ->setLimits(0,$l)
        ->setBuffered(false)
        ->exec();
);

As you can see, it is a little more code, but the code is pretty self-explanatory and now one can build the sets and the other parameters as arrays and then include them easily in the statements.

A bit different: Zend Framework's $db->select() approach

A next step would be to build queries with a single API. This is a feature implemented by the Zend Framework, where you can build your SQL with some API functions and it will even work across various databases:

select = $db->select()
  ->from('blogeintraege',array('id','Titel'))
  ->where('id < ?', $id)
  ->order('id DESC')
  ->limit(0,10);

Well doesn't that look nice?

Kommentare: keine

Twitter Bookmarklet III

11.07.2009, 20:16

For twitter users: Here's an easy-to-use toolbar button for your browser that substitutes the URL shortening and copy-pasting for you. There's no installation, I don't want to know your twitter login or password, and it will shorten the URL using bit.ly.

The bookmarklet will:

  • Receive a short URL from the bit.ly API
  • Open up your twitter homepage in a new tab (Firefox) or in a pop up with the short URL and the page title included in the textarea
  • (Or take you to the twitter login page, which will then redirect)

To install just drag this link/button into your browser's bookmarks toolbar:

tweet

The bookmarklet is even supporting flickr-Photos (using their short URL like http://flic.kr/p/6qxGR2) and other web sites (Ars technica, PHP-Manual, this blog...) if they provide own shortening services.

The code is a bit inspired by John Resig's „retweet“ button but it's not on the page you are viewing, but in your browser's toolbar, so you don't rely on webmasters cluttering their designs with social bookmarking services' buttons.

For IE-Users: You will have to right-click on the link and choose save bookmark. After that, you will be warned, because it's not a simple link, but a bookmarklet.

Kommentare: 1 Einträge

ShortURL Auto-Discovery Twitter Bookmarklet

07.04.2009, 17:44
Tweet-this-Bookmarklet

Tweet-this-Bookmarklet

Recently I've created a boomarklet to post links quickly to twitter using URL-shortening. The main feature was that you don't have to login on 3rd party web sites because it takes you to twitter. But now there's some more improvement: The new bookmarklet looks for a tiny url on the website itself in a <link rel="short_url"-Tag> (thanks to Snaplog).

To install just drag this link in your bookmark toolbar and you're done:

tweet this

Since there are not too many pages that implement the short_url tag, it falls back to is.gd shortening if it couldn't find one. To test it navigate to a page that offers a short_url for example: http://robert.snaplog.com/:E39/brooklyn_not_ark

Edit 2009-10-22: New Version

The new major version Twitter Bookmarklet III is available.

New in Version 0.9.3.5:

Since the short_url could lead to confusion with URL/URI and has the underscore I've updated the bookmarklet again to support rel="shortlink" too, which seems like a better term. There was of course some discussion.

New in Version 0.9.2:

The bookmarklet has been updated again to allow the short_url keyword to be one of a space separated list. This means it works now on arstechnica.com.

New in Version 0.9.1:

I had to update the bookmaklet to support relative URLs as used by http://www.geograph.org.uk/photo/19. In Javascript element.href returns the full, absolute url like http://e.com/absolute etc. while l.attributes[x].nodeValue may return something like /relative.

Kommentare: 2 Einträge
[ Seite 1 2 ] Nächste Seite »
 
Χρόνογραφ
© 2008-2012 by Bernhard Häussner - Impressum - Login
Kurz-Link zur Homepage: http://1.co.de/