lunedì 21 novembre 2011

Rvm & git info in console

due semplici istruzioni per ridursi il lavoro

export PS1="\[\033[01;34m\]\$(~/.rvm/bin/rvm-prompt) \[\033[01;32m\]\w\[\033[00;33m\]\$(__git_ps1 \" (%s)\") \[\033[01;36m\]\$\[\033[00m\] "

in questo modo viene sempre visualizzato il prompt della console in questo modo

ruby-1.9.2-p0@d7track ~/myapp (master) $

specificando sempre

ruby@gemset indirizzo (branch) $

guida originale

Update:

per avere un set di colori e alcune opzioni in più
https://github.com/jimeh/git-aware-prompt

git clone git://github.com/jimeh/git-aware-prompt.git ~/.bash

in questo modo si può usare in .bashrc

# from https://github.com/jimeh/git-aware-prompt

PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
export DOTBASH=~/.bash
source $DOTBASH/main.sh
export PS1="\[$txtblu\]\$(~/.rvm/bin/rvm-prompt) \[$txtgrn\]\w\[$txtcyn\]\$git_branch\[$txtrst\]\$ "
export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "

martedì 12 luglio 2011

Rails 3 jquery tabs cookie memories

Usando JQuery ui tabs volevo mantenere la tab selezionata di volta in volta usando i cookie come mostrato qui

Per farlo ho incluso il plugin jquery.cookie.js, ma per non perdere gli indirizzi completi ho dovuto passare in application.js il path che altrimenti risultava troncato nel cookie


$(function() {
$( ".tabs" ).tabs({ cookie: {
expires: 1,
path: window.location.pathname
} });
});

martedì 10 maggio 2011

If i use a ldap configuration with

# config/ldap.yml
development:
base: ou=people,dc=test,dc=com
attribute: uid
group_base: ou=groups,dc=test,dc=com
required_groups:
- ["moreMembers", "cn=users,ou=groups,dc=test,dc=com"]

and I have my dn like

uid=gmgp,ou=developpers,ou=people,dc=test,dc=com

in the log the LDAPLogger write

LDAP: LDAP search: uid=gmgp
LDAP: Authorizing user uid=gmgp,ou=developpers,ou=people,dc=test,dc=com
LDAP: LDAP search: uid=gmgp
LDAP: LDAP search: uid=gmgp
LDAP: LDAP search: uid=gmgp
LDAP: User uid=gmgp,ou=people,dc=test,dc=com is not in group: cn=users,ou=groups,dc=test,dc=com

my simple workaround is to create a local attribute


#devise_ldap_authenticatable-0.4.6/lib/devise_ldap_authenticatable/ldap_adapter.rb

27 class LdapConnect
28
29 attr_reader :ldap, :login, :login_dn

54 def dn
55 DeviseLdapAuthenticatable::Logger.send("LDAP search: #{@attribute}=#{@login}")
56 filter = Net::LDAP::Filter.eq(@attribute.to_s, @login.to_s)
57 ldap_entry = nil
58 @ldap.search(:filter => filter) {|entry| ldap_entry = entry}
59 if ldap_entry.nil?
60 @ldap_auth_username_builder.call(@attribute,@login,@ldap)
61 else
62 @login_dn = ldap_entry.dn
63 end
64 end

84 def in_required_groups?
85 return true unless ::Devise.ldap_check_group_membership
86
...
99 admin_ldap.search(:base => group_name, :scope => Net::LDAP::SearchScope_BaseObject) do |entry|
100 unless entry[group_attribute].include? @login_dn
101 DeviseLdapAuthenticatable::Logger.send("User #{@login_dn} is not in group: #{group_name }")
102 return false
103 end
104 end
105 end

This workaround works even if it does not solve the underlying problem
I prepare a commit as it should if I find a moment of time

martedì 3 maggio 2011

Taps per migrazioni tra db (ex: sqlite3 to mysql)

Con la gemma Taps la migrazione dati da un db ad un altro è veramente semplice
Qui la guida base da cui sono partito

1) istallare taps sulle due macchine

$ [sudo] gem install taps

sembra che possa servire in alcuni casi anche

$ [sudo] gem install hoptoad_notifier

2) lanciare il server taps (che sfrutta sinatra) con il comando

$ taps server [OPTIONS] local_database_url login password

per esempio: (utente e password non presenti nel db sono aggiunti posticci in quanto richiesti)

$ taps server sqlite://development.sqlite3 pippo pippo
== Sinatra/1.0 has taken the stage on 5000 for production with backup from Mongrel


3) creare se non esistente il db di destinazione

4) lanciare taps per ricevere i dati

$ taps pull [OPTIONS] local_database_url remote_url

$ taps pull mysql://root@localhost/nome_db_destinazione http://pippo:pippo@localhost:5000

ed è tutto fatto!