<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0">
  <title>mokhan.ca</title>
  <link rel="alternate" type="text/html" href="http://mokhan.ca/" />
  
  <id>http://mokhan.ca/</id>
  <updated>2013-05-29T22:01:17-06:00</updated>
  <subtitle>a journal about code and my experiments with truth, trust, and honesty</subtitle>
  <author>
    <name>mo khan</name>
    <uri>http://mokhan.ca</uri>
    <email>email@mokhan.ca</email>
  </author>
  
  <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/mokhan" /><feedburner:info uri="mokhan" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry>
    <title>layoffs</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/FMckj68Ncsk/layoffs.html" />
    <id>http://mokhan.ca/journal/2013/05/29/layoffs</id>
    <updated>2013-05-29T20:36:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;Today 5 people from my office were laid off. Another 2 people were laid
off about a month ago. That's 7 layoffs in the 4 months that I have been
here.&lt;/p&gt;

&lt;p&gt;This was the first time that I had worked somewhere where more then one
person was let go at a time. I have been fortunate in my career to never
have seen layoffs before. This shook me up a bit.&lt;/p&gt;

&lt;p&gt;I remember being a kid when my dad was laid off. It was not a fun time
for him or the rest of us in the family. He never really got back into
the same field of work, but I know he tried. I remember the look of
shame on his face when he took the job at Zellers trying to get people
to sign up for a Zellers card. Everyday he came home in his Zellers
uniform he just look defeated. From that point on I believe he started
living in the past. He would say things like "I should have taken a
computer class instead of another geophysics class" or "I should have
never sold that house" and "I should have done...". You get the drift.&lt;/p&gt;

&lt;p&gt;I think while my dad was in his prime he would never have guessed that
someday his skillset would no longer be needed. I think that hurt him.&lt;/p&gt;

&lt;p&gt;Living in the past, makes it very difficult to live in the now.&lt;/p&gt;

&lt;p&gt;Whether you are a full time employee, contractor, business owner, self
employed or whatever you are not guaranteed work.&lt;/p&gt;

&lt;p&gt;Today was a rude awakening for me. I, like my dad, started drifting into
the past. Unlike my dad, I am choosing to live in the now and look forward
to what the future may bring.&lt;/p&gt;

    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=FMckj68Ncsk:OZYoUNNABQE:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=FMckj68Ncsk:OZYoUNNABQE:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=FMckj68Ncsk:OZYoUNNABQE:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/FMckj68Ncsk" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//journal/2013/05/29/layoffs.html</feedburner:origLink></entry>
  
  <entry>
    <title>ios day three</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/EW_iTinLbqM/ios-day-three.html" />
    <id>http://mokhan.ca/ios/sait/2013/05/14/ios-day-three</id>
    <updated>2013-05-14T17:51:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;h2&gt;MVC (Model View Controller)&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Model means data.&lt;/li&gt;
&lt;li&gt;View means view or screen.&lt;/li&gt;
&lt;li&gt;Controller means controller.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Every view has a controller, but not every controller has a view. Some
special controllers, that we call &lt;strong&gt;controller of controllers&lt;/strong&gt; are used
in Xcode.&lt;/p&gt;

&lt;h2&gt;Connecting a view to a controller&lt;/h2&gt;

&lt;p&gt;Do some drag and drop stuff. Ctrl+click and drag UI elements to the
code editor (this seems like a good idea... sarcasm intended).&lt;/p&gt;

&lt;p&gt;IBOutlet is a keyword that allows teh view to see the code and connect
to it.&lt;/p&gt;

&lt;p&gt;IBAction has the same value as void. It is a keyword that allows the
button to see the code and connect to it.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;IBAction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;firstButton:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;sender&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Simulator Rotation&lt;/h2&gt;

&lt;p&gt;If you press Command+left or Command+right it will rotate the simulator.
You can turn this off by unchecking "Use Autolayout" in the File
Inspector for the .xib file.&lt;/p&gt;

&lt;p&gt;The view wont rotate when the phone is upside down. Apple doesn't want
you to be playing a game or using an app with the phone upside down.&lt;/p&gt;

&lt;h2&gt;Collections&lt;/h2&gt;

&lt;p&gt;Objective-C has several different types of collections.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;li&gt;Sets&lt;/li&gt;
&lt;li&gt;Dictionaries&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Collections can only contain references to objects.&lt;/p&gt;

&lt;h3&gt;NSArray&lt;/h3&gt;

&lt;p&gt;is immutable, which means it must be completely populated when it's
instantiated.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;NSArray&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;NSArray&lt;/span&gt; &lt;span class="n"&gt;alloc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nl"&gt;initWithObjects:&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;ruby&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;@&amp;quot;c&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;@&amp;quot;c#&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;nil&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;nil terminal is necessary. That is how the array will know what size it
will be.&lt;/p&gt;

&lt;p&gt;To store an integer into an array:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;NSArray&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;NSArray&lt;/span&gt; &lt;span class="n"&gt;alloc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nl"&gt;initWithObjects:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;NSNumber&lt;/span&gt;
  &lt;span class="nl"&gt;numberWithInt:&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]];&lt;/span&gt;
  &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;numbers&lt;/span&gt; &lt;span class="nl"&gt;objectAtIndex:&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;intValue&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;NSMutableArray&lt;/h3&gt;

&lt;p&gt;Is mutable, so you can push objects into it or pop object off of it.&lt;/p&gt;

&lt;h2&gt;Controls&lt;/h2&gt;

&lt;p&gt;Controls are how we input data into our application, and view the data
from our app.&lt;/p&gt;

&lt;h3&gt;Labels&lt;/h3&gt;

&lt;p&gt;The view is always controlled by the ViewController. It is the file
owner.&lt;/p&gt;

&lt;h3&gt;Buttons&lt;/h3&gt;

&lt;p&gt;Touch Up Inside: When you touch the button and lift your finger off the
button. Basically a click event.&lt;/p&gt;

&lt;h2&gt;44 - Magic Number&lt;/h2&gt;

&lt;p&gt;44x44 is the minimum area for when someone is tapping something.&lt;/p&gt;

    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=EW_iTinLbqM:3FSb6yKIDB8:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=EW_iTinLbqM:3FSb6yKIDB8:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=EW_iTinLbqM:3FSb6yKIDB8:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/EW_iTinLbqM" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//ios/sait/2013/05/14/ios-day-three.html</feedburner:origLink></entry>
  
  <entry>
    <title>cprg-190 day two</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/51P2KviJqL0/cprg-190.html" />
    <id>http://mokhan.ca/ios/sait/2013/05/09/cprg-190</id>
    <updated>2013-05-09T18:30:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;Starting with arithmetic expressions but I already read that last class.&lt;/p&gt;

&lt;p&gt;Everything inherits from NSObject.&lt;/p&gt;

&lt;h2&gt;Person.m&lt;/h2&gt;

&lt;p&gt;Define the implementation of the Person class.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;&lt;span class="cp"&gt;#import &amp;quot;Person.h&amp;quot;&lt;/span&gt;

&lt;span class="k"&gt;@implementation&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;

&lt;span class="k"&gt;@end&lt;/span&gt;
  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Person.h&lt;/h2&gt;

&lt;p&gt;Define the interface for Person.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;&lt;span class="cp"&gt;#import &amp;quot;Person.h&amp;quot;&lt;/span&gt;

&lt;span class="k"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; : &lt;span class="nc"&gt;NSObject&lt;/span&gt;

&lt;span class="k"&gt;@end&lt;/span&gt;
  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;strong vs weak references&lt;/h2&gt;

&lt;p&gt;Strong reference is like a dog on a leash.
The dog wants to run a way. strong is like the leash. As long as the
pointer is strong then the dog can't run away. With a weak reference
the dog can run away.&lt;/p&gt;

&lt;h2&gt;method invocation&lt;/h2&gt;

&lt;p&gt;Instead of calling it invoking a method or calling a function it is
described as "sending a message".&lt;/p&gt;

&lt;p&gt;To invoke a class method.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;To invoke an instance method.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="n"&gt;sayHi&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Documentation for NSObject#new&lt;/h2&gt;

&lt;p&gt;new
Allocates a new instance of the receiving class, sends it an init
message, and returns the initialized object.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;(id)new
Return Value
A new instance of the receiver.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;Discussion
This method is a combination of alloc and init. Like alloc, it
initializes the isa instance variable of the new object so it points to
the class data structure. It then invokes the init method to complete
the initialization process.&lt;/p&gt;

&lt;p&gt;You will never see people use "new". Instead they use alloc and init.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  
  &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;alloc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Properties&lt;/h2&gt;

&lt;p&gt;To get and set you can send messages to the object. To set a property
you need to prefix the message with "set".&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  
  &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="nl"&gt;setFirstName:&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;Mo&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="n"&gt;NSLog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;%@&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;dot syntax&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  
  &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;&amp;quot;Mo&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;NSLog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;%@&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Named Parameters&lt;/h2&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  
&lt;span class="k"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; : &lt;span class="nc"&gt;NSObject&lt;/span&gt;
&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;name:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;theName&lt;/span&gt; &lt;span class="nf"&gt;age:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;theAge&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@end&lt;/span&gt;

&lt;span class="k"&gt;@implementation&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;

&lt;span class="k"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nf"&gt;name:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;theName&lt;/span&gt; &lt;span class="nf"&gt;age:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nv"&gt;theAge&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;@end&lt;/span&gt;

&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;person&lt;/span&gt; &lt;span class="nl"&gt;name:&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;blah&amp;quot;&lt;/span&gt; &lt;span class="nl"&gt;age:&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=51P2KviJqL0:e7jRv43URMk:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=51P2KviJqL0:e7jRv43URMk:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=51P2KviJqL0:e7jRv43URMk:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/51P2KviJqL0" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//ios/sait/2013/05/09/cprg-190.html</feedburner:origLink></entry>
  
  <entry>
    <title>cprg-190 day one</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/rnrVpIMzqNs/cprg-190-day-one.html" />
    <id>http://mokhan.ca/ios/sait/2013/05/08/cprg-190-day-one</id>
    <updated>2013-05-08T09:22:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;instructor: kris hopkins
kris.hopkins@sait.ca&lt;/p&gt;

&lt;p&gt;register for university developer program.
access to all of the wwdc videos.
  * publish up to 100 hours of video.&lt;/p&gt;

&lt;p&gt;Acronym soup:
* OTA (over the air) download.&lt;/p&gt;

&lt;p&gt;xcodeproj - This is the xcode project.&lt;/p&gt;

&lt;p&gt;Why is there NS in front of log?
Objective C was created by the company NeXT. NeXT first introduced their
object-oriented operating system, called NeXTSTEP, in the late 80s. Many
of the classes you will see in Objective-C still have NS in front of
them as a reference to Next Step.&lt;/p&gt;

&lt;p&gt;Why is there a symbol @ in front of the string we are logging?
Objective-C is a strict superset of C. This means you can compile any C
code in an Objective-C project. In Objective-C we never use C Strings,
we always use object oriented strings, called NSStrings. The @ symbol is
a heads up to the compiler that what is coming next is an Objective-C
NSString and not a C string.&lt;/p&gt;

&lt;h2&gt;Objective-C Primitive Data Types&lt;/h2&gt;

&lt;p&gt;There are 5 primitive datatypes in Objective-C:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;int - integer&lt;/li&gt;
&lt;li&gt;float - floating point number&lt;/li&gt;
&lt;li&gt;double - double precision floating point number&lt;/li&gt;
&lt;li&gt;char - a single character&lt;/li&gt;
&lt;li&gt;BOOL - YES or NO&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;Everything else is a Class data type.&lt;/p&gt;

&lt;h2&gt;Objective-C Variables&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;variables are used to identify a value.&lt;/li&gt;
&lt;li&gt;variables are always strongly typed.&lt;/li&gt;
&lt;li&gt;every variable must be one data type only and must be declared.&lt;/li&gt;
&lt;/ul&gt;


&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;myInt&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="n"&gt;myInt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;myInt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;Format Specifiers&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;%d - int&lt;/li&gt;
&lt;li&gt;%f - float, double&lt;/li&gt;
&lt;li&gt;%c - char&lt;/li&gt;
&lt;li&gt;&lt;p&gt;%@ - any object e.g NSString&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Note that when outputting the value for a BOOL data type use %d to get
the int value. 0 for NO and 1 for YES&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;NSString&lt;/h3&gt;

&lt;p&gt;All objects use pointser. A pointer is a variable that holds a reference
to an address in memory instead of an actual value. The address in
memory holds the actual value that has been assigned.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;myString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;@&amp;quot;Hello&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="n"&gt;NSLog&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;What the what? %@&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;myString&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;Arithmetic Operators&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;"+" Add&lt;/li&gt;
&lt;li&gt;"-" Subtract&lt;/li&gt;
&lt;li&gt;"*" Multiply&lt;/li&gt;
&lt;li&gt;"/" divide&lt;/li&gt;
&lt;li&gt;"%" remainder (modulus)&lt;/li&gt;
&lt;li&gt;"=" assignment&lt;/li&gt;
&lt;li&gt;"+=" add R to L, then assign to L&lt;/li&gt;
&lt;li&gt;"-=" subtract R from L, then assign to L&lt;/li&gt;
&lt;li&gt;"*=" multiply L by R, then assign to L&lt;/li&gt;
&lt;li&gt;"/=" divide R into L, then assign result to L&lt;/li&gt;
&lt;li&gt;"%=" L mod B, then assign to L&lt;/li&gt;
&lt;li&gt;"++" add 1&lt;/li&gt;
&lt;li&gt;"--" subtract&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Relational Operators&lt;/h3&gt;

&lt;p&gt;Work same way they do in other C-based languages.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"==" equal to&lt;/li&gt;
&lt;li&gt;"!=" not equal to&lt;/li&gt;
&lt;li&gt;"&amp;lt;" less than&lt;/li&gt;
&lt;li&gt;"&amp;lt;=" less than or equal to&lt;/li&gt;
&lt;li&gt;"&gt;" greater than&lt;/li&gt;
&lt;li&gt;"&gt;=" greater than or equal to&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Logical Operators&lt;/h3&gt;

&lt;p&gt;All logical operators work exactly the same way they do in other C-based
languages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;"&amp;amp;&amp;amp;" and&lt;/li&gt;
&lt;li&gt;"||" or&lt;/li&gt;
&lt;li&gt;"!" not&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;Custom classes&lt;/h3&gt;

&lt;p&gt;NSObject is the top level class and parent class of all other classes in
Objective-C.&lt;/p&gt;

&lt;p&gt;Objective-C classes contain two files. The first is the interface file,
identified by the .h suffix. This can also be called the "header" file
(h = header). The second is the implementation file, identified by a .m
suffix.&lt;/p&gt;

&lt;p&gt;The interface file contains a declaration of the elements of a class
that other classes can see. The implementation file contains all the
actual content for the class.&lt;/p&gt;

&lt;p&gt;All of the declarations inside an interface file are contains within the
@interface and @end keywords.&lt;/p&gt;

&lt;p&gt;All of the content inside an implementation file is contained within the
@implementation and @end keywords.&lt;/p&gt;

&lt;h4&gt;Interface&lt;/h4&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;&lt;span class="lineno"&gt;1&lt;/span&gt; &lt;span class="cp"&gt;  #import &amp;lt;Foundation/Foundation.h&amp;gt;&lt;/span&gt;
&lt;span class="lineno"&gt;2&lt;/span&gt;   &lt;span class="k"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt; : &lt;span class="nc"&gt;NSObject&lt;/span&gt;
&lt;span class="lineno"&gt;3&lt;/span&gt;   &lt;span class="k"&gt;@end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Preprocessor statement. Imports the Foundation framework so we have
access to the build Objective-C classes such as NSObject.&lt;/li&gt;
&lt;li&gt;Shows that this is an interface for Person.&lt;/li&gt;
&lt;li&gt;Closes the interface section of the file.&lt;/li&gt;
&lt;/ol&gt;


&lt;h4&gt;Implementation&lt;/h4&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;&lt;span class="lineno"&gt;1&lt;/span&gt; &lt;span class="cp"&gt;#import &amp;quot;Person.h&amp;quot;&lt;/span&gt;
&lt;span class="lineno"&gt;2&lt;/span&gt; &lt;span class="k"&gt;@implementation&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;
&lt;span class="lineno"&gt;3&lt;/span&gt; &lt;span class="k"&gt;@end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ol&gt;
&lt;li&gt;Import our header file so our implementation file can see it.&lt;/li&gt;
&lt;li&gt;begin implementation section of the file, and states the name of the classes.&lt;/li&gt;
&lt;li&gt;close the implementation.&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;@property keyword tells the compiler that we want to create a property.
strong and nonatomic keywords have to do with memory management and
we'll talk about them later.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;newPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;new&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Create a new instance of Person. This is like new Person() in other
languages. Instead of "calling a method" we are "sending a message".&lt;/p&gt;

&lt;p&gt;Sending the new message to the Person class will work, but you'll rarely
see it this way. It is much more common to see the instantiation of the
object like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;newPerson&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;Person&lt;/span&gt; &lt;span class="n"&gt;alloc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;init&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This breaks the new message into two parts. First we allocate memory for
our object (alloc), then we initialize it by calling the object's
initialization message (init).&lt;/p&gt;

&lt;p&gt;Many objective c classes have many different init messages that do
different things and pass in different arguments.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;newString&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[[&lt;/span&gt;&lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="n"&gt;alloc&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="nl"&gt;initWithFormat:&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;%@&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;@&amp;quot;my text&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Here is how you set and get our firstName property:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newPerson&lt;/span&gt; &lt;span class="nl"&gt;setFirstName:&lt;/span&gt;&lt;span class="s"&gt;@&amp;quot;Mo&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="n"&gt;newPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;@&amp;quot;Mo&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newPerson&lt;/span&gt; &lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
  &lt;span class="n"&gt;newPerson&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;firstName&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h3&gt;Methods (Messages)&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;doSomething&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="nl"&gt;doSomething:&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="n"&gt;firstThing&lt;/span&gt;
  &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;(+) class method&lt;/li&gt;
&lt;li&gt;(-) instance method&lt;/li&gt;
&lt;li&gt;&lt;p&gt;(void) return type&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A colon is required if there is at least one argument.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;The data type must be stated.&lt;/li&gt;
&lt;li&gt;We assign a name to each argument.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;If you want to be able to call your method from other classes, we need
to declare it in our interface (header) file:&lt;/p&gt;

&lt;h3&gt;Public and Private&lt;/h3&gt;

&lt;p&gt;Any property declared in the .h file is public. To make it private, put
it in an @interface block above the @implementation block in the .m
file, like this:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="objc"&gt;  &lt;span class="k"&gt;@interface&lt;/span&gt; &lt;span class="nc"&gt;Person&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="k"&gt;@property&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;strong&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;nonatomic&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;NSString&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;myPrivateString&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;@end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Any method declared in the .h file is public. To make a method private,
simple do not declare it in the .h file.&lt;/p&gt;

&lt;h3&gt;Strong/Weak References&lt;/h3&gt;

&lt;p&gt;A &lt;em&gt;strong&lt;/em&gt; reference to an object is one where the memory is reserved (and
the object stays alive) until we don't need it any more. This is the
default.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;weak&lt;/em&gt; reference to an object is one where the memory is reserved only
until all other strong pointers stop pointing to it strongly.&lt;/p&gt;

&lt;p&gt;We will almost always use a strong reference.&lt;/p&gt;

    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=rnrVpIMzqNs:iPqBLo-aqHA:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=rnrVpIMzqNs:iPqBLo-aqHA:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=rnrVpIMzqNs:iPqBLo-aqHA:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/rnrVpIMzqNs" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//ios/sait/2013/05/08/cprg-190-day-one.html</feedburner:origLink></entry>
  
  <entry>
    <title>CORS</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/tXT4lc6l9B8/cors.html" />
    <id>http://mokhan.ca/devops/2013/05/07/cors</id>
    <updated>2013-05-07T15:49:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;Cross-Origin Resource Sharing is a way for web applications that are hosted at one domain to access resources hosted in a different domain.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;If http://blah.com/ wants to use a webfont that is served up
through http://blah.cloudfront.net then an Access-Control-Allow-Origin
header needs to be returned with the resource with a value of
http://blah.com/. If not, Firefox will not load the web font.
Chrome and Safari don't seem to care.
This is actually trickier than it sounds.&lt;/p&gt;

&lt;p&gt;On a site we have been working on recently, we host our pre-compiled assets as well as any digital
uploads in an AWS S3 bucket. We use CloudFront with a distribution that
points to that bucket to distribute the static asssets. In order to get
the proper Access-Control-Allow-Origin header to be returned you must
setup some CORS rules on your S3 bucket.&lt;/p&gt;

&lt;h2&gt;CORS Configuration&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Log in to the AWS console.&lt;/li&gt;
&lt;li&gt;Navigate to the S3 dashboard.&lt;/li&gt;
&lt;li&gt;Choose your S3 bucket.&lt;/li&gt;
&lt;li&gt;Click on Properties.&lt;/li&gt;
&lt;li&gt;Choose the Permissions section.&lt;/li&gt;
&lt;li&gt;Click on "Edit CORS Configuration"&lt;/li&gt;
&lt;li&gt;Enter the following rules.&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="xml"&gt;&lt;span class="cp"&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;CORSConfiguration&lt;/span&gt; &lt;span class="na"&gt;xmlns=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;http://s3.amazonaws.com/doc/2006-03-01/&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;CORSRule&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;AllowedOrigin&amp;gt;&lt;/span&gt;*&lt;span class="nt"&gt;&amp;lt;/AllowedOrigin&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;AllowedMethod&amp;gt;&lt;/span&gt;GET&lt;span class="nt"&gt;&amp;lt;/AllowedMethod&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;MaxAgeSeconds&amp;gt;&lt;/span&gt;3000&lt;span class="nt"&gt;&amp;lt;/MaxAgeSeconds&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;AllowedHeader&amp;gt;&lt;/span&gt;Content-*&lt;span class="nt"&gt;&amp;lt;/AllowedHeader&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;AllowedHeader&amp;gt;&lt;/span&gt;Host&lt;span class="nt"&gt;&amp;lt;/AllowedHeader&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/CORSRule&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/CORSConfiguration&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;The AWS documentation suggests that you can upload a "cors" file to the
root of your bucket to configure rules, but I could not get this to
work.&lt;/p&gt;

&lt;p&gt;You can test your configuration using curl.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="text"&gt;$ curl -i -H &amp;quot;Origin: https://blah.com&amp;quot; -svk -o /dev/null https://blah.cloudfront.net/assets/font.eot
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;If it works you in the response you should see:&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="text"&gt;  Access-Control-Allow-Origin: http://blah.com
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;But it's not over. If the first request to the cloudfront resource is
for an http request then cloudfront will cache the response header as
http. If the next request is for the same resource using https, then you
will get the same cached http header back. This will cause Firefox to
not load your webfont.&lt;/p&gt;

&lt;p&gt;If you choose to hit your s3 bucket directly this is not an issue as
headers are not cached. I have found that serving the font using https
directly from the s3 bucket seems to be the easiest solution so far.&lt;/p&gt;

&lt;h3&gt;links&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html"&gt;aws documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=tXT4lc6l9B8:FX0UAGX2unQ:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=tXT4lc6l9B8:FX0UAGX2unQ:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=tXT4lc6l9B8:FX0UAGX2unQ:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/tXT4lc6l9B8" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//devops/2013/05/07/cors.html</feedburner:origLink></entry>
  
  <entry>
    <title>cloudfront</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/MG1AX0uwR94/cloudfront.html" />
    <id>http://mokhan.ca/devops/2013/05/01/cloudfront</id>
    <updated>2013-05-01T09:46:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;CloudFront is a web service that speeds up distribution of your content.
It delivers that content through a worldwide network of servers. When
someone requests conten from CloudFront they are routed to the closed
edge server to them to retrieve the content.&lt;/p&gt;

&lt;p&gt;The number of networks and the distance that the request has to travel
will have a significant impact on the performance, reliability, and
availability of the asset.&lt;/p&gt;

&lt;h2&gt;Origin Servers&lt;/h2&gt;

&lt;p&gt;An origin server is the location where you store the original content.&lt;br/&gt;
This can be an EC2 instance, an S3 bucket or your own http server.&lt;/p&gt;

&lt;p&gt;CloudFront will serve cached copies of your assets when available on the
edge server. Otherwise for the first request to an edge server
CloudFront will make a request to your origin server to cache the asset.&lt;/p&gt;

&lt;p&gt;Amazon CloudFront helps improve performance of your website by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;cache static content at edge locations. this means (css, js, images)
are served by the location closest to the server to reduce latency and
improve performance.&lt;/li&gt;
&lt;li&gt;proxies requests for dynamic content back to your origin running in an
AWS region.&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;You can use a CloudFront to deliver your entire website, including both
static and dynamic content. You can control multiple origin servers and
caching properties for different urls on your webiste.&lt;/p&gt;

&lt;p&gt;Good choice for when you want to distribute updates or other downloadable software to end users.
It also offers lower prices than Amazon S3 at higher usage tiers.&lt;/p&gt;

&lt;p&gt;This is a great option for delivering media files.
Lower data transfer prices and higher data transfer speeds.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Streaming media: Using Real Time Messaging Protocol (RTMP) you can
stream from assets stored in S3 buckets.&lt;/li&gt;
&lt;li&gt;Progressive download: You can drop media into S3 then configure cloudfront for progressive download.&lt;/li&gt;
&lt;li&gt;live events: sounds like you can deliver live streaming stuff.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Distribution&lt;/h2&gt;

&lt;p&gt;After choosing your origin server you can create a distribution. A
distribution tells cloudfront where your files are. cloudfront will give
you a unique domain name that you can use to reference your files.&lt;/p&gt;

&lt;p&gt;E.g. if your origin is an S3 bucket
http://mybucket.s3.amazonaws.com/images/image.jpg
you would change your links to point to
http://mybucket.cloudfront.net/images/image.jpg&lt;/p&gt;

&lt;p&gt;You can also configure a CNAME so that you can serve the assets right
from your own domain.&lt;/p&gt;

&lt;p&gt;There are 2 types of distributions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download distribution: deliver content via http or https.&lt;/li&gt;
&lt;li&gt;Streaming distribution: delivers content via RTMP.&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;Expiration&lt;/h2&gt;

&lt;p&gt;File expire after being in an edge location for 24 hours. After
expiration, the next request for that content will be forwarded to your
origin.&lt;/p&gt;

&lt;h2&gt;Steps&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Choose origin server.&lt;/li&gt;
&lt;li&gt;Create a distribution.&lt;/li&gt;
&lt;li&gt;Update your site to point asset urls to the cloudfront domain.&lt;/li&gt;
&lt;li&gt;ship it?&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;CloudFront vs Amazon S3&lt;/h2&gt;

&lt;p&gt;S3 is designed for long term durable storage. CloudFront is designed to
distribute your popular content with low latency. It is not durable.
CloudFront can be a more cost-effective way to deliver popular assets to
end users.&lt;/p&gt;

&lt;h3&gt;links&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://aws.amazon.com/cloudfront/"&gt;cloudfront sales page&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=MG1AX0uwR94:40QgrANCObg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=MG1AX0uwR94:40QgrANCObg:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=MG1AX0uwR94:40QgrANCObg:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/MG1AX0uwR94" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//devops/2013/05/01/cloudfront.html</feedburner:origLink></entry>
  
  <entry>
    <title>load averages</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/rr4Za44ohF8/load-averages.html" />
    <id>http://mokhan.ca/devops/2013/04/30/load-averages</id>
    <updated>2013-04-30T13:39:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;load averages are the 3 numbers shown with the "uptime" and "top" commands.&lt;/p&gt;

&lt;p&gt;load averages: 1.51 1.30 1.24&lt;/p&gt;

&lt;blockquote&gt;&lt;p&gt;run-queue-length: the sum of the number of processes that are currently
running plus the number that are waiting (queued) to run.&lt;/p&gt;&lt;/blockquote&gt;

&lt;p&gt;You want your CPU load to stay below 1.00. You are ok if you get some
temporary spikes above 1.00. When you are consistently above 1.00, you
need to worry.&lt;/p&gt;

&lt;p&gt;Many sysadmins will draw a line at 0.70.&lt;/p&gt;

&lt;h3&gt;Rules for a single core.&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;blockquote&gt;&lt;p&gt;0.70: time to investigate before things get worse.&lt;/p&gt;&lt;/blockquote&gt;&lt;/li&gt;
&lt;li&gt;&lt;blockquote&gt;&lt;p&gt;1.00: fix it now, or you will be up in the middle of the night.&lt;/p&gt;&lt;/blockquote&gt;&lt;/li&gt;
&lt;li&gt;&lt;blockquote&gt;&lt;p&gt;5.00: you are in serious trouble.&lt;/p&gt;&lt;/blockquote&gt;&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The load is relative to the number of processor cores available.
100% utilization mark is 1.00 on a single core, 2.00 on a dual-core,
4.00 on a quad core, etc.&lt;/p&gt;

&lt;h3&gt;Rules of Thumb&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;number of cores = max load&lt;/li&gt;
&lt;li&gt;cores is cores. two quad-cores == four dual-cores == eight single-cores.&lt;/li&gt;
&lt;/ol&gt;


&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="text"&gt;  $ uptime
  load averages: 1.51 1.30 1.24
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;load averages: [average over last minute] [average over last 5 minutes] [average over last 15 minutes]&lt;/p&gt;

&lt;p&gt;Focus on the 15 minute average.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="text"&gt;  $ cat /proc/cpuinfo
  $ grep &amp;#39;model name&amp;#39; cat /proc/cpuinfo | wc -l
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h4&gt;helpful links&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages"&gt;scout app&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=rr4Za44ohF8:Z9UHF62E1BI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=rr4Za44ohF8:Z9UHF62E1BI:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=rr4Za44ohF8:Z9UHF62E1BI:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/rr4Za44ohF8" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//devops/2013/04/30/load-averages.html</feedburner:origLink></entry>
  
  <entry>
    <title>heroku performance conversation</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/DBNGjCLCHyo/heroku-performance-conversation.html" />
    <id>http://mokhan.ca/devops/rails/2013/04/30/heroku-performance-conversation</id>
    <updated>2013-04-30T13:18:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;p&gt;Earlier this morning I got a chance to sit in on a phone conversation
with an engineer from Heroku. The topic of discussion was on how we can
improve performance for &lt;a href="http://fairgoods.com/"&gt;fairgoods.com&lt;/a&gt;. These
are some of the notes from that conversation.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Memory usage reports from new relic is not very useful.&lt;/li&gt;
&lt;li&gt;look up &lt;a href="https://devcenter.heroku.com/articles/log-runtime-metrics"&gt;log runtime metrics&lt;/a&gt; from the heroku dev center.

&lt;ul&gt;
&lt;li&gt;gives visibility into load and memory usage for running dynos.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;goal is to keep reponse times to below 500mS.&lt;/li&gt;
&lt;li&gt;find the optimal number of unicorn workers per dyno. without
constraining resources. (3 seems to be the magic number for us.)&lt;/li&gt;
&lt;li&gt;lookup a plugin called &lt;a href="https://github.com/heroku/heroku-manual-deploy"&gt;manual deploy&lt;/a&gt; to do rolling restarts. this
allows you to restart workers one at a time instead of all at once.&lt;/li&gt;
&lt;li&gt;load average below 4s is ok or else you might need to tweak the number
of unicorn workers.&lt;/li&gt;
&lt;li&gt;heroku currently offers 2X dynos that have approximately double the memory available.

&lt;ul&gt;
&lt;li&gt;we were suggested to A/B test 1X vs 2X dynos to see if that would make a difference for us.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;we had no H12 errors which indicate the number of request timeouts.&lt;/li&gt;
&lt;li&gt;suggested unicorn timeout is 15 seconds, we are currently at 30 seconds.

&lt;ul&gt;
&lt;li&gt;if your requests need to take longer than that then we should
consider partitioning different parts of the application.&lt;/li&gt;
&lt;li&gt;one place that seems to have larger request times is when running reports.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;break out the admin section of the site into its own application. You
can configure different applications to connect to the same database
by configuring environment variables. This move slow processing on the
admin side to separate dynos than from the dynos that would serve the
main website.&lt;/li&gt;
&lt;li&gt;you can also scale up the dynos when interacting with the admin section.&lt;/li&gt;
&lt;li&gt;in our case we could increase the unicorn worker count.&lt;/li&gt;
&lt;li&gt;move image assets to cloudfront. serving images and static content
through heroku is not ideal. we should see a performance increase if
we can do this.&lt;/li&gt;
&lt;/ul&gt;


&lt;h3&gt;example proc file&lt;/h3&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="text"&gt;  web: bundle exec unicorn -p $PORT -c ./config/unicorn.rb
  worker:  bundle exec rake jobs:work
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=DBNGjCLCHyo:y_x1yOcv0Fg:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=DBNGjCLCHyo:y_x1yOcv0Fg:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=DBNGjCLCHyo:y_x1yOcv0Fg:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/DBNGjCLCHyo" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//devops/rails/2013/04/30/heroku-performance-conversation.html</feedburner:origLink></entry>
  
  <entry>
    <title>viewport</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/T3V7gYmMTR0/viewport.html" />
    <id>http://mokhan.ca/html/2013/04/23/viewport</id>
    <updated>2013-04-23T09:48:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;h1&gt;viewport&lt;/h1&gt;

&lt;p&gt;Viewport is an effective screen size for a mobile device. Use a special
meta tag in the html header to tell mobile devices how many pixels to
fit into its screen. Each device defaults to a default setting. Width
should be equal to or slightly larger than your web content to ensure a
little bit of margin next to your text for readability.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;viewport&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;width=1024&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;You can also set the viewport width to the same as the mobile devices
native screen resolution.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="html"&gt;  &lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;viewport&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;width=device-width, initial-scale=1.0, maximum-scale=1.0&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Initial scale tells iphones and ipads not to scale to its default 980
px. Maximum scale previews users from zooming in.&lt;/p&gt;

&lt;h1&gt;css media queries&lt;/h1&gt;

&lt;p&gt;Conditional statements for CSS which you can use to target specific devices.
You can point to different stylesheets depending on the media type and screen size.
Or you can use conditional statements embedded in css to target media types and screen size.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="css"&gt;  &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="nt"&gt;handheld&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;screen&lt;/span&gt; &lt;span class="nt"&gt;and&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;max-device-with&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;480px&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="nt"&gt;screen&lt;/span&gt; &lt;span class="nt"&gt;and&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;min-width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;481px&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nt"&gt;and&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;max-width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;1024px&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="nt"&gt;screen&lt;/span&gt; &lt;span class="nt"&gt;and&lt;/span&gt; &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;min-width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;1025px&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="nt"&gt;print&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;width&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;This builds css to target mobile phones, tablets and computers.&lt;/p&gt;

&lt;h2&gt;helpful links&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://www.bigbossmas.com/web-development/responsive-web-design-designing-a-website-for-mobile-devices/"&gt;web design for mobile&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;


    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=T3V7gYmMTR0:3rA0pBfdDGI:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=T3V7gYmMTR0:3rA0pBfdDGI:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=T3V7gYmMTR0:3rA0pBfdDGI:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/T3V7gYmMTR0" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//html/2013/04/23/viewport.html</feedburner:origLink></entry>
  
  <entry>
    <title>rails caching</title>
    <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/mokhan/~3/AIhword9Qpo/rails-caching.html" />
    <id>http://mokhan.ca/ruby/rails/2013/04/11/rails-caching</id>
    <updated>2013-04-11T12:28:00-06:00</updated>
    <content type="html" xml:lang="en" xml:base="http://mokhan.ca/">
      &lt;h2&gt;Options&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;HTTP Caching: Uses HTTP headers to instruct browsers on server side caching.&lt;/li&gt;
&lt;li&gt;Page Caching: Cache the entire page to disk and serve directly from the web server like Nginx.&lt;/li&gt;
&lt;li&gt;Action Caching: Runs through the rails pipeline and runs before_filters but returns cached results from disk like page caching.&lt;/li&gt;
&lt;li&gt;Fragment Caching: Store parts of views in the cache.&lt;/li&gt;
&lt;li&gt;Rails.cache: In memory server side cache.&lt;/li&gt;
&lt;/ul&gt;


&lt;h2&gt;Page Caching&lt;/h2&gt;

&lt;p&gt;class ProductsController &amp;lt; ActionController
  caches_page :index&lt;/p&gt;

&lt;p&gt;  def index&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@products = Products.all
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  end
end&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/products will generate a file called products.html.gz. NGINX will efficiently serve this static file&lt;/li&gt;
&lt;li&gt;by default pages are cached in /public&lt;/li&gt;
&lt;/ul&gt;


&lt;p&gt;To expire a page you call expire_page in the action that would invalidate the cache.&lt;/p&gt;

&lt;p&gt;class ProductsController &amp;lt; ActionController
  caches_page :index&lt;/p&gt;

&lt;p&gt;  def index&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;@products = Products.all
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  end&lt;/p&gt;

&lt;p&gt;  def create&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;expire_page :action =&amp;gt; :index
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;  end
end&lt;/p&gt;

&lt;p&gt;Nginx can serve compressed content directly from disk by enabled gzip_static&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="text"&gt;  location / {
    gzip_static on;
  }
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;Page caching ignores parameters like /products?page=1. If someone
requests /products?page=2 they will get the cached first page. A
workaround is to use a route like /products/page/1&lt;/p&gt;

&lt;h2&gt;Action Caching&lt;/h2&gt;

&lt;p&gt;This is good for pages that restrict access in some way. Incoming
request does go from webserver to rails stack. Before filters are run to
allow for things like authentication. Instead of expire_page you use
expire_action.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductsController&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActionController&lt;/span&gt;
  &lt;span class="n"&gt;before_filter&lt;/span&gt; &lt;span class="ss"&gt;:authenticate&lt;/span&gt;
  &lt;span class="n"&gt;caches_action&lt;/span&gt; &lt;span class="ss"&gt;:index&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
    &lt;span class="vi"&gt;@products&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Product&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;all&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;

  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;create&lt;/span&gt;
    &lt;span class="n"&gt;expire_action&lt;/span&gt; &lt;span class="ss"&gt;:action&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="ss"&gt;:index&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Fragment Caching&lt;/h2&gt;

&lt;p&gt;Add cache "key" to your view to cache a fragment. You can use the
updated_at timestamp to signal when to invalidate the cache.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;%= cache &amp;quot;post-&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="vi"&gt;@post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sx"&gt;&amp;quot;, @post.updated_at.to_i do %&amp;gt;&lt;/span&gt;
&lt;span class="sx"&gt;  &amp;lt;h1&amp;gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt;&amp;lt;/h1&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;p&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;%=&lt;/span&gt; &lt;span class="vi"&gt;@post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;content&lt;/span&gt; &lt;span class="sx"&gt;%&amp;gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sx"&gt;% end &lt;/span&gt;&lt;span class="o"&gt;%&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;p&gt;If you touch a post it will update the timestamp.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;  &lt;span class="no"&gt;Post&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;touch&lt;/span&gt;

  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Comment&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;ActiveRecord&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Base&lt;/span&gt;
    &lt;span class="n"&gt;belongs_to&lt;/span&gt; &lt;span class="ss"&gt;:post&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:touch&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;


&lt;h2&gt;Rails Cache&lt;/h2&gt;

&lt;div class="highlight"&gt;&lt;pre&gt;&lt;code class="ruby"&gt;  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;write&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;bar&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;read&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;foo&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;clear&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;




    &lt;div class="feedflare"&gt;
&lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=AIhword9Qpo:IjygPFuUyfw:yIl2AUoC8zA"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?d=yIl2AUoC8zA" border="0"&gt;&lt;/img&gt;&lt;/a&gt; &lt;a href="http://feeds.feedburner.com/~ff/mokhan?a=AIhword9Qpo:IjygPFuUyfw:zNBqN1PhYbM"&gt;&lt;img src="http://feeds.feedburner.com/~ff/mokhan?i=AIhword9Qpo:IjygPFuUyfw:zNBqN1PhYbM" border="0"&gt;&lt;/img&gt;&lt;/a&gt;
&lt;/div&gt;&lt;img src="http://feeds.feedburner.com/~r/mokhan/~4/AIhword9Qpo" height="1" width="1"/&gt;</content>
  <feedburner:origLink>http://mokhan.ca//ruby/rails/2013/04/11/rails-caching.html</feedburner:origLink></entry>
  
</feed>
