1. Embedding GitHub Gists in Tumblr Posts

    inparens:

    Tumblr’s utter lack of Gist support was pretty much a show-stopper for me, which is why this is my first post. In trying to figure out how to hack it myself, I ran across Jarred Grippe’s post describing how he hacked it. I refactored his solution a bit to add some error checking and a couple of features:

    http://gist.github.com/637764

    Most of the magic comes from the call to embedNextGist inside the document.write overrides. Typically when scripts are being added to the page programatically, you have to be careful not to execute code that depends on the script before the script is loaded. For example, if I had instead just put embedNextGist in a loop, all of the document.write overrides and appending of script tags would have happened long before the first appended script even loaded. The calls to the overridden document.write do not occur until the script has loaded, which would mean that all of the appended scripts would use whichever version of document.write was provided in the last iteration of the loop. That is, each Gist would, in turn, write itself into the last p.gist.

    But in this case, all of that trouble is circumvented by calling embedNextGist from document.write which is called by the appended script (a call which, naturally, cannot happen until the script is loaded).

    Two other small notes:

    • Jarred’s version writes the stylesheet link for every Gist that it handles. My version never writes the stylesheet link because I have that link as part of my Tumblr template.
    • My version caches document.write before processing Gists and restores it upon completion.

    Here is an uncommented version and a 412 byte minified version.

    Enhanced by Zemanta
  2. fastcompany:

3-D Printing Is So Last Year.
MIT’s “Self-Assembling Sand” Builds Objects Instantly

    fastcompany:

    3-D Printing Is So Last Year.

    MIT’s “Self-Assembling Sand” Builds Objects Instantly

  3. Capistrano Push Alerts

    While reading over a few articles I came across a rather nice peice of code by Pivotial Labs’ Jason Noble that did a article on Verifying hosts are active in the load balancer pool with capistrano. This got me to thinking what if I can go one step further and have it pushed to my android device. Plus do it all in pure ruby [plus a gem or to].

    So for my weekend hack I wrote up this little bit of code plus started work on creating a gem that supports jabber, android, and iPhone.

    Related articles

    deploy.rb

    require 'httparty'
    require 'ruby-notify-my-android'
    
    set :application, "example"
    set :repository,  ""
    
    set :scm, :none
    
    role :web, "localhost"
    role :web, "example.tld"
    role :app, "example.tld"
    role :db,  "db.example.tld", :primary => true
    
    def push_notify(hostname)
        NMA.notify do |n|
          n.apikey = YAML.load_file('nmaapi.yml')['apikey']
          n.application = application
          n.event = "Check Load Balencer Status"
          n.description = message
        end
    end
    
    desc "Retrieves the check.txt file to see if the host is in the load balancer"
      task :check_load_balancer do
        roles[:web].map(&:host).each do |hostname|
          url      = "http://#{hostname}/check.txt"
          response = HTTParty.get url
          message  = "Retrieving #{url}: #{response.message}"
          puts message
          push_notify message
      end
    end
    #--
    # (C)2012 Dwight Spencer 
    #
    # Permission is hereby granted, free of charge, to any person obtaining a copy
    # of this software and associated documentation files (the "Software"), to
    # deal in the Software without restriction, including without limitation the
    # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
    # sell copies of the Software, and to permit persons to whom the Software is
    # furnished to do so, subject to the following conditions:
    #
    # The above copyright notice and this permission notice shall be included in
    # all copies or substantial portions of the Software.
    #
    #  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    # THE SOFTWARE.
    #++
    

    nmaapi.yaml

    ---
       apikey: SECRET_KEY_FROM_NOTIFY_MY_ANDROID.COM

    Related resources

    Enhanced by Zemanta
  4. Enabling SELinux on Amazon ec2

    Reciently while working on a Develnet EC2 node I had to deal with a headache beyond all belief, turning on SELinux for Amazon AMI.

    How Do I Enable SELinux under Redhat / Fedora, CentOS, and AMI Linux Systems?

    What is SELinux

    SELinux is a kernel security extension, which can be used to guard against misconfigured or compromised programs. It comes with Mandatory Access Control (MAC) system that improves the traditional UNIX/Linux DAC (Discretionary Access Control) model.

    Installing SELinux

    sudo yum install -Y sel*

    Turning on SELinux

    ~% sudo $EDITOR /etc/selinux/config
    SELINUX=permissive SELINUXTYPE=targted
    ~% sudo $EDITOR /etc/sysconfig/config

    Setting Policies

    sudo touch /.autorelabel

    sudo restorecon -Rv -n /home

    sudo genhomedircon

    Reboot

    sudo shutdown -r now “Enabling SELinux policies “

    Troubleshooting

    egrep -i ‘selinux=0|enforcing=0’ /boot/grub/*