Formatting DateTime in Rails

  • There are some useful params with Time#to_s
[14] pry(main)> time = u.created_at
=> Thu, 13 Nov 2014 14:21:01 UTC +00:00
[15] pry(main)> time.to_s(:long)
=> "November 13, 2014 14:21"
[16] pry(main)> time.to_s(:short)
=> "13 Nov 14:21"
[17] pry(main)> time.to_s(:default)
=> "2014-11-13 14:21:01 UTC"
[18] pry(main)> time.to_s(:db) #this will put it into the UTC time zone
=> "2014-11-13 14:21:01"
[19] pry(main)> time.to_s(:number)
=> "20141113142101"
[20] pry(main)> time.to_s(:long_ordinal)
=> "November 13th, 2014 14:21"
[21] pry(main)> time.to_s(:rfc822)
=> "Thu, 13 Nov 2014 14:21:01 +0000"
> time.utc.strftime('%FT%TZ')
=> "2016-03-18T18:33:09Z"
  • And for custom formatting, there is a very good post for it:
    https://hackhands.com/format-datetime-ruby/

Burn bootable ISO file into U-Disk in Mac OSX Yosemite

1 Open DiskUtil and format your u-disk with FAT format

2 Open Terminal, run diskutil list, you’ll get following output:

$diskutil list
/dev/disk0
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:      GUID_partition_scheme                        *500.3 GB   disk0
   1:                        EFI EFI                     209.7 MB   disk0s1
   2:       Microsoft Basic Data BOOTCAMP                100.0 GB   disk0s2
   3:       Microsoft Basic Data DATA                    250.3 GB   disk0s3
   4:                  Apple_HFS Mac                     149.0 GB   disk0s4
   5:                 Apple_Boot Recovery HD             650.0 MB   disk0s5
/dev/disk1
   #:                       TYPE NAME                    SIZE       IDENTIFIER
   0:     FDisk_partition_scheme                        *7.7 GB     disk1
   1:                 DOS_FAT_32 UNTITLED 1              7.7 GB     disk1s1

So remember the disk position of your u-disk, as in the example above, it’s /dev/disk1

3 Run following command in terminal:

sudo dd if=/Users/unieagle/Downloads/Windows10_TechnicalPreview_x64_ZH-CN_9926.iso of=/dev/disk1 bs=8192

You can drag your iso file into terminal after input sudo dd if=, it will fill the path of iso file for u automatically.

4 Wait about 40′, and u will get the info in terminal:

532494+1 records in
532494+1 records out
4362192896 bytes transferred in 3034.644407 secs (1437464 bytes/sec)

This indicate success. So enjoy your bootable u-disk from ISO file.

Note
If you got error message dd: /dev/disk1: Resource busy in the step 3, try to UNMount your udisk partition in DiskUtil and redo step 3.

Reference
http://www.macx.cn/thread-2078747-1-1.html

[Solved] Install Nokogiri on Yosemite with Ruby 2.1.3

Updated to Yosemite and got the following problem while run bundle install with ruby 2.1.3:

An error occurred while installing nokogiri (1.6.1), and Bundler cannot continue.
Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling.

The solution is:

gem install nokogiri -v '1.6.1' -- --use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2
Fetching: nokogiri-1.6.1.gem (100%)
Building native extensions with: '--use-system-libraries=true --with-xml2-include=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/usr/include/libxml2'
This could take a while...
Successfully installed nokogiri-1.6.1
Parsing documentation for nokogiri-1.6.1
Installing ri documentation for nokogiri-1.6.1
Done installing documentation for nokogiri after 3 seconds
1 gem installed