Wednesday, November 2, 2011

Wednesday, January 26, 2011

Very colorful vim

It seems that xterms and screen are slowly clawing their way into the 21st century... We can now view our code in more than 16 colors. There are a few hoops you'll need to jump through to get it working.




  • Make sure tmux is 256 ready, editing your ~/.tmux.conf

    • set -g default-terminal "screen-256color"



  • Make sure screen is 256 ready, editing your ~/.screenrc


    • # terminfo and termcap for nice 256 color terminal
      # allow bold colors - necessary for some reason
      attrcolor b ".I"
      # tell screen how to set colors. AB = background, AF=foreground
      termcapinfo xterm 'Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm'
      # erase background with current bg color
      defbce "on"


  • Check your terminal supports 256 colors

    • colortest

    • Run that in and out of screen

    • If you find that the gradient doesn't print what you expect, you may need to recompile screen with the configure option --enable-colors256

    • If that doesn't work, you may need to recompile X...


  • Update your .vimrc

    • syntax on

      set t_Co=256



You can now begin using some super fancy color schemes with vim. While in vim, use :colorscheme to test drive the many and varied options. Fortunately, colorscheme supports tab completion and it will search your system (/colors) and user (~/.vim/colors) runtime directories. Once you've settled on a scheme you like, add the command to your .vimrc.



Very nice (am I crazy, or are a bunch of these fifteen year old emacs color schemes)



Not too shabby

Tuesday, January 18, 2011

Migrating to MySQL

Diaspora has chosen to move from NoSQL to SQL (too much relational data). As of this writing, they are only known to support MySQL, since that's what they're running on joindiaspora.com, AFAIK. Here are my hoops, on Ubuntu...
https://github.com/diaspora/diaspora/wiki/Migrating-from-MongoDB-to-MySQL

  1. Update your source
    • git fetch upstream

    • git checkout master

    • git pull upstream master

  2. Install mysql packages
    • apt-get install mysql-server mysql-client libmysqlclient16-dev

  3. Make sure you're utf8 all the way, Diaspora is
    • sudo vi /etc/mysql/my.cnf
      1. Update the server section [mysqld]
        • collation_server=utf8_bin

          character_set_server=utf8

      2. Update the client section [mysql]
        • default-character-set = utf8

  4. Restart MySQL
    • service mysql restart

  5. Create your database.yml
    • cp config/database.yml.example config/database.yml

  6. Edit your new yaml file to suit your environment
    • Note As of this writing, only the MySQL user root can migrate from mongo to MySQL

  7. Create the necessary databases and tables
    • rake db:drop:all
      • Make sure test, development, and production all have valid credentials (for root mysql user)

      • You can safely ignore messages like:
        Couldn't drop diaspora_production : <Mysql2::Error: Unknown database 'diaspora_production'>

    • rake db:create

    • rake db:migrate

    • rake migrations:migrate_to_mysql





Voila, you should now have everything you need to help the community continue to test this massive change...

Wednesday, January 12, 2011

A rake task to syntax check erb, haml, rb, sass, and yaml files

Diaspora is pretty fluid right now. This means we are have some green tests, some missing tests, and other tests that check intent (not implementation). In an ideal world, I suppose test cases would cover all of our bases...



Until then, I've added a new task to my fork, check_syntax:all. This breaks down further to the subtasks check_syntax:erb, check_syntax:haml, check_syntax:haml_ruby, check_syntax:sass, and check_syntax:yaml. Most of these tasks are pretty straight forward, search the tree for .suffix files and check their syntax. The subtask check_syntax:haml_ruby uses HAML::Engine.new().precompiled (similar output to haml --debug) to generate the ruby haml generates. The resulting ruby is syntax checked... This is very important, because haml --check does not check ruby syntax.



The following is based on Hungry Machine's post

code is also available from here


namespace :check_syntax do
require 'erb'
require 'open3'
require 'yaml'

desc "Check syntax of various file types"
task :all => [:ruby, :erb, :yaml, :haml, :haml_ruby, :sass]

#desc 'Check syntax of .erb and .rhtml files'
task :erb do
(Dir["**/*.erb"] + Dir["**/*.rhtml"]).each do |file|
next if skip_path?(file)

Open3.popen3('ruby -Ku -c') do |stdin, stdout, stderr|
stdin.puts(ERB.new(File.read(file), nil, '-').src)
stdin.close
if error = ((stderr.readline rescue false))
puts red_string(file) + error[1..-1].sub(/^[^:]*:\d+: /, '')
end
stdout.close rescue false
stderr.close rescue false
end
end
end

#desc 'Check syntax of .haml files'
task :haml do
haml = bin_path "haml"
Dir['**/*.haml'].each do |file|
next if skip_path?(file)
next if file.match("vendor/plugins/.*/generators/.*/templates")

Open3.popen3("#{haml} -c #{file}") do |stdin, stdout, stderr|
if error = ((stderr.readline rescue false))
puts red_string(file) + error
end
stdin.close rescue false
stdout.close rescue false
stderr.close rescue false
end
end
end

#desc 'Check ruby syntax of .haml files'
task :haml_ruby do
Dir['**/*.haml'].each do |file|
next if skip_path?(file)
next if file.match("vendor/plugins/.*/generators/.*/templates")

Open3.popen3("ruby -Ku -c") do |stdin, stdout, stderr|
stdin.puts(Haml::Engine.new(File.read(file)).precompiled)
stdin.close
if error = ((stderr.readline rescue false))
puts red_string(file) + error.sub(/^[^:]*:\d+: /, '')
end
stdout.close rescue false
stderr.close rescue false
end
end
end

#desc 'Check syntax of .rb files'
task :ruby do
Dir['**/*.rb'].each do |file|
next if skip_path?(file)
next if file.match("vendor/plugins/.*/generators/.*/templates")

Open3.popen3("ruby -Ku -c #{file}") do |stdin, stdout, stderr|
if error = ((stderr.readline rescue false))
puts error
end
stdin.close rescue false
stdout.close rescue false
stderr.close rescue false
end
end
end

#desc 'Check syntax of .sass files'
task :sass do
sass = bin_path "haml", "sass"
Dir['**/*.sass'].each do |file|
next if skip_path?(file)
next if file.match("vendor/plugins/.*/generators/.*/templates")

Open3.popen3("#{sass} -c #{file}") do |stdin, stdout, stderr|
if error = ((stderr.readline rescue false))
puts error
end
stdin.close rescue false
stdout.close rescue false
stderr.close rescue false
end
end
end

#desc 'Check syntax of .yml files'
task :yaml do
Dir['**/*.yml'].each do |file|
next if skip_path?(file)

begin
YAML.load_file(file)
rescue => e
puts red_string(file) + "#{(e.message.match(/on line (\d+)/)[1] + ':') rescue nil} #{e.message}"
end
end
end

def bin_path gem_name, bin_name=nil
bin_name=gem_name if bin_name.nil?
[`bundle show #{gem_name}`.chomp!, 'bin', bin_name].join("/")
end

def skip_path?(file)
["tmp", "vendor/gems", "vendor/rails"].each do |dir|
return true if file.match(dir)
end
return false
end

def red_string(str)
"\e[31m" + str + "\e[0m: "
end
end


Wednesday, January 5, 2011

Running Diaspora, without ./script/server on Ubuntu

I wanted to free my terminal from the plethora of Diaspora* foreground daemons... I also wanted to make sure that these alpha daemons could be restarted, once they inevitably crashed. I tried using an older version of an Ubuntu init script.

The original version followed older init practices, and avoided upstart altogether. This allowed me to skip script/server, but didn't restart services. As such, I decided to yank the core team's daemontools implementation. Core functionality was there, using this approach, but websocket didn't quite work (no pushes to clients) and I noticed numerous complaints, running ps axuw|grep readproc. No amount of fiddling yielded usable/stable results...

Finally, I decided to change my service names, prefixing each name with a number, similar to init and then instituting requirements. It is redundant, but the numbering was a convenient mnemonic ... The order of execution mimics the order script/server.

Install instructions, a version of my work, and a handy script for controlling daemontools services can be found at github.

I completed work on this and two days later (one day later?) leamas completed a wholesale rewrite of the Ubuntu package installer. It seems to have tighter integration with Ubuntu's edicts and expectations...