Let’s say you’ve been working on a component in an incubator-style repository, and it’s time to move it to the main project’s repository. Simply copying the code would destroy the valuable history in the target repo, so that should be avoided. There are also lots of other components in the incubator repo that you don’t want to move.
You can do this using git filer-branch
. Warning: this will reduce your local copy of the incubator repository to just your component.
Either clone it locally to a different path or be prepared to clone it again from the remote.
1
|
|
Now your repository has been reduced to just the contents and history of components/my-component
.
Use git format-patch
to export all of your commits to a patch file. Props to @rombert for this idea.
1
|
|
I feel like this command could use some explaining. First off, we’re telling format-patch
to output everything to --stdout
. Otherwise,
it would create one patch file per commit, which can get pretty clumsy if there are lots of them. Second, we’re passing the output of
git rev-list HEAD | tail -n 1
for the --root
parameter. The enclosed command will find find the sha1
of the very first commit, while
the --root
parameter will tell format-patch
to include that commit, not start from it. Lastly, HEAD
is the target ref, which is
basically the most recent commit.
Now it’s time to add your component to the main project. Of course, you don’t want to add your component to the root of the repository (which is what all the paths in the patch are relative to). Thankfully, git supports prepending a path to all filenames in a patch.
1
|
|
Now your main project contains your component and all of its history. Some notes:
Pretty neat.
]]>Being fed up with ZoneMinder, I ditched it and decided to try and hack together
something of my own. After fiddling for the next half of the day with ffmpeg
,
I came up with a viable solution, in bash.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
|
Unfortunately, I was not able to just copy the codec, which would have been
optimal in terms of resource (CPU/memory) usage on my server, but it doesn’t
use up that much. Now I can set OUTPUT_DIR
to somewhere in my /var/www
,
set up authentication on it via .htaccess
and be done with it. Dad can now
easily view the recordings using his browser, and if he really needs to view the
live stream I can just bookmark the RTSP stream in VLC for him or something.
Bottom line: K.I.S.S.
]]>find
, the command line tool. In case you’re not familiar with the find
command, RTFM, it’s freaking beautiful. However, in the hands of a non-RTFM-ing user (like me) it can be quite destructive. Let me demonstrate.
I wanted to use find
to delete a bunch of files from a hierarchy, based on a simple name rule. So I thought I should use xargs
in combination with find
to delete them. After a quick lookup of the -print0
and -name
arguments of the find
command, I concluded that it would be a good idea to run the following command:
1
|
|
Can you guess what it did? Let me help you: it deleted all the files under .
. The directories are still there, but they’re not any help, are they? Now, fortunately for me, this was in a git repository that I had just pushed to a remote, so I was able to just clone it again.
In order to understand what happened, I had to actually read the man page carefully and pay attention. Apparently, everything that comes after the path (in my case .
) on the command line is treated as an expression by find
, where every argument evaluates to true or false, and is ORed with the next one. The -print0
argument always returns true, because it’s only meant to change the output, not the actual filtering. Because of this, my -name
argument was completely ignored.
To conclude, the correct command would have been:
1
|
|
This way, the -name
argument will take precedence over print0
. However, because I actually spent time reading the manual this time, I discovered find
also has a -delete
argument, so xargs
is not actually needed at all:
1
|
|
As I was saying, freaking beautiful.
]]>1 2 3 |
|
Now, expand the Object and voilà, you’ll see both properties. This can be very confusing with more complicated objects. If you’re too lazy to run that code, here’s proof:
As a solution, you can clone the object before logging it. Here are a few suggestions for how to do that.
]]>First off, we’re going to need Ruby, right? So let’s install that, and also throw in curl (we’re going to need it in a bit):
Update: actually, you don’t need Ruby installed on your system at all. Installing curl is enough here:
1
|
|
Next, we’re going to install RVM. RVM is, at the website puts it, a Ruby Version Manager. Basically, it allows you to install multiple versions of Ruby in your home folder and use them seamlessly (as if they were the default Ruby in the system). This is useful for us because the version of Ruby Ubuntu installed is 1.8.7 (as of this writing), while the latest stable version of Ruby is 1.9.3. RVM also allows us to keep separate collections of gems (called gemsets, for obvious reasons). This is very useful when working with multiple projects that may have conflicting dependencies.
Installing RVM is dead simple. Just run the command under Quick Install:
1
|
|
Warning: the above command might not be the latest one. Make sure to double check with the RVM website.
Now, close the current terminal and open a new one. This is so that RVM can load into the new bash session. Now, let’s see what RVM suggests we should install:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
|
Install the dependencies suggested by RVM for Ruby (see the marked lines above and make sure to use sudo).
Good. Now it’s time to install Ruby! Again. The next command will install the latest stable Ruby into your home directory (so the system is not affected). Beware, it will take a long time to complete, as it downloads the Ruby source code and compiles it!
1
|
|
Now, if the command above finishes with a message similar to:
RVM is not a function, selecting rubies with 'rvm use ...' will not work.
Please visit https://rvm.io/integration/gnome-terminal/ for a solution.
Then do visit that URL and follow the instructions there. Finished? Good. Open a new terminal, again. Now type:
1
|
|
If all went well, you should see a green message telling you which Ruby is being used. Next, you should create a gemset (we talked about them in the beginning) for your new project, and also switch to it:
1
|
|
You finally have your environment set up. Next step is to install the rails gem:
1
|
|
Note: the —no-rdoc —no-ri parameters are passed so that it doesn’t waste time installing docs that are available on the Internet anyway. If you wish to have them installed for some reason, just omit those parameters.
Good, now you’re ready to create your new Rails app! Simply type:
1
|
|
To run the new app:
1 2 |
|
You just got an error now, didn’t you? Did it sound like this?
1
|
|
What’s happening is that Rails needs a JavaScript runtime (well, duh, it says so right in the error message!). What it needs it for, from what I can tell, is the new CoffeeScript (and LESS?) functionality added in the asset pipeline in Rails 3.1. To fix this, just require a JavaScript runtime gem in your app. We’re going to use one called “therubyracer”. Open up the file called “Gemfile” and add this line to it:
1
|
|
Now, in order to actually install that gem, just run:
1
|
|
in your project’s directory. The bundle command basically looks in your Gemfile and installs / updates dependencies based on it. Running the app should now actually finally ultimately work:
1 2 3 4 5 6 7 8 |
|
Now, every time you open a new terminal and intend to run the project, you will have to:
1 2 3 4 |
|
If you want to skip the two rvm
commands, you can use an .rvmrc
file. That, however, is beyond the scope of this post, and is documented here.
As I was saying, surprisingly tricky. Sure, you could have used the Ruby and Rails provided by your package manager, but given the rapid development of both, you would be several major versions behind and lacking many features. Also, managing multiple projects is now a breeze. Just install the required Ruby (some projects might rely on older versions of it), create a new gemset for it, install dependencies, run.
Whew!
]]>