gems

爱死gems了

很多年前爱上java的时候别人问我java有什么好,我说标准库比较丰富,网络,多线程,数据库都是内置的。当时觉得java比c/c++好用多了。而且觉得java就是最好的语言。

工作以后重心逐渐转到了matlab,感觉更好。很大的一个好处就是类库很全,特别是科学计算方面,要什么有什么。

最近几年陆陆续续用ruby,还有rails。标准类库也很丰富。但是最大的好处是安装第三方类库super easy。只要个gem install。有了bundler和rvm世界就更清爽了。而且感觉第三方类库相当丰富。整个community非常活跃,而且前卫。最近搞个网站,自己提出的公司项目。内容方面早就想好了。但是我的弱点是没有前端的经验,比如ui。另外,一直也没有时间试过用户管理。看过rails tutorial,但总觉得很复杂,得安静的好好花个一天才能把整个东西搭好。而一天的时间是没有的。老板可不希望看到我花整天整天的时间搞pet projects。我每天只能在下班前一个小时到半个小时花点儿时间,边学习边搞。好吧。感谢主。这两个问题在rails里面只要装个gem就只需要十几分钟搞定。酷的令人发指。ui,可以用twitter bootstrap。用户管理,登录,注册什么的,用devise。就像傻瓜相机一样。要拍照么?按一下键就好了。要弄个带用户的网站么?用rails+bootstrap+devise。三分钟把网站搭好。

以前喜欢java的时候觉得java已经到头了。现在用ruby和rails,感觉java就是个笨重的大卡车。就像当年站在java上看c++ ,或者,是看汇编。

Advertisements

heroku sinatra rmagick

gemfile:

source 'http://rubygems.org'
gem 'sinatra'
gem "rmagick", "2.12.0", :require => 'RMagick'

hello.rb:

require 'sinatra'
require 'RMagick'
include Magick

get '/' do
  content_type 'image/png'
  img = Magick::Image.read('logo:')[0]
  img.format = 'png'
  img.to_blob
end

bundle, error happens

sudo apt-get install libmagickwand-dev

bundle

 

beaglebone audio kworker noise solution

solution is here

I posted a issue here in February and some guy suggested the solution: i.e. turn on CONFIG_MUSB_PIO_ONLY=Y

don’t have time to try this until yesterday

the new problem: how to compile a kernel for beaglebone and install it?

solution: follow instructions http://elinux.org/BeagleBoardUbuntu#Demo_Image

git clone git://github.com/RobertCNelson/linux-dev.git
cd linux-dev
git checkout origin/am33x-v3.2 -b am33x-v3.2
./build_kernel.sh

then error happened, through README, we should first

cd ~/
git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

Then update “LINUX_GIT” to “LINUX_GIT=~/linux-stable/” in system.sh to point to your new local kernel source copy.

note the directory is not necessary to be the home ~. the linux kernel is big.

also remember uncomment the cross compiler settings, in system.sh

during compiling, menuconfig will pop out, now we need to turn on CONFIG_MUSB_PIO_ONLY. don’t remember the detailed path, something like Drivers ->… -> USB -> …  turn off DMA

after compiling, something will generated in ./deploy and now it’s ready to install the new kernel

insert sd card

run “./tools/load_uImage.sh”

error happened again. need to modify system.sh again:

uncomment ZRELADDR=0x80008000

run sudo fdisk -l to see the device of sd card, on my machine, it’s /dev/sdd

uncomment the MMC line and set MMC=/dev/sdd

run “./tools/load_uImage.sh” again, type yes if ask to confirm /dev/sdd

done.

take out micro sd and insert into beaglebone, now no high cpu usage kworker shown up if I run arecord | aplay stuff.

tested my own algorithm, it takes less than 50% cpu. sound is pretty smooth.

json_decode php 5.1

solution here:

1. copy/download the contents http://mike.teczno.com/JSON/JSON.phps

2. add the following lines:

<?php
if ( !function_exists(‘json_decode’) ){ //for php < 5.2
function json_decode($content, $assoc=false){
require_once(‘JSON.phps’);
if ($assoc){ $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE); }
else { $json = new Services_JSON; }
return $json->decode($content);
}
}
?>

setup a new environment of rvm, ruby, github and heroku under mint/ubuntu

//instructions change quickly, should always check tool website first and follow instructions spit out by the tools

== rvm and ruby
sudo apt-get install curl
curl -L get.rvm.io | bash -s stable
source ~/.rvm/scripts/rvm
rvm requirements
sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion
rvm install 1.9.3
gem install bundler

== github

cd ~/.ssh
ssh-keygen -t rsa -C “xxx@gmail.com”
gedit id_rsa.pub and add the key to github

== heroku
wget -qO- https://toolbelt.heroku.com/install.sh | sh
heroku login
heroku keys:add ~/.ssh/id_rsa.pub

rvm ruby gem install zlib error

ERROR: Loading command: install (LoadError)

cannot load such file — zlib

ERROR: While executing gem … (NameError)

uninitialized constant Gem::Commands::InstallCommand

reason: didn’t install required packages for ruby before rvm install ruby-xxx

solution adapted from here:

install required stuff like: sudo apt-get install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake libtool bison subversion

rvm remove ruby-x.x.x

rvm install ruby-x.x.x

新电脑?

这些天又有买一台高性能台式机的想法,16G内存,6核CPU,大概700~800块钱,不包括显示器。

主要原因是有些事情得用Linux,又不想给笔记本重装系统。用虚拟机吧,又贼慢。

但是在办公室的一台高性能电脑上,同时运行三个虚拟机都不慢。

不过非常不喜欢台式机,沉,占地方,噪音大,耗电大,最主要是不能随便移动。而我大部分时间都在客厅,跟老婆孩子在一起。

而且,实在不想买一台windows PC了。想换个Mac。

但是高性能Mac贼贵。想买air吧,也不知道开发程序方不方便。

昨天搞了个linux usb stick,装的linux mint。回去用老婆的老ibm笔记本试了一下,还真可以用,速度还不慢,界面还挺酷的。

好吧,就这么解决了。买个16G的u盘,装个persistent linux mint。这样拿到办公室还可以用台式机的硬件。

然后就等着买个iPad。

然后就是mac air。