<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Konr Ness</title>
    <description>PHP, Javascript, MySQL Developer in Minneapolis, MN</description>
    <link>http://konrness.com/</link>
    <atom:link href="http://konrness.com/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Sun, 25 Apr 2021 22:34:58 +0000</pubDate>
    <lastBuildDate>Sun, 25 Apr 2021 22:34:58 +0000</lastBuildDate>
    <generator>Jekyll v2.5.3</generator>
    
      <item>
        <title>Hosting this site on Google Cloud Run</title>
        <description>&lt;p&gt;Since 2009, this blog, among other personal projects, was hosted on a VM on Rackspace. The $20 per month I was paying finally got to me, and I decided to migrate it to a new host. I selected Google Cloud Run. To do that, I needed to repackage the site into a Docker Container and migrate the domain.&lt;/p&gt;

&lt;p&gt;This site is built using &lt;a href=&quot;https://jekyllrb.com/&quot;&gt;Jekyll&lt;/a&gt;, which is a static site generator. I write the posts in markdown, and Jekyll transforms them into styled HTML. The site search is run with Javascript and a generated JSON site index.&lt;/p&gt;

&lt;p&gt;Previously, I ran the Jekyll commands to build the site and manually uploaded them to the VM with SCP. I thought, if I’m going to migrate to a cloud native, containerized platform I should also replace the old-school techniques that I was using for build/release.&lt;/p&gt;

&lt;p&gt;All of the code for this site, including the build/deploy process, is on &lt;a href=&quot;https://github.com/konrness/konrness.com&quot;&gt;Github&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;step-1---containerize-the-build&quot;&gt;Step 1 - Containerize the Build&lt;/h2&gt;

&lt;p&gt;The old way:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# deploy.sh&lt;/span&gt;
bundle &lt;span class=&quot;nb&quot;&gt;exec &lt;/span&gt;jekyll build
scp -r _site/* venus@konrness.com:/vweb/konrness.com/docs/&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The new way:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# build.sh&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;export &lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;JEKYLL_VERSION&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;2.5.3
docker run --rm &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  --volume&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;$PWD:/srv/jekyll&amp;quot;&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  -it jekyll/jekyll:&lt;span class=&quot;nv&quot;&gt;$JEKYLL_VERSION&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  jekyll build&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The benefits of containerizing the build process is that I no longer need to maintain a local Ruby installation and mess around with managing dependencies. Everything is built into the jekyll/jekyll Docker image and self-contained. When I’m done building, the container dies and nothing hangs around.&lt;/p&gt;

&lt;p&gt;The result of this build is a new &lt;code&gt;_site&lt;/code&gt; folder which is the static contents of the generated site, including directories, static assets (JS, CSS, fonts, etc.) and HTML files.&lt;/p&gt;

&lt;h2 id=&quot;step-2---create-a-deployable-artifact&quot;&gt;Step 2 - Create a deployable artifact&lt;/h2&gt;

&lt;p&gt;Now that I have the site generated, the second step of the &lt;code&gt;build.sh&lt;/code&gt; script packages the code into a Docker container.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# build.sh (continued)&lt;/span&gt;

docker build -t konrness/konrness.com .&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Since the site is entirely static, I am using the &lt;code&gt;nginx:alpine&lt;/code&gt; Docker image to deliver the site.&lt;/p&gt;

&lt;p&gt;The Dockerfile is as simple as:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# Dockerfile&lt;/span&gt;
FROM nginx:alpine
COPY _site /usr/share/nginx/html&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This copies the static site from &lt;code&gt;_site&lt;/code&gt; into the default web directory for the &lt;code&gt;nginx&lt;/code&gt; container.&lt;/p&gt;

&lt;p&gt;I can then run this Docker container locally to preview and test the site.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# run.sh&lt;/span&gt;
docker run -p 8080:80 -it konrness/konrness.com&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h2 id=&quot;step-3---publish-to-docker-hub&quot;&gt;Step 3 - Publish to Docker Hub&lt;/h2&gt;

&lt;p&gt;Once I have validated locally that the Docker image I have created is ready for release, I tag and push to Docker Hub and GCP Container Registry.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# release.sh&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;timestamp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;$(&lt;/span&gt;date +%y.%-m.%-d&lt;span class=&quot;k&quot;&gt;)&lt;/span&gt;
 
&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Tagging version &lt;span class=&quot;nv&quot;&gt;$timestamp&lt;/span&gt;
docker tag konrness/konrness.com konrness/konrness.com:&lt;span class=&quot;nv&quot;&gt;$timestamp&lt;/span&gt;
 
&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Pushing tag: &lt;span class=&quot;nv&quot;&gt;$timestamp&lt;/span&gt;
docker push konrness/konrness.com:&lt;span class=&quot;nv&quot;&gt;$timestamp&lt;/span&gt;
 
&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Pushing tag: latest
docker push konrness/konrness.com:latest
 
&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Pruning...
docker system prune -f&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;The tag to be deployed is versioned based on the date. For instance, the tag I push on April 16th, 2021 would be named &lt;code&gt;konrness/konrness.com:21.4.16&lt;/code&gt;. I push the tag to both Docker Hub as well as my personal Google Cloud Platform Container Registry because I am hosting the site on GCP Cloud Run, and Cloud Run does not support pulling Docker images from Docker Hub.&lt;/p&gt;

&lt;h2 id=&quot;step-4---deploy-to-cloud-run&quot;&gt;Step 4 - Deploy to Cloud Run&lt;/h2&gt;

&lt;p&gt;The last step of the &lt;code&gt;release.sh&lt;/code&gt; script is to deploy to Cloud Run.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# release.sh (continued)&lt;/span&gt;

&lt;span class=&quot;nb&quot;&gt;echo &lt;/span&gt;Deploying to Cloud Run
gcloud run deploy konrness-com --image gcr.io/personal-sites-310123/konrness.com:&lt;span class=&quot;nv&quot;&gt;$timestamp&lt;/span&gt; --region us-central1 --platform managed&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Easy as that.&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s Next&lt;/h2&gt;

&lt;p&gt;This build and release process is currently entirely scripted, and only run on my local workstation. In a future iteration of this, I plan to implement a CI/CD solution that will automate the process for me. I’ll link to that here, when I get to it.&lt;/p&gt;
</description>
        <pubDate>Fri, 16 Apr 2021 13:18:18 +0000</pubDate>
        <link>http://konrness.com/devops/hosting-this-site-on-google-cloud-run/</link>
        <guid isPermaLink="true">http://konrness.com/devops/hosting-this-site-on-google-cloud-run/</guid>
        
        <category>gcp,</category>
        
        <category>google,</category>
        
        <category>static</category>
        
        <category>html,</category>
        
        <category>jekyll,</category>
        
        <category>docker</category>
        
        
        <category>devops</category>
        
      </item>
    
      <item>
        <title>PHP: Your privates aren&#39;t as private as you think they are</title>
        <description>&lt;p&gt;In PHP, we have three visibility keywords:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;public&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;protected&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;private&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
 
 &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Student&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
 
     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
         &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
     &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getClasses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
     &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
         &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
     &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
 
 &lt;span class=&quot;nv&quot;&gt;$mary&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;CompSci2001&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;CompSci2002&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;In &lt;a href=&quot;https://3v4l.org/3nLfb&quot;&gt;this example&lt;/a&gt;, we see &lt;code&gt;private&lt;/code&gt; and &lt;code&gt;public&lt;/code&gt; being used. The list of the students’ classes are readable externally, 
but once the student is instantiated the list of classes cannot be modified. This is because the &lt;code&gt;classes&lt;/code&gt; property is declared &lt;code&gt;private&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A quote from the &lt;a href=&quot;http://php.net/manual/en/language.oop5.visibility.php&quot;&gt;PHP manual for Visibility&lt;/a&gt;, describes the visibility keywords:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Class members declared &lt;code&gt;public&lt;/code&gt; can be accessed everywhere. Members declared &lt;code&gt;protected&lt;/code&gt; can be accessed only within the 
class itself and by inherited classes. Members declared as &lt;code&gt;private&lt;/code&gt; may only be accessed by the class that defines the member.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But pay close attention to the wording there: “may only be accessed by the &lt;strong&gt;class&lt;/strong&gt; that defines the member.”&lt;/p&gt;

&lt;p&gt;A common misconception is that these visibilities are &lt;em&gt;object-level&lt;/em&gt;. But they are not; they are &lt;em&gt;class-level&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;Consider &lt;a href=&quot;https://3v4l.org/iGG8S&quot;&gt;this example&lt;/a&gt; where &lt;strong&gt;one instance&lt;/strong&gt; of a class modifies &lt;strong&gt;the other instance’s&lt;/strong&gt; private properties.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Student&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;__construct&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getClasses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;k&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;combineClasses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;Student&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$otherStudent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$allClasses&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;array_unique&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;array_merge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
                &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                &lt;span class=&quot;nv&quot;&gt;$otherStudent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        
        &lt;span class=&quot;nv&quot;&gt;$this&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt;         &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$allClasses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;$otherStudent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;classes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$allClasses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;


&lt;span class=&quot;nv&quot;&gt;$mary&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;CompSci2001&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;CompSci2002&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$john&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Student&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;CompSci2002&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;CompSci2003&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

&lt;span class=&quot;nv&quot;&gt;$mary&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;na&quot;&gt;combineClasses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$john&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;h3 id=&quot;dude-what&quot;&gt;Dude, what?&lt;/h3&gt;

&lt;p&gt;After seeing the previous example, you may be thinking that surely PHP screwed up it’s object-oriented implementation 
when it added visibility keywords in PHP 5? However, this same implementation of class-level visibility exists in
other popular languages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html&quot;&gt;Java&lt;/a&gt;: Access level modifiers determine whether other classes can use a particular field or invoke a particular method.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/ms173121.aspx&quot;&gt;C#&lt;/a&gt;: The type or member can be accessed only by code in the same class or struct.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/zfbte35d.aspx&quot;&gt;C++&lt;/a&gt;: The private keyword specifies that those members are accessible only from member functions … of the class.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The basics tenets of object-oriented programming allow for this.&lt;/p&gt;

&lt;h3 id=&quot;what-does-this-mean-to-you-as-a-php-developer&quot;&gt;What does this mean to you as a PHP developer?&lt;/h3&gt;

&lt;p&gt;It’s important to note that the reason we declare class members as &lt;code&gt;private&lt;/code&gt; is to make the class more encapsulated.
Encapsulation allows for changing the internals of the class without affecting the code that uses your class. 
This still holds true with our new understanding about visibility, because the code that has access to your class’s private members is &lt;em&gt;the class&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;We can all agree that the typical object-oriented model of having classes represent real-world objects, and setting 
visibility to limit the outside world from modifying properties is good. When following the “classes describe the real world”
technique, you can probably think of some realistic use-cases for exploiting class-level visibility. But like all 
powerful things, it is possible to do real harm when exploited.&lt;/p&gt;
</description>
        <pubDate>Mon, 21 Nov 2016 13:29:18 +0000</pubDate>
        <link>http://konrness.com/php/php-your-privates-arent-as-private-as-you-think-they-are/</link>
        <guid isPermaLink="true">http://konrness.com/php/php-your-privates-arent-as-private-as-you-think-they-are/</guid>
        
        
        <category>php</category>
        
      </item>
    
      <item>
        <title>How to strace a process that hasn&#39;t started yet</title>
        <description>&lt;p&gt;My personal server, which runs this blog, was recently hacked. I knew that the server was sending out a constant stream 
of spam email, but I didn’t know what process it was coming from. When I ran &lt;code&gt;top&lt;/code&gt; I saw that a &lt;code&gt;perl&lt;/code&gt; script was running
but I didn’t know what it was doing, so I wanted to run &lt;code&gt;strace&lt;/code&gt; on it.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;strace&lt;/code&gt; you can diagnose processes if you provide a process ID (PID), like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;strace -vvtf -p 1234
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;However, the perl process was ending faster than I could capture the pid to strace it.&lt;/p&gt;

&lt;p&gt;Using the following script, you can provide the process name and it will wait until the process starts, and then strace it:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;while true; do pid=$(pgrep &#39;processname&#39; | head -1); if [[ -n &quot;$pid&quot; ]]; 
then strace  -s 2000 -vvtf -p &quot;$pid&quot;; break; fi; done
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This technique can be used to run strace on processes that have an unknown PID or for running strace on processes that are
ending before you can capture the PID.&lt;/p&gt;
</description>
        <pubDate>Thu, 29 Jan 2015 18:39:18 +0000</pubDate>
        <link>http://konrness.com/linux/how-to-strace-a-process-that-has-not-started-yet/</link>
        <guid isPermaLink="true">http://konrness.com/linux/how-to-strace-a-process-that-has-not-started-yet/</guid>
        
        
        <category>linux</category>
        
      </item>
    
      <item>
        <title>My 2013 Goals to Learn New Technologies</title>
        <description>&lt;p&gt;That’s right, I’m setting goals for 2013 on the last day of the third quarter. But my current status warrants the urgency. 
I have been &lt;a href=&quot;http://nerdery.com/people#Kn&quot;&gt;a PHP developer&lt;/a&gt; since I started at &lt;a href=&quot;http://nerdery.com/&quot;&gt;The Nerdery&lt;/a&gt; exactly 
6 years ago this month. Within the first few months I learned Zend Framework (&lt;a href=&quot;http://framework.zend.com/manual/1.0&quot;&gt;version 1.0.2&lt;/a&gt; at the time). 
I have developed all of my projects since then in Zend Framework. In doing that I have come to be somewhat of a Zend Framework expert.&lt;/p&gt;

&lt;p&gt;In addition to being involved in over 400 projects I have also taken on more of a management role as a Principal Software Engineer (PSE). 
I am now leading a team of 7 other PSEs. Our team is in charge of &lt;a href=&quot;http://www.nerdery.com/workwithme/Kn&quot; title=&quot;Work with me!&quot;&gt;recruiting&lt;/a&gt;, 
mentoring developers, helping with sales and resourcing needs, and defining and enforcing standards, among other things. 
Doing all of these non-development things, along with my focus on Zend Framework 1, has caused me to miss 6 years of changes in web development.&lt;/p&gt;

&lt;p&gt;Now with &lt;a href=&quot;http://framework.zend.com/about/faq/&quot;&gt;Zend Framework 1.x being sunsetted in 2014&lt;/a&gt; and 
&lt;a href=&quot;http://framework.zend.com/&quot;&gt;Zend Framework 2 being released&lt;/a&gt;, which at first blush feels very foreign to me, I find 
myself at a cross-road. I can either continue to float further and further away from actual programming and focus on 
management and project leadership, or dive back in and reintroduce myself to the new stuff.&lt;/p&gt;

&lt;p&gt;Without further ado, here’s my list of technologies that I want to learn by the end of 2013:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Groovy on Grails&lt;/li&gt;
  &lt;li&gt;OpenStack, or other virtualization environments&lt;/li&gt;
  &lt;li&gt;Vagrant + Puppet/Chef&lt;/li&gt;
  &lt;li&gt;Varnish&lt;/li&gt;
  &lt;li&gt;Javascript MVC (Backbone, RequireJS, Underscore, Grunt)&lt;/li&gt;
  &lt;li&gt;MongoDB&lt;/li&gt;
  &lt;li&gt;Solr&lt;/li&gt;
  &lt;li&gt;Symfony2&lt;/li&gt;
  &lt;li&gt;Node.js&lt;/li&gt;
  &lt;li&gt;.Net MVC&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hmm, that’s a pretty long list. I probably won’t get to all of them by the end of the year. But if I can stay focused I 
will hopefully be able to reap the benefits by being more effective at my job and assuring my long-term career 
opportunities in the industry. I hope my friends and colleagues can hold me to it and help me achieve this goal.&lt;/p&gt;
</description>
        <pubDate>Mon, 30 Sep 2013 16:39:18 +0000</pubDate>
        <link>http://konrness.com/personal/my-2013-goals-to-learn-new-technologies/</link>
        <guid isPermaLink="true">http://konrness.com/personal/my-2013-goals-to-learn-new-technologies/</guid>
        
        
        <category>personal</category>
        
      </item>
    
      <item>
        <title>PHP Session Locks – How to Prevent Blocking Requests</title>
        <description>&lt;p&gt;Many people are aware that modern browsers limit the number of concurrent connections to a specific domain to between 4 or 6. 
This means that if your web page loads dozens of asset files (js, images, css) from the same domain they will be queued 
up to not exceed this limit. This same problem can happen, but even worse, when your page needs to make several requests 
to PHP scripts that use sessions.&lt;/p&gt;

&lt;h3 id=&quot;problem&quot;&gt;Problem&lt;/h3&gt;

&lt;p&gt;PHP writes its session data to a file by default. When a request is made to a PHP script that starts the session 
(session_start()), this session file is locked. What this means is that if your web page makes numerous requests to PHP 
scripts, for instance, for loading content via Ajax, each request could be locking the session and preventing the other 
requests from completing.&lt;/p&gt;

&lt;p&gt;The other requests will hang on session_start() until the session file is unlocked. This is especially bad if one of your 
Ajax requests is relatively long-running.&lt;/p&gt;

&lt;h3 id=&quot;solution&quot;&gt;Solution&lt;/h3&gt;

&lt;p&gt;The session file remains locked until the script completes &lt;em&gt;or&lt;/em&gt; the session is manually closed. To prevent multiple PHP 
requests (that need $_SESSION data) from blocking, you can start the session and then close the session. This will unlock 
the session file and allow the remaining requests to continue running, even before the initial request has completed.&lt;/p&gt;

&lt;p&gt;To close the session, call:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;x&quot;&gt;session_write_close();&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This technique works great if you do not need to write to the session after your long-running process is complete. 
Fortunately, the $_SESSION data is still available to be read, but since the session is closed you may not write to it.&lt;/p&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-php&quot; data-lang=&quot;php&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// start the session&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;session_start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// I can read/write to session&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$_SESSION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;latestRequestTime&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;time&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// close the session&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;session_write_close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// now do my long-running code.&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// still able to read from session, but not write&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$twitterId&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$_SESSION&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;twitterId&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// dang Twitter can be slow, good thing my other Ajax calls&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// aren&amp;#39;t waiting for this to complete&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;$twitterFeed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;fetchTwitterFeed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$twitterId&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;echo&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;json_encode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$twitterFeed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
</description>
        <pubDate>Fri, 17 Dec 2010 16:39:18 +0000</pubDate>
        <link>http://konrness.com/php5/how-to-prevent-blocking-php-requests/</link>
        <guid isPermaLink="true">http://konrness.com/php5/how-to-prevent-blocking-php-requests/</guid>
        
        
        <category>php5</category>
        
      </item>
    
      <item>
        <title>Google Wave-style scroll bar jQuery plugin</title>
        <description>&lt;p&gt;Google Wave introduced a revolutionary new way of online communication and collaboration. It seemed to swiftly solve 
the problems inherent our current 40-year-old email system. Unfortunately, it never actually caught on.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/images/scrollbar.png&quot; alt=&quot;Google Wave Scrollbar screenshot&quot; title=&quot;Google Wave Scrollbar&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In addition to rethinking email, though, Google Wave’s user interface also rethought things such as scroll bars. 
I was particularly impressed with Google Wave’s scrollbars which were small, unintrusive, and easy to use.&lt;/p&gt;

&lt;p&gt;In it’s tiny form-factor, the Google Wave scroll bar is able to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Indicate document height&lt;/li&gt;
  &lt;li&gt;Indicate current scroll location&lt;/li&gt;
  &lt;li&gt;Scroll by clicking the arrows (dragger doesn’t move until you move your mouse away)&lt;/li&gt;
  &lt;li&gt;Scroll by dragging&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;After being announced that &lt;a href=&quot;http://googleblog.blogspot.com/2010/08/update-on-google-wave.html&quot;&gt;Google Wave will be retired&lt;/a&gt;, 
I wanted to immortalize this new way of scrolling in a jQuery plugin that does the same thing.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://konrness.github.io/google-wave-scrollbar/&quot;&gt;&lt;strong&gt;View Demo&lt;/strong&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It currently does not work in IE because it uses CSS image data instead of referencing an actual image URL, but upon 
changing the image CSS, it will work in IE.&lt;/p&gt;

&lt;p&gt;This is an alpha release, so please recommend changes or express your interest in a more configurable plugin.&lt;/p&gt;
</description>
        <pubDate>Tue, 02 Nov 2010 16:39:18 +0000</pubDate>
        <link>http://konrness.com/javascript/google-wave-style-scroll-bar-jquery-plugin/</link>
        <guid isPermaLink="true">http://konrness.com/javascript/google-wave-style-scroll-bar-jquery-plugin/</guid>
        
        
        <category>javascript</category>
        
      </item>
    
      <item>
        <title>How to Create Javascript Objects</title>
        <description>&lt;p&gt;It is easy to create Javascript objects, but this method goes one step further by allowing you to create a Javascript 
object with private and public methods, as well as private variables. It’s a perfect way to create a single access 
point for Javascript and Flash to communicate.&lt;/p&gt;

&lt;p&gt;The project I’m currently working on requires heavy interaction between a Flash object and the HTML/DOM. Links on the 
page need to call methods on the Flash object, and events in the Flash object need to trigger actions on the page.&lt;/p&gt;

&lt;p&gt;I decided to create a DOM/Flash Connector in Javascript that would expose all of the methods that each can call into 
the other. I wanted it to be fully encapsulated, and as object oriented as possible.&lt;/p&gt;

&lt;p&gt;One example of what it needed to do was show extended content (in HTML) that the Flash object was not large enough to 
display. For example, when a photo is displayed within the Flash object, the photo’s title, description, comments, tags, 
rating, etc. is displayed in HTML below the Flash object.&lt;/p&gt;

&lt;p&gt;Here is the method I chose to use:&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;Connector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_flashElSelector&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_flashIsReady&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_flash&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// load html into extended content area&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// this is a &amp;quot;private&amp;quot; method in the Connector class&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// it can only be called from within the returned object&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;_populateExtendedContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;#extendedcontent&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// initialize connector object&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// set the jQuery selector to be used for retrieving &lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// the Flash object element&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;init&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;_flashElSelector&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// flash is ready&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// flash calls this method as soon as it is ready to accept&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// incoming method calls&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;flashReady&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(){&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// find flash object in DOM&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;_flash&lt;/span&gt;        &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_flashElSelector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;_flashIsReady&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// show content for specified ID in extended content area&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;showExtendedContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// call the &amp;quot;private&amp;quot; method to display content in the&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// HTML part of the site&lt;/span&gt;
            &lt;span class=&quot;nx&quot;&gt;_populateExtendedContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;/show/extendedcontent&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;

        &lt;span class=&quot;cm&quot;&gt;/**&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;         * Flash Methods&lt;/span&gt;
&lt;span class=&quot;cm&quot;&gt;         */&lt;/span&gt;

        &lt;span class=&quot;c1&quot;&gt;// show content for specified ID in Flash object&lt;/span&gt;
        &lt;span class=&quot;nx&quot;&gt;showContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;

            &lt;span class=&quot;c1&quot;&gt;// if flash isn&amp;#39;t ready to accept method calls, ignore&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// this request&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;_flashIsReady&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;

                &lt;span class=&quot;c1&quot;&gt;// call the showContent() method on the Flash object&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// this is a method that is exposed by Flash that will&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// display content, based on the content&amp;#39;s ID&lt;/span&gt;
                &lt;span class=&quot;nx&quot;&gt;_flash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;showContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

                &lt;span class=&quot;c1&quot;&gt;// call the showExtendedContent() method on the Connector&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// in this case, &amp;quot;this&amp;quot; refers to the same object as the&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// global &amp;quot;Connector&amp;quot; does&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// displays the extended content in the HTML area of the site&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;this&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;showExtendedContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// closure&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}();&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// set the jQuery selector for retrieving the Flash object&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// this is done on the individual pages that have Flash to allow&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// for different IDs for the Flash objects on each page&lt;/span&gt;
&lt;span class=&quot;nx&quot;&gt;Connector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;#flashobject&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If the user selected some content to be displayed within the Flash object, Flash would call to the connector as follows 
to display the extended information for the content in HTML.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;Connector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;showExtendedContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;If the user selected some content to be displayed within the HTML part of the site, Javascript would call to the 
connector as follows to display the content in Flash and the extended information for the content in HTML.&lt;/p&gt;

&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;Connector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;showContent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Note that since the function being assigned to &lt;code&gt;Connector&lt;/code&gt; has the &lt;code&gt;();&lt;/code&gt; at the end of it (line 67), it gets executed 
immediately. This function then returns an object that contains several functions and is assigned to the &lt;code&gt;Connector&lt;/code&gt; 
variable. All of the variables and functions within &lt;code&gt;Connector&lt;/code&gt;, that are not returned, are private and inaccessible 
from the global scope, but fully accessible from within the &lt;code&gt;Connector&lt;/code&gt;, as evidenced by line 36.&lt;/p&gt;

&lt;p&gt;If you have any questions regarding the script please feel free to post them here in the comments. I’m sure there are 
many other ways of creating Javascript objects, so please share your thoughts.&lt;/p&gt;
</description>
        <pubDate>Fri, 21 Aug 2009 16:39:18 +0000</pubDate>
        <link>http://konrness.com/javascript/how-to-create-javascript-objects/</link>
        <guid isPermaLink="true">http://konrness.com/javascript/how-to-create-javascript-objects/</guid>
        
        
        <category>javascript</category>
        
      </item>
    
  </channel>
</rss>
