Wednesday, February 2, 2011
ruby 1.9 gem 1.5 bundler 1.0.9 problem fixed
bundler 1.0.10 fixed whatever problem it had with gem 1.5. just have bundler at or above version 1.0.10 and gem 1.5, or bundler 1.0.9 or below with gem 1.4. and all of this seems to only have been an issue on ruby 1.9.*. i saw no reports of problems on ruby 1.8.?
Saturday, January 29, 2011
heroku not working with rvm on ubuntu
turns out when rvm installs ruby 1.9.2 on ubuntu, it will keep compiling even if some libraries aren't there. so if you don't have ssl libraries, it will compile ruby, but you just won't get to require 'net/https'. which is cool. i prefer this behavior. but it leads to some head scratching when later on, trying to install and use heroku keys:add, you get messages like the following:
no such file to load -- net/https. Try running apt-get install libopenssl-ruby
(See full trace by running task with --trace)
wtf? so ok, sudo aptitude install -y libopenssl-ruby and try again.
but that same message comes up! i tried other stuff, like rvm package install openssl and still got the same error message. uninstalled the gemset and reinstalled. still no dice. uninstalled rvm completely rvm implode and reinstalled bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ), and that did the trick. in retrospect, all i probably needed to do was recompile 1.9.2. and even then, i probably just needed to recompile the openssl part with the libopenssl-ruby library installed on my system.
so in short, what i needed to do was:
sudo aptitude install -y libopenssl-ruby{,1.9.1}
rvm implode
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
gem install rails
gem install heroku
heroku keys:add
and then continue with the rails tutorial heroku part
here's some posts i found while troubleshooting just now:
no such file to load -- net/https. Try running apt-get install libopenssl-ruby
(See full trace by running task with --trace)
wtf? so ok, sudo aptitude install -y libopenssl-ruby and try again.
but that same message comes up! i tried other stuff, like rvm package install openssl and still got the same error message. uninstalled the gemset and reinstalled. still no dice. uninstalled rvm completely rvm implode and reinstalled bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head ), and that did the trick. in retrospect, all i probably needed to do was recompile 1.9.2. and even then, i probably just needed to recompile the openssl part with the libopenssl-ruby library installed on my system.
in short
so in short, what i needed to do was:
sudo aptitude install -y libopenssl-ruby{,1.9.1}
rvm implode
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
gem install rails
gem install heroku
heroku keys:add
and then continue with the rails tutorial heroku part
related posts
here's some posts i found while troubleshooting just now:
- http://nicksda.apotomo.de/2010/03/running-ruby-191-with-rvm-on-ubuntu-karmic/
- http://22ideastreet.com/debug/no-such-file-to-load-when-running-ruby-1-9-2-on-ubuntu this blog's tagline is pretty much exactly how i see the "i am lucky" blog
- http://www.richardsimonjust.com/2011/01/ruby-on-rails-in-the-beginning/ i didn't actually see this until after i had done the above. looks like this is a more rvm-ish way to do it.
Tuesday, November 30, 2010
rexml notes
REXML::Document.write is deprecated
rexml printing can be done with something like:
#!/usr/bin/env ruby
require 'rexml/document'
include REXML
doc = Document.new
doc << Element.new('root')
doc.elements['root'] << Element.new('child')
output = ''
doc.write output
puts output
#<root><child/></root>
output, indent = '', 1
doc.write output, indent
puts "with indent:"
puts output
=begin
with indent:
<root>
<child/>
</root>
=endnew hotness
but that's deprecated. so use
REXML::Formatters instead.#!/usr/bin/env ruby
require 'rexml/document'
include REXML
doc = Document.new
doc << Element.new('root')
doc.elements['root'] << Element.new('child')
output, indent = '', 1
Formatters::Pretty.new(indent).write doc, output
puts output
=begin
<root>
<child/>
</root>
=endthere are 2 other formatters availabe: default, and transitive. transitive does its best to preserve content nodes, including whitespace, but it will insert whitespace in non-content areas to improve formatting. so between attributes, tagnames, but not in text nodes.
more pretty print, please
pretty print also has a
width, and a compact. compact will fit nodes with only text children onto 1 line if it can be done smaller than the width. large sections of text are always wrapped at 80 chars and indented 1 level further than their parent.#!/usr/bin/env ruby
require 'rexml/document'
include REXML
doc = Document.new
doc << Element.new('root')
child = Element.new('child')
child << Text.new(<<-EOT)
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
EOT
small = Element.new('small')
small << Text.new(' little
text ')
doc.elements['root'] << child
doc.elements['root'] << small
output, indent = '', 20
pretty = Formatters::Pretty.new(indent)
pretty.width = 75
pretty.compact = true
pretty.write doc, output
puts output
=begin
<root>
<child>
Lorem ipsum dolor sit amet, consectetur
adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis
nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit
in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint
occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim
id est laborum.
</child>
<small> little text </small>
</root>
=end
side note
i used this line for printing the above stuff escaping the characters, but preserving the whitespace:
File.open(__FILE__){ |f| puts Text.new(f.readlines.join, true) }adding children on child creation
some child elements can have their parent node set on creation. works for Document, and Element nodes, but this doesn't work for text nodes, as far as i can tell.
#!/usr/bin/env ruby
require 'rexml/document'
include REXML
doc = Document.new
root = Element.new('root', doc)
child = Element.new('child', root)
Text.new('Lorem ipsum', child) #doesn't work, why?
small = Element.new('small', root)
little = Text.new(' little
text ')
small << little # adding text nodes like this works
output, indent = '', 20
pretty = Formatters::Pretty.new(indent)
pretty.width = 75
pretty.compact = true
pretty.write doc, output
puts output
=begin
<root>
<child/>
<small> little text </small>
</root>
=end
Monday, July 26, 2010
ruby Array#uniq uses eql? and hash
this one kept me busy for 20 minutes
if you create an array of objects and wish to call
uniq on that array, the objects of the array must supply both the eql? and hash methods. the hash method must return an integer; it's not enough that the return value be constant, it must be a Fixnum.an example
here's some code to demonstrate that you need both to be defined.
class Foo
attr_reader :s
def initialize s
@s = s
end
def inspect
"#{self.class}: @s=#{@s.inspect}"
end
alias :to_s :inspect
end
foo_array = ["a","b","b"].map{|e|Foo.new e}
puts "initially:"
puts " #{foo_array.inspect}"
puts " #{foo_array.uniq.join ', '}"
#initially:
# [Foo: @s="a", Foo: @s="b", Foo: @s="b"]
# Foo: @s="a", Foo: @s="b", Foo: @s="b"
class Foo
alias :old_hash :hash
def hash
@s.hash
end
end
puts "with hash defined:"
puts " #{foo_array.inspect}"
puts " #{foo_array.uniq.join ', '}"
#with hash defined:
# [Foo: @s="a", Foo: @s="b", Foo: @s="b"]
# Foo: @s="a", Foo: @s="b", Foo: @s="b"
class Foo
undef hash
alias :hash :old_hash
def eql? o
@s == o.s
end
end
puts "with eql? defined:"
puts " #{foo_array.inspect}"
puts " #{foo_array.uniq.join ', '}"
#with eql? defined:
# [Foo: @s="a", Foo: @s="b", Foo: @s="b"]
# Foo: @s="a", Foo: @s="b", Foo: @s="b"
class Foo
def hash
@s.hash
end
end
puts "with eql? and hash defined:"
puts " #{foo_array.inspect}"
puts " #{foo_array.uniq.join ', '}"
#with eql? and hash defined:
# [Foo: @s="a", Foo: @s="b", Foo: @s="b"]
# Foo: @s="a", Foo: @s="b"
=begin
# ruby asdf.rb
initially:
[Foo: @s="a", Foo: @s="b", Foo: @s="b"]
Foo: @s="a", Foo: @s="b", Foo: @s="b"
with hash defined:
[Foo: @s="a", Foo: @s="b", Foo: @s="b"]
Foo: @s="a", Foo: @s="b", Foo: @s="b"
with eql? defined:
[Foo: @s="a", Foo: @s="b", Foo: @s="b"]
Foo: @s="a", Foo: @s="b", Foo: @s="b"
with eql? and hash defined:
[Foo: @s="a", Foo: @s="b", Foo: @s="b"]
Foo: @s="a", Foo: @s="b"
=end
references
this forum finally led me to the idea of overriding
hash and eql?. but it also says that the only requirement for hash is that it be constant for a given state of an object. well it also needs to be a number, it turns out. otherwise you get something like this:
asdf.rb:26:in `uniq': can't convert String into Integer (TypeError)
from asdf.rb:26:in `'
infuriating. i had no idea what integer it was talking about. i see no integer! AAUGH! so it turns out that someone in a thread on the internet wasn't completely correct.
Monday, April 5, 2010
gitweb serving gitosis repos via apache2 (on ubuntu karmic)
set up gitosis
modify
create
make files visible to apache2
modify
save the configuration and push it back to gitosis
open
install packages
sudo aptitude install gitweb apache2configure gitweb
modify
/etc/gitweb.conf:
# path to git projects (.git)
#$projectroot = "/var/cache/git";
$projectroot = "/srv/gitosis/repositories";
# directory to use for temp files
$git_temp = "/tmp";
# target of the home link on top of all pages
#$home_link = $my_uri || "/";
# html text to include at home page
$home_text = "indextext.html";
# file with project list; by default, simply scan the projectroot dir.
#$projects_list = $projectroot;
$projects_list = "/srv/gitosis/gitosis/projects.list";
# stylesheet to use
#$stylesheet = "/gitweb.css";
$stylesheet = "/git/gitweb.css";
# logo to use
#$logo = "/git-logo.png";
$logo = "/git/git-logo.png";
# the 'favicon'
#$favicon = "/git-favicon.png";
$favicon = "/git/git-favicon.png";
configure apache2
create
/etc/apache2/conf.d/git with this content:
<Directory /var/www/git>
Allow from all
AllowOverride all
Order allow,deny
Options ExecCGI
<Files gitweb.cgi>
SetHandler cgi-script
</Files>
</Directory>
DirectoryIndex gitweb.cgi
SetEnv GITWEB_CONFIG /etc/gitweb.conf
make files visible to apache2
sudo mkdir /var/www/git
sudo cp /usr/share/gitweb/* /var/www/git
sudo cp /usr/lib/cgi-bin/gitweb.cgi /var/www/git
sudo /etc/init.d/apache2 reload
chmod 0755 /srv/gitosis/repositories/test_repo.git
configure gitosis
git clone gitosis@localhost:gitosis-admin.git
cd gitosis-admin
modify
gitosis.conf, add the following:
[repo test_repo]
gitweb = yes
description = one line test repo description
owner = first_name last_name
save the configuration and push it back to gitosis
git add gitosis.conf
git ci -m "publishing test_repo via gitweb"
git push origin master
try it out
open
http://localhost/git and see test_repo.git in column titled "Project"references
- how to install a public git repository on a debian server
- daniel baumann debian cheatpages on gitosis
/usr/share/doc/gitosis/examples/example.conf(installed with gitosis package)
Wednesday, March 3, 2010
git submodule moving
how do you update a git submodule? say the submodule used to be at
before:
after:
now
before:
after:
when
places i went looking for this info, but didn't find it:
http://book.git-scm.com/5_submodules.html
http://progit.org/book/ch6-6.html
http://pitupepito.homelinux.org/?p=24
http://gaarai.com/2009/04/20/git-submodules-adding-using-removing-and-updating/
http://www.hackido.com/2009/01/quick-tip-remove-git-submodule.html
gitosis@example.com:submodule_a.git, but the developers switched hosts and now it's at gitosis@example.net:submodule_a.git. turns out all you have to do is change .git/config.in superproject/.git/config
before:
[submodule "submodule_a"]
url = gitosis@example.com:submodule_a.git
after:
[submodule "submodule_a"]
url = gitosis@example.net:submodule_a.git
now
git submodule update will use example.net instead of example.com. but that doesn't change the content of the repository, just the configuration for your local copy of the superproject. if someone clones your repo, they'll try to reach the submodule at gitosis@example.com:submodule_a.git. to avoid this, update .gitmodules to point at the new location as well.in superproject/.gitmodules
before:
[submodule "submodule_a"]
path = submodule_a
url = gitosis@example.com:submodule_a.git
after:
[submodule "submodule_a"]
path = submodule_a
url = gitosis@example.net:submodule_a.git
when
git submodule init reads the .gitmodules file (in a newly cloned repo), it will get the new location for the submodule and setup the .git/config file accordingly.helpful, but not what i wanted
places i went looking for this info, but didn't find it:
http://book.git-scm.com/5_submodules.html
http://progit.org/book/ch6-6.html
http://pitupepito.homelinux.org/?p=24
http://gaarai.com/2009/04/20/git-submodules-adding-using-removing-and-updating/
http://www.hackido.com/2009/01/quick-tip-remove-git-submodule.html
Tuesday, March 2, 2010
gitosis on ubuntu karmic 9.10
quickstart
as some_user@example.com:
on the server that will host the git repos,
sudo aptitude install gitosis
sudo -H -u gitosis gitosis-init < ~/.ssh/id_rsa.pub
git clone gitosis@localhost:gitosis-admin.git
cd gitosis-admin
scp newuser@example.net:.ssh/id_rsa.pub keydir/newuser@example.net.pub
vim gitosis.conf #:tabnew /usr/share/doc/gitosis/examples/example.conf
#add newuser@example.net to project_foo_group, make project_foo writable, close
git add .
git ci -m "add newuser@example.net to project_foo_group, make project_foo writable"
git push origin master
example gitosis.conf pushed back to gitosis-admin.git:
[gitosis]
[group gitosis-admin]
writable = gitosis-admin
members = some_user@example.com
[group project_foo_group]
members = some_user@example.com new_user@example.net
writable = project_foo
then as newuser at example.net:
cd project_foo
git remote add origin gitosis@example.com:project_foo.git
git push origin master
again, but cluttered with explanations
as some_user@example.com
sudo aptitude install gitosisturns out there's a gitosis package in ubuntu. but it was unclear what installing it did. after reading some docs, such as
/usr/share/doc/gitosis/README.rst.gz (installed with the gitosis package) and a blog post about hosting git, i was ready to guess. i found that the gitosis user had already been set up. finding its home directory was a matter of sudo su gitosis -;cd;pwd. this let me know first, that there was indeed a user named gitosis and second, that its home directory was at /srv/gitosis. this turns out to be irrelevant because the gitosis package already knows this. that directory was empty, iirc. so i guessed that i needed to pick up at gitosis-init.
sudo -H -u gitosis gitosis-init < ~/.ssh/id_rsa.pub
tell gitosis whom to trust for its administration. make the user
gitosis run gitosis-init and give it the public key of whomever will admin the gitosis server (in this case it's the public rsa key of the current user). gitosis-init takes care of putting this file in the right place with the right name(/srv/gitosis/repositories/gitosis-admin.git/gitosis-export/keydir/some_user@example.com.pub). the exact place doesn't matter. it just matters that gitosis knows about it and will refer to it to verify requests, like cloning:
git clone gitosis@localhost:gitosis-admin.git
the current user (some_user@example.com) wants to clone from the user
gitosis at localhost the gitosis-admin git repository. the user gitosis sees this request and needs to verify that it should fulfill that request. it uses the key (some_user@example.com.pub) that was just set up in the gitosis-init step. ssh magic happens here. the user gitosis trusts the incoming request and pushes out the repository to the requester, some_user@example.com. now some_user@example.com can modify the repository and write it back (all of these permissions and configurations are set up by gitosis-init.
cd gitosis-admin
when you clone the repo, its contents are put into a folder in the current directory, so go into it.
scp newuser@example.net:.ssh/id_rsa.pub keydir/newuser@example.net.pub
copy yet another public key into the key directory. this is the public key of newuser at example.net. copy it to the directory keydir with the filename user@host.pub. gitosis knows to look in this directory for files named like this for the public key.
vim gitosis.conf #:tabnew /usr/share/doc/gitosis/examples/example.conf
#add newuser@example.net to project_foo_group, make project_foo writable, close
modify gitosis.conf to add the relevant sections. scroll up a bit to see gitosis.conf. there is an example configuration at the location specified. in my example i create a group called new_project_group for the repository new_project. it says that the users some_user@example.com and newuser@example.net can write (which implies read and write) to the project new_project.
git add .
git ci -m "add newuser@example.net to project_foo_group, make project_foo writable"
save those changes! the public key and the configuration change! very important. but remember, this is just saving locally. you haven't told anyone else about this.
git push origin master
put those changes back up to the repository that gitosis@example.com knows about! gitosis will check its current configuration and see that it accepts changes from some_user@example.com to the gitosis-admin.git repository. gitosis has some kind of hook magic going on here. i'm not sure if it's a post-commit, or post-applypatch or what. but something black box happens here. the result of the black box is that changes you just pushed back to the gitosis-admin repo are now reflected by gitosis@example.com. it now knows about a new_project_group group, and the public key of newuser@example.net (for more ssh magic), and about the new_project repository.
as newuser@example.net
so now that the server has been set up and configured and doodadded, it's time to go put some content in it, other than the content that determines the configuration and the doodadding.
cd project_foo
newuser@example.net already has a project with some commits in it. so go into that directory.
git remote add origin gitosis@example.com:project_foo.git
tell that git repo about the new git server! gitosis on example.com knows about the project_foo git repo from the configuration file pushed to it earlier.
git push origin master
and the finish! this will push the master branch to the location nicknamed origin. origin is the nickname for gitosis@example.com:new_project.git. gitosis receives this request, does more ssh magic by looking at the public key pushed in gitosis-admin/keydir/newuser@example.net.pub. hooray! gitosis@example.com will see that the repo doesn't already exist, and accept the push, creating and populating the repo in one swoop! hooray!
Subscribe to:
Posts (Atom)