Latin vs UTF-8

Latin is a single-byte encoding.

So, non-Latin characters will break if you try to display them using a Latin encoding.

UTF-8 is potentially a 3 byte encoding and can encode a great deal more. 

Here’s a Unicode/UTF-8 character table:

http://www.utf8-chartable.de/unicode-utf8-table.pl?start=256&unicodeinhtml=dec

If you’re using MySQL, here’s how to ALTER the table to convert to the UTF-8 character set. Note there’s a slight subtlety here in that, because of the extra bytes used by UTF-8, unless you specify the column type it might roll over to the next larger column type size. E.g. for VARCHAR:

ALTER TABLE table_name MODIFY column_name VARCHAR(255) CHARACTER SET utf8;

http://dev.mysql.com/doc/refman/5.0/en/alter-table.html

Ruby: how the interpreter parses your code

I wasn’t sure exactly how the Ruby code I’d written was being interpreted.

For example, 

class TestClass

def initialize(x = 1)

@x = x

end

puts “inside the class”

end

a = TestClass.new(5)

puts “declared an instance”

Now, does this print “inside the class” or “declared an instance” first?

The answer is “inside the class”.

See also this post describing using Ripper to parse code:

http://www.rubyinside.com/using-ripper-to-see-how-ruby-is-parsing-your-code-5270.html 

Rails and Nginx: caching

Rails using Phusion Passenger is actually pretty quick after Passenger has first loaded.

And adding caching makes it pretty zippy.

Adding caching via Nginx makes it super fast. Cached pages bypass Rails and are served directly by Nginx which is incredibly fast.

Here’s a guide to using Rails with Nginx. Assuming you’ve got both installed, you need to:

1. add a flag to enable, e.g.:

config.action_controller.perform_caching = true

2. add caches_page

E.g. 

class ProductsController < ActionController

 

  caches_page :index

 

  def index

    @products = Products.all

  end

end

Rails guide on page caching:

http://guides.rubyonrails.org/caching_with_rails.html#page-caching

Nginx page caching:

http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_page_caching_support

Note that this assumes your cache will be in the public/ folder. For a non-standard page cache directory you’ll need to use mod_rewrite.

Passenger: 100% CPU

Possible reasons:

1. Piped logging seems to have caused a problem that’s been fixed in version 4.0.6 of Passenger

2. If you need to debug Passenger problems, use this option:

PassengerDebugLogFile <path to log>

and this to specify the log level:

PassengerLogLevel <integer – see guide>

(in Apache syntax)

passenger_log_level

(in Nginx syntax)

Apache Guide:

http://www.modrails.com/documentation/Users%20guide%20Apache.html#_logging_and_debugging_options

Nginx Guide:

http://www.modrails.com/documentation/Users%20guide%20Nginx.html#_passenger_debug_log_file_lt_filename_gt

Rails: Phusion Passenger

Passenger is an application server for Ruby (Rack) and Python (WSGI) apps.

Some notes on installing it:

https://www.phusionpassenger.com/download

Ignore the docs that suggest:

$ sudo gem install passenger

$ sudo passenger-install-apache2-module

Instead use:

gem install passenger

passenger-install-apache2-module

Then paste the LoadModule code it spits out at the end into your Apache conf file.

Test whether Passenger has installed by running:

curl -sI localhost | grep ^Server

and check for the “Phusion_Passenger” signature. E.g. 

Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Phusion_Passenger/4.0.5 mod_ssl/2.2.22 OpenSSL/0.9.8x

If you need to uninstall Passenger using sudo then:

$ sudo gem uninstall passenger

And a discussion on whether to use rvmsudo or not here:

https://groups.google.com/forum/#!topic/rubyversionmanager/9dnmAsTiHR4

In short, https://www.phusionpassenger.com/download

suggests using sudo but the rvm page suggests not:

https://rvm.io/integration/passenger

Note:

If you get a warning doing the passenger install apache2 module like this:

rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all

Warning: can not check /etc/sudoers for secure_path, falling back to call via /usr/bin/env, this breaks rules from /etc/sudoers. Run:

    export rvmsudo_secure_path=1

Then run:

    export rvmsudo_secure_path=1

and:

rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all

(remember to run rvm requirements afterwards)

On the Mac the Apache conf and restart commands go like this:

[~]$ sudo vim /etc/apache2/httpd.conf

[~]$ sudo apachectl restart

See also:

https://developer.apple.com/library/mac/#featuredarticles/PhusionRails/_index.html

and this very useful guide:

http://jasoncodes.com/posts/mac-os-rails-server

Rails: Phusion Passenger

Passenger is an application server for Ruby (Rack) and Python (WSGI) apps.

Some notes on installing it:

https://www.phusionpassenger.com/download

Ignore the docs that suggest:

$ sudo gem install passenger

$ sudo passenger-install-apache2-module

Instead use:

gem install passenger

should be sufficient and rvm.io suggests just running:

passenger-install-apache2-module

See also:

http://stackoverflow.com/questions/17245105/passenger-module-fails-to-install

and

http://stackoverflow.com/questions/17248660/installing-passenger-use-sudo-rvmsudo-or-nothing

Then, paste the LoadModule code it spits out at the end into your Apache conf file.

Test whether Passenger has installed by running:

curl -sI localhost | grep ^Server

and check for the “Phusion_Passenger” signature. E.g. 

Server: Apache/2.2.22 (Unix) DAV/2 PHP/5.3.15 with Suhosin-Patch Phusion_Passenger/4.0.5 mod_ssl/2.2.22 OpenSSL/0.9.8x

If you need to uninstall Passenger using sudo then:

$ sudo gem uninstall passenger

And a discussion on whether to use rvmsudo or not here:

https://groups.google.com/forum/#!topic/rubyversionmanager/9dnmAsTiHR4

In short, https://www.phusionpassenger.com/download

suggests using sudo but the rvm page suggests not:

https://rvm.io/integration/passenger

Note:

If you get a warning doing the passenger install apache2 module like this:

rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all

Warning: can not check /etc/sudoers for secure_path, falling back to call via /usr/bin/env, this breaks rules from /etc/sudoers. Run:

    export rvmsudo_secure_path=1

Then run:

    export rvmsudo_secure_path=1

and:

rvmsudo rvm get stable && rvm reload && rvmsudo rvm repair all

(remember to run rvm requirements afterwards)

On the Mac the Apache conf and restart commands go like this:

[~]$ sudo vim /etc/apache2/httpd.conf

[~]$ sudo apachectl restart

See also:

https://developer.apple.com/library/mac/#featuredarticles/PhusionRails/_index.html

Rails: clear cached page

Rails automatically enables caching on Production and disables it on Development.

1. To disable caching on Production, edit config/environments/production.rb and set:

config.action_controller.perform_caching = false

2. To perform Page Caching use the caches_page method, e.g.:

class ProductsController < ActionController

 

  caches_page :index

 

  def index

    @products = Products.all

  end

end

3. If you need to debug what’s going on use:

tail -f current/log/production.log 

4. These may also help

http://stackoverflow.com/questions/2847859/rails-cache-clearing

http://stackoverflow.com/questions/17245401/rails-caching-on-production

https://news.ycombinator.com/item?id=1185473

(which points to: http://brainspl.at/nginx.conf.txt)

5. Finally, if you’re using Passenger then you may need to tell it to restart. 

Check whether this works (i.e. your content refreshes after this):

touch tmp/restart.txt

If so, then update your deploy.rb file with:

namespace :deploy do

  task :restart do

    run “touch #{current_path}/tmp/restart.txt”

  end

end

Thanks to:

http://stackoverflow.com/questions/3948074/capistrano-nginx-passenger-restart-rails-app/3948197

http://guides.rubyonrails.org/caching_with_rails.html#page-caching 

WWDC 2013 101: Platforms State of the Union

Released:

iOS7

AirDrop

New UI

3 big ideas: Clarity, Deference (getting the chrome out of the way of the content), Depth (parallax, blurs, sophisticated animations) 

4 things to pay attention to: Content (shows through the bars) , Metrics (cells are going edge to edge), Buttons (using coloured text more than buttons, don’t have borders), Pickers (pops in inline with content)

Text Kit: complement to WebKit

Animations: dynamics, transitions (e.g. View Controller transitions), motion effects (UIMotionEffects – e.g. for parallax effect), UIKit Dynamics (physics engine)

Multitasking: new multitasking interface, background fetch and transfers; 

For more info read:

iOS7 Transition Guide 

OS X Mavericks

Battery Life – some major updates such as listing power hungry apps;

Centralized Memory Management – Low memory notifications, Purgeable memory, Compressed memory; 

Responsive Scrolling – rendered on the main thread in small tiles, automatic for OS X 10.8; 

App Nap – Timer Rate Limiting (i.e. apps perform CPU work together); 

Multi Monitors;

MapKit; 

Xcode 5.0

For iOS7 and OS X Mavericks.

Asset catalogs: naming convention of @2x etc is deprecated (more here: http://stackoverflow.com/questions/17052344/access-asset-catalog-programmatically); slice images in Xcode; 

Auto Layout workflow – set constraints and get immediate feedback in Xcode via the Assistant

Debug Gauges – also iCloud debugging; Quicklook for variables;

Testing Tools – Test Navigator (e.g. Unit Tests), can now run just one test or at class or bundle level. XCTest – not much on the internet about all this yet but an interesting article in Chinese here:

http://translate.google.com/translate?sl=auto&tl=en&js=n&prev=_t&hl=en&ie=UTF-8&u=http%3A%2F%2Fwww.cnblogs.com%2Fliufan9%2Farchive%2F2013%2F06%2F14%2F3135414.html&act=url

Source Control – Top Level source control menu (Checkout, commit, merge, see history)

Continuous Integration – merging many code updates from many developers and constantly integrating them into the code base. Bots – CI tasks that run on OS X Server (Xcode > Product > Create Bot).

Sprite Kit

Available for iOS and OS X.

Physics Engine; Particles; CIFilters; Video so Masking can be added inline over video

See the Adventure Game source code.

Game Controllers

Defining a standard software interface.

1. a hardware standard

2. a software interface