All of the interesting technological, artistic or just plain fun subjects I'd investigate if I had an infinite number of lifetimes. In other words, a dumping ground...

Friday, 18 April 2008

CVS to GIT and back

CVS to GIT and back

The first step is to import a CVS tree into GIT:


mkdir foobar.git
cd foobar.git
git-cvsimport -p x -v -d :ext:takis@cvs.sourceforge.net:/cvsroot/someproject foobar


We will not make any modifications to the project in that directory, this directory is purely intended to be a GIT conversion of the CVS repository. Instead, we'll create a clone of that archive and do our hackery in there:


git clone -l foobar.git/ foobar-pi.git/


The "l" flag makes sure that git uses hard links instead of copying files, if possible.

Next, we'll make some modifications to the project and commit them using git-commit or cg-commit. As said earlier, we'll make those modifications in the foobar-pi.git directory:

cd foobar-pi.git
... do stuff ...
cg-commit


If new changes are committed in the CVS repository, we need to fetch those in our foobar.git repository, which is kind of a GIT mirror of the online CVS repository.


cd foobar.git
git-cvsimport -p x -v -d :ext:takis@cvs.sourceforge.net:/cvsroot/someproject foobar



Now, we'll pull in the CVS-commits to the clone directory.

cd foobar-pi.git
git pull



This results in a way to have a nice GIT repository of a project being hosted using CVS. Your GIT repository makes it easy to view changes in the project as you've got the full history locally on your system.

To prepare you modifications to be send as a patch, do the following:

git-format-patch origin..HEAD


This will give you a set of files, containing patches, which you can post to a mailinglist or maintainer.

If you've got write access to the CVS-repository, you probably want to commit these patches back into the CVS yourself. To do this, checkout the CVS repository somewhere on your filesystem:

export CVS_RSH=ssh
...


Get into the CVS working directory, and set the environment variable GIT_DIR to point to the .git directory within your git directory:

export GIT_DIR=/usr/local/src/foobar-pi.git/.git/


View the GIT-logs and select which commits you want to push into the CVS-repository:

git-log


Copy and paste the commit-identifier (being an SHA1-hash) and use it as a parameter to git-cvsexportcommit:

git-cvsexportcommit 4a20cbafdf25a141b31a8333284a332d1a4d6072
unset GIT_DIR


Do not forget to unset the GIT_DIR environment variable!

This will output:

$VAR1 = '4a20cbafdf25a141b31a8333284a332d1a4d6072';
...
Ready for you to commit, just run:

cvs commit -F .msg Uiml/uiml.net.build


Repeat the command shown above:

cvs commit -F .msg Uiml/uiml.net.build


The patch which you wrote and committed in your clone GIT tree, is now committed back into the CVS repository.

Now, you can resync your GIT-CVS mirror tree:

cd foobar.git
git-cvsimport -p x -v -d :ext:takis@cvs.sourceforge.net:/cvsroot/someproject foobar


Now, your patches which you committed in the CVS repository, will be pulled back into the GIT-tree which acts as a mirror of the CVS-repository.

Now, you'll want to merge this back into your GIT-clone tree, which is where you do your actual work:

cd foobar-pi.git
git pull


Now, you've come full circle. You patches which were initially committed in foobar-pi.git, were committed to the CVS tree, and pulled back into the mirror GIT tree (foobar.git) and finally back into your clone/working GIT tree (foobar-pi.git). Ofcourse your patches were already in foobar-pi.git and GIT will notice this.

Circular Icons

Circular is a free icon set containing 100+ free to use icons

Circular is a themed collection of 100+ 16×16 icons designed by me, Ben Gillbanks. The icons are available as a zip download of alpha transparent png's (link over there on the right), and cost a grand total of nothing!

License

The Circular icon set is licensed under the Creative Commons Attribution 2.5 License. This means you can use it for anything you like (commercial, charity, free etc) and make any changes you like. All I ask is that you include a link to this page somewhere in your credits/ about page.

KadC - P2P library

http://kadc.sourceforge.net/intro.html

Introduction

Welcome to KadC, a C library for publishing and retrieving records in Kademlia-based Distributed Hash Tables. Possible uses include publishing a client's IP address for other peers to connect to (e.g., Internet phones, serverless IM programs); replacements for DNS; search engine for BitTorrent clients; replacements for LDAP directories; etc. For other ideas, see my postings archived here and here .

Thursday, 10 April 2008

JSON, Yahoo YUI, charting

http://zedgraph.org/wiki/index.php?title=Main_Page

Are you looking for a way to draw in .Net? Here's yet another charting class library with a high degree of configurability that is also easy to use.

ZedGraph is a set of classes, written in C#, for creating 2D line and bar graphs of arbitrary datasets. The classes provide a high degree of flexibility -- almost every aspect of the graph can be user-modified. At the same time, usage of the classes is kept simple by providing default values for all of the graph attributes. The classes include code for choosing appropriate scale ranges and step sizes based on the range of data values being plotted.

ZedGraph also includes a UserControl interface, allowing drag and drop editing within the Visual Studio forms editor, plus access from other languages such as C++ and VB. ZedGraph is licensed under the LGPL.

http://www.jfree.org/jfreechart/

Welcome To JFreeChart!

JFreeChart is a free 100% Java chart library that makes it easy for developers to display professional quality charts in their applications. JFreeChart's extensive feature set includes:

  • a consistent and well-documented API, supporting a wide range of chart types;
  • a flexible design that is easy to extend, and targets both server-side and client-side applications;
  • support for many output types, including Swing components, image files (including PNG and JPEG), and vector graphics file formats (including PDF, EPS and SVG);
  • JFreeChart is "open source" or, more specifically, free software. It is distributed under the terms of the GNU Lesser General Public Licence (LGPL), which permits use in proprietary applications.

http://developer.yahoo.com/flash/

ASTRA: ActionScript Toolkit for Rich Applications

ASTRA, the ActionScript Toolkit for Rich Applications, is a collection of Flash and Flex components, code libraries, toolkits and utilties developed by Yahoo! for ActionScript developers. These libraries available under the terms of the open source BSD license.

http://developer.yahoo.com/yui/

The Yahoo! User Interface Library (YUI)

The Yahoo! User Interface (YUI) Library is a set of utilities and controls, written in JavaScript, for building richly interactive web applications using techniques such as DOM scripting, DHTML and AJAX. The YUI Library also includes several core CSS resources. All components in the YUI Library have been released as open source under a BSD license and are free for all uses.

http://developer.yahoo.com/yui/json/

JSON Utility

The JSON Utility is a YUI implementation of Douglas Crockford's work on JSON (JavaScript Object Notation). JSON is a safe, efficient, and reliable data interchange format. The JSON Utility provides methods for working with JSON in JavaScript, providing JSON-to-string and string-to-JSON conversion and validation

http://developer.yahoo.com/yui/charts/

Yahoo! UI Library: Charts

The YUI Charts Control visualizes tabular data on a web page in several possible formats including vertical columns, horizontal bars, lines, and pies. Notable features include support for the DataSource Utility, customizable series and axes, a customizable mouse-over datatip, combination charts, and skinning.








C++ priority queue with multiple threads

file mini.h

/* Copyright Tim O'Hare 2008 */
#ifndef _MINI_H
#define _MINI_H_
#include
#include
#define DEBUG false
class Mini
{
public:
Mini(long i): in(i) {};
Mini * pop(void) { Mini * rtn = qu.front(); qu.pop(); return rtn;};
void push(Mini * min) { qu.push(min); };
private:
long in;
std::queue qu;


};

class Message {
public:
/* for left < right; lefts cost saving is greater that right */
bool operator< (const Message& x) const { return costsave > x.costsave; }
void service(void) { if (DEBUG) std::cout << "cost saving: " << costsave << std::endl;};
Message(int costsaving): costsave(costsaving) {};
private:
int costsave;
};

class Lock {
public:
Lock(pthread_rwlock_t & stat_rwlock);
~Lock();
private:
pthread_rwlock_t rwlock;
};
#endif




file: main.cc
/* Copyright Tim O'Hare */
#include
#include
#include
#include
#include
#include "mini.h"

using namespace std;

vector < pthread_t * >threads;
pthread_rwlock_t stat_rwlock;

Lock::Lock(pthread_rwlock_t & stat_rwlock): rwlock(stat_rwlock)
{
pthread_rwlock_wrlock(&stat_rwlock);
//rwlock = stat_rwlock;
}
Lock::~Lock()
{
pthread_rwlock_unlock(&stat_rwlock);
}

/* C++ book Pg. 479 */
//void server(priority_queue&q, Lock& lck)
void server(priority_queue*q, pthread_rwlock_t& lck)
{
while(!q->empty()) {
if (DEBUG) cout << "q is not empty" << endl;
Message m(0);
{
//Lock lock(lck); // only hold the lock while extracting the message
Lock lock(stat_rwlock); // only hold the lock while extracting the message
if (DEBUG) cout << "delete: have the lock" << endl;
if (q->empty()) return;
m = q->top();
q->pop();
}
m.service();
}
if (DEBUG) cout << "q empty" << endl;
}

void sleeptime()
{
struct timeval now;
gettimeofday(&now, NULL);
unsigned int seed = now.tv_usec;
usleep(rand_r(&seed));
}

void createMessage(priority_queue*qu, int i)
{
Message m(i);
if (DEBUG) cout << "created message " << i << endl;
Lock lock(stat_rwlock); // only hold the lock while extracting the message
if (DEBUG) cout << "add: have the lock" << endl;
qu->push(m);
}

void* createMini(void *ptr)
{
if (DEBUG) cout << "Thread for createMini started" << endl;
int i=0;
//priority_queue*q1 = (priority_queue*)ptr;
//priority_queuequ = *q1;
priority_queue*qu = (priority_queue*)ptr;
for (;;i++) {
if (DEBUG) cout << "inserting " << i << endl;
createMessage(qu,i);
//sleep(1);
sleeptime();
}
}


void* deleteMini(void *ptr)
{
if (DEBUG) cout << "Thread for deleteMini started" << endl;
priority_queue*qu = (priority_queue*)ptr;
long i;
for (;;i++) {
if (DEBUG) cout << "Calling server" << endl;
server(qu, stat_rwlock);
if (DEBUG) cout << "Server finished" << endl;
//sleep(1);
//unsigned int now=time(NULL);
//usleep(rand_r(&now));
sleeptime();
}
}

int main()
{
//queue qu;
/*for (int i=0; i < 10; i++ )
qu.push(i);*/

//Mini * min2 = new Mini(0);
pthread_rwlock_init(&stat_rwlock, NULL);
priority_queuequ;
//server(qu,stat_rwlock);

pthread_t *tid1;
for (int j=1;j<100;j++) {
tid1 = new pthread_t;
threads.push_back(tid1);
if (pthread_create(tid1, NULL, &createMini, &qu)) {
perror("Failed to create createMini thread: ");
return -1;
}
}

pthread_t *tid2;
for (int k=1;k<100;k++) {
tid2 = new pthread_t;
threads.push_back(tid2);

//if (pthread_create(tid2, NULL, &deleteMini, min2)) {
if (pthread_create(tid2, NULL, &deleteMini, &qu)) {
perror("Failed to create deleteMini thread: ");
return -1;
}
}

pthread_join(*tid1, NULL);
pthread_join(*tid2, NULL);
return 0;
}



compile on Linux:
g++ -Wall main.cc -o qu -lpthread

Monday, 7 April 2008

From Postgresql weekly news - geek talk

A second problem with it is that PortalDefineQuery
 really can't risk error, because if it elog's before having set up
 the Portal, we will leak the plancache refcount that the caller is
 trying to hand off to the portal.

substitute text in multiple files at once on Linux

find . -name "*.c*" | xargs grep -l 'foo' | xargs /bin/sed -i -e 's/foo/bar/g'
find . -name "*.h" | xargs grep -l 'foo' | xargs /bin/sed -i -e 's/foo/bar/g'

From http://lists.freebsd.org/pipermail/freebsd-questions/2005-January/074032.html

tim's shared items

Add to Google Reader or Homepage