鋼の鍊魔術師

嵌入 FreeBSD 的心,修的是魔道還是正道?

Fork me on GitHub

Fix Cydia Crash the Hard Way

After I upgrade my iphone to 5.0.1, I cannot use it easily as usual.

Today I’ve tried some ways to fix it and I finally let cydia could install apps now. I bought PhoneDisk and mount my iphone, then just saw what file caused Cydia crashed. And I found if I delete /var/lib/apt/lists/apt.saurik.com_dists_ios_675.00_main_binary-iphoneos-arm_Packages then Cydia would not crash. So I just edit apt.saurik.com_dists_ios_675.00_main_binary-iphoneos-arm_Packages and left openssh and its deps packages only and use Cydia to install it. Then:

1
2
3
4
5
$ ssh (to my iphone)
$ fetch debs from http://apt.saurik.com/cydia/debs/ and send to iphone (I use `PhoneDisk` to mount iphone)
$ dpkg -r cydia-lproj cydia ; dpkg -i cydia-lproj_1.1.0_iphoneos-arm.deb cydia_1.1.1_iphoneos-arm.deb # yes, it still crashes eachtime
$ dpkg -i apt_1\:0-23_iphoneos-arm.deb gettext_0.17-6_iphoneos-arm.deb libsigc++_2.2.3-4_iphoneos-arm.deb apt7-ssl_0.7.25.3-3_iphoneos-arm.deb curl_7.19.4-6_iphoneos-arm.deb berkeleydb_4.6.21-4_iphoneos-arm.deb 
$ apt-get update; apt-get dist-upgrade

But Cydia would still crash when you using search or add source, so I just keep searching in Cydia All Packages myself or I just ssh access to it and use apt-get install <packages>.

That’s it.

I got SBSettings back and also some useful tools.

Using Email to Convert PDF to AZW and Sync to Your Kindle Device

I’ve tried some methods to use amazon service to convert my PDF files to AZW and sync to my kindle device.

The right way is as follows.

Just send your PDF file as attachment to your kindle account (@kindle.com or @free.kindle.com) and the Email Subject must be convert or convert. then it will be converted to AZW format.

Then, just wait 1 or 2 minutes and check your kindle device, you will see new file syncing to it.

Update:

  1. The file size of each attached personal document should be less than 50MB (before compression in a ZIP file)

  2. The email submitted should not contain more than 25 attached personal documents

And the Amazon Kindle Support team says:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
The Kindle Personal Document Service can convert and deliver the following types of documents:
Microsoft Word (.doc, .docx)
Rich Text Format (.rtf)
HTML (.htm, .html) 
Text (.txt) documents
Archived documents (zip , x-zip) and compressed archived documents
Mobi book

Images that are of type JPEGs (.jpg), GIFs (.gif), Bitmaps (.bmp), and PNG images (.png).
Adobe PDF (.pdf) documents are delivered without conversion to Kindle DX, Second Generation and Latest Generation Kindles.

Adobe PDF (.pdf) can be converted to Kindle format and delivered on an experimental basis.

If the document that failed belonged to one of the above document types, please ensure the document is not password protected or encrypted. Note that the Latest Generation Kindles support password protected PDFs.

Helpful tips for personal document attachments:
The file size of each attached personal document should be less than 50MB (before compression in a ZIP file)
The email submitted should not contain more than 25 attached personal documents

You can learn more about transferring personal documents to your Kindle in our help pages:
http://www.amazon.com/kindlepersonaldocuments/

Symfony2 Nginx Virtualhost Config

Symfony2 nginx virtualhost settings:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
server {
    listen       80;
    server_name symfony2.dev;
    root    /path/to/your/symfony2/web/;

    index app_dev.php;

    location ~ /\.git {
        deny  all;
    }

    location / {
        if (!-e $request_filename) {  
            rewrite ^/(.*)$ /app_dev.php?q=$1 last;  
        } 
    }

    location ~ \.php$ {
        fastcgi_pass    unix:/tmp/php-fpm.sock;
        fastcgi_index   app_dev.php;
        include         fastcgi_params_production;
    }
}

And the fastcgi_params_production is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

refer: http://sebwebdev.posterous.com/51840968

Symfony2 Initial Project Script

This script use recommanded steps on symfony2 official site, just save it as symfony2_init.sh and chmod +x symfony2_init.sh, then you could start using ./symfony2_init.sh <project_name> to built each of your symfony2 project.

Note: you must change SYMFONY_VERSION if you want to use new version of symfony2.

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
31
32
33
34
35
36
37
38
#!/bin/sh
if ! test $# -eq 1
then
    echo 'Usage: ./symfony2_init.sh <project_name>'
    exit
fi

PROJECT_NAME=$1
SYMFONY_VERSION=2.0.7

# 1. fetch symfony
curl http://symfony.com/get/Symfony_Standard_$SYMFONY_VERSION.tgz -o symfony.tgz

# 2. extract and rename
mkdir $PROJECT_NAME
tar xvf symfony.tgz -C $PROJECT_NAME
cd $PROJECT_NAME
mv Symfony/* .
rmdir Symfony

# 3. add .gitignore
echo '/web/bundles/
/app/bootstrap*
/app/cache/*
/app/logs/*
/vendor/
/app/config/parameters.ini' > .gitignore

# 4. keep default setting samples
cp app/config/parameters.ini app/config/parameters.ini.dist

# 5. git init
git init
git add .
git ci -m 'Initial commit'

# 6. download vendor libraries
php bin/vendors install

refer: http://symfony.com/doc/current/cookbook/workflow/new_project_git.html

Change RVM to Rbenv

I use RVM for days but I don’t really like it. Someday I found there is a replacement called rbenv and I just give it a try.

It’s really simple with the following steps.

  • Clean your RVM environment:
1
$ rm -rf ~/.rvm
  • Please remove the following line from your Zsh or Bash environment. [[ -s "$HOME/.rvm/scripts/rvm" ]] && . "$HOME/.rvm/scripts/rvm" # Load RVM function

  • Quit your current terminal and open new one.

(Or just source ~/.zshrc or your refresh your bash settings at the same console.)

  • Install ruby-build:

(Because ruby-build has rbenv-install command)

1
$ cd; git clone git://github.com/sstephenson/ruby-build.git; cd ruby-build; ./install.sh
  • Intsall rbenv:

(You must change .zshrc to .bash_profile if you use bash. Also, bash has no rehash command, you must use rbenv rehash to rehash your shell environment)

1
2
3
4
5
6
7
8
$ git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(rbenv init -)"' >> ~/.zshrc
$ source ~/.zshrc
$ rbenv-install 1.9.2-p290
$ rehash
$ rbenv global 1.9.2-p290
$ gem install rails # just for test

refer and learn more rbenv commands:

  1. https://github.com/sstephenson/rbenv
  2. https://github.com/sstephenson/ruby-build