Just to start a new tag “codepixel”
The whole planet here
Just to start a new tag “codepixel”
The whole planet here
This is something I came across reviewing the headers of OSG, it’s called the “safe bool idiom” and arises when we try to overload the bool operator of a class to make it part of boolean expressions… Of course this is wrong, let me spoil you a correct version of what should look like a class using the safe bool idiom
class Testable {
bool ok_;
typedef void (Testable::*bool_type)() const;
void this_type_does_not_support_comparisons() const {}
public:
explicit Testable(bool b=true):ok_(b) {}
operator bool_type() const {
return ok_==true ?
&Testable::this_type_does_not_support_comparisons : 0;
}
};
Simple, eh? Let’s examine what’s going on here. First, we typedef bool_type to be a pointer to a const member function of Testable, taking zero arguments and returning void. This is our magic type that allows for testing in Boolean contexts, without taking part in overloading contexts. Next, we define a conversion function to bool_type, just as we did with bool and void* earlier. Finally, we return “true” using a pointer to a member function (this_type_does_not_support_comparisons), which fits the bool_type, and a null value for “false”. It’s now possible to safely test instances of Testable in Boolean contexts. The strange name does have a purpose; read on to find out what it is!
Yeah, simple! the way I like it. XD
Here is the thing, the other day I wanted to copy one subdirectory from one computer to another, I can not rely on scp because I needed root permissions, neither tar worked because there was symlinks, different file permissions and owners, and there wasn’t space enough to do it (of course, you can send the tar using netcat…). The perfect solution to do such a copy is use rsync, it works nice, and can be used to reupdate a backup, and so on.
The problem is I need both root permissions on both machines, on the local machine having root permissions is the easy part but how should we proceed to get root permissions at the other end ?
You can do several things, like creating the root user, disable sudo asking for password, … but I won’t recommend them. The solution I came across ( I don’t remember from where ) is simple, but quite forgivable (that’s why I’m writing a post-to-myself). Here it is:
stty -echo; ssh myUser@REMOTE_SERVER "sudo -v"; stty echo rsync -avze ssh --rsync-path='sudo rsync' myUser@REMOTE_SERVER:/REMOTE_PATH/ LOCAL_PATH
The second line tells sudo to execute “sudo rsync” instead of “rsync” on the remote host. Without the first line sudo will prompt for a password (and we won’t be able to input it), the “sudo -v” is the one which does the trick. It simply touches the timestamp sudo has to avoid asking the password on each call.
The “stty [-]echo” avoid others to have a look at our passwords while we type them
Recently I’ve been playing with git and I found it fascinating!, for those that still don’t know what it is, git is a really fast distributed revision control system (wikipedia). Now the problem is how to switch from subversion to git, fortunately git-svn helps a lot and we can play with git and subversion in many ways. Let’s talk about them from the easiest to the not-so-easy way. I’m supposing here that you want to move from a centralized subversion to a git repository that probably will be online on a server.
This is for those that want to throw subversion away completely, for some reason this is the easiest way to switch. First what you would do on the server:
# first clone the repository from subversion
# if you can use file:// it will be faster,
# otherwise use http://your-project-url.com/svn/MySuperProject
[server]$ git svn clone -s file:///home/pplux/.../svn/MySuperProject tmp
# clone to a bare new git repository (with no track of subversion)
[server]$ git clone --bare file://`pwd`/tmp MySuperProject
# remove the old git repo from subversion, no longer needed
[server]$ rm -rf tmp/
# update server info, for "dumb" servers this is needed
[server]$ cd MySuperProject/
[server]$ git --bare update-server-info
Now clients can simple clone your repository and start working:
# use this for normal-read-only, or maybe you could use ssh://
# if you plan to upload data.
[client] $ git clone http://your-server-url.com/git/MySuperProject
Here we want to keep the subversion repository like the main reference of the project, but let people (or ourselves) use git for development. The reason to mirror the subversion is just a matter of speed, it is much faster to clone an existing git repository than cloning from subversion each time.
Here we will need to do a bit more of work, but it’s a much smoother way to migrate from subversion to git. First what we need to do on the server:
# Create and initialize a bare git repository
[server]$ mkdir MySuperProject[server]$ cd MySuperProject/
[server]$ git --bare init
Initialized empty Git repository in /home/pplux/.../MySuperProject/
# set svn project to import
[server]$ git --bare svn init -s http://your-server-url.com/svn/MySuperProject
# fetch svn data (sloooow)
[server]$ git --bare svn fetch --all
A src/CMakeLists.txt
A CMakeLists.txt
W: +empty_dir: trunk/include
...
# auxiliary files to help "dumb" servers
[server]$ git --bare update-server-info
Now the client, here we will do much more work than before to setup both the origin from the git mirror and the subversion config to commit there future changes.
# Create and initialize our copy of the git repository
[client] $ mkdir MySuperProject
[client] $ cd MySuperProject/
[client] $ git init
Initialized empty Git repository in /Users/pplux/projects/MySuperProject/.git/
# setup the server as the initial origin of data
[client] $ git remote add origin http://your-server-url.com/git/MySuperProject
# also tell git to fecth data from the remote origin(that case svn)
[client] $ git config --add remote.origin.fetch '+refs/remotes/*:refs/remotes/*'
# fetch data from the git mirror(takes a bit)
[client] $ git fetch
got 2c68737541f19685f667f601a502447425d1fcfe
walk 2c68737541f19685f667f601a502447425d1fcfe
got d4916373650b9bb636c0284dd501e6c7bfa8e304
got 13af9568120f8e7771bd386d9b7dadf69f1181cb
...
# setup the original subversion as
[client] $ git svn -s init http://your-server-url.com/svn/MySuperProject
# rebuild data...
[client] $ git svn fetch
Rebuilding .git/svn/trunk/.rev_map.1a3bf6a2-ba3d-0410-9263-a3f888f14dcd ...
r1 = 126490373bfbc2a770d762398b67fffeef73bead
r2 = a2288725c8c68ef426b97cf2b28a9135a34734d3
r3 = 4158b92a5c68489bb6ff2b4f4567cf8f830d7282
# to start working create a master that will track "trunk"
[client] $ git checkout -b master -t trunk
The post ends here you can safely stop reading now, but if you ask me, there are some good reasons to switch to git:
And big thanks to slack for pointing me out git, if he says something is good stuff… believe him
Other good links about what we’ve talked here:
http://www.gnome.org/~federico/news-2008-11.html#27
http://markmcb.com/tag/workflow/
http://utsl.gen.nz/talks/git-svn/intro.html#howto-track-rebuildmeta
http://www.viget.com/extend/effectively-using-git-with-subversion/
http://techbase.kde.org/Development/Tutorials/Git#Interfacing_KDE.27s_SVN_repository_with_git-svn
http://live.gnome.org/GitForGnomeDevelopers
http://tsunanet.blogspot.com/2007/07/learning-git-svn-in-5min.html
http://blogs.gnome.org/johncarr/2008/06/21/git-mirrorgnomeorg/
http://markmcb.com/2008/09/17/migrating-a-subversion-svn-project-and-server-to-git/
Since October 31st, around 9:45am, I’m the proudly owner of a new macbook! So again I’m quitting linux, not really, but for a notebook apple is the only one that delivers a truly “notebook-experience”, IMHO. I could not do without the close-the-lid-and-leave thing, the unix feeling, and my terminal,but it took me some days to tweak this things to feel back at home, and just as a reminder for myself I’m going to write down some little tips.
(más…)
The reasons because I didn’t write in English were perfectly explained by sole some time ago. I’m not trying to be “cool” by start writing in English, I’m just trying to be a little more “International” and hopefully most of the technical stuff I want to talk about will reach a bigger audience.
I’ve placed a new category English (RSS) for those that don’t care what I have to say in Spanish XD
And pleeeeeeeease, If you find any mistake in my grammar, vocabulary, etc. leave me a comment! I’m also trying to improve my English
Hace mucho, mucho tiempo, en una galaxia muy lejana… había un acelerador de partículas… y digo yo ¿Si mañana se acaba el mundo para qué voy a trabajar hoy?
Cómo no se va a acabar, y eso lo afirmo ya (como informático-físico-teórico que soy) pues va a ser que empezamos la temporada “vuelta al cole”, con nuevos papers por escribir, una tesis que no se si acabaremos, y un mundo nuevo de incertidumbres entre las que se encuentra que se me acaba la beca. Si alguien quiere ofrecerme trabajo, bien sea como desarrollador de videojuegos, gráficos o algo interesante o bien cobrando una pasta indecente, puede escribirme que con gusto le respondo
Hay muchas cosas nuevas que contar, papers interesantes que discutir, opengl’s casi-3.0 … pero se han acumulado tanto que mejor hacemos borrón y cuenta nueva. Por cierto, la gente se está animando a escribir en inglés, mr blat, sole, miguel, otros a los que no conozco pero sigo, Ricardo Cabello, Iñigo Quilez, Jesus de Santos Garcia, Román Cortés (no en todos),
Víctor M. Muriel, Ruben Penalva, … y otros que seguro me estoy dejando. ¿Será el momento de intentar escribir en inglés?
Ya he dicho más de una vez que los de PhD cómics me espían….
y también… real como la vida misma I y extraordinariamente real.
Gestionado con WordPress