Sort directory by file size with formatted size field using du -k | sort -nr | awk

du -k | sort -nr | awk '
     BEGIN {
        split("KB,MB,GB,TB", Units, ",");
     }
     {
        u = 1;
        while ($1 >= 1024) {
           $1 = $1 / 1024;
           u += 1
        }
        $1 = sprintf("%.1f %s", $1, Units[u]);
        print $0;
     }
    ' > sort_file.txt

Magento - Grouped Product Parent SKU

I needed to get the parent sku of a grouped product. When a grouped product is added to the cart, only the individual items are stored, so the individual product skus are available, but not the parent sku.



<?php
// Start the Magento application without controller
require_once 'app/Mage.php';
Mage::app();

// Get magento frontend core/session Singleton
Mage::getSingleton('core/session', array('name'=>'frontend'));

// Get checkout session Singleton
$session = Mage::getSingleton('checkout/session');

// Use singleton method to get all items in cart
$cart_items = $session->getQuote()->getAllItems();

// Iterate through cart items


foreach( $cart_items as $item ) {
    // Normal product data
    $sku = $item->getSku();
    $qty = $item->getQty();
    $price = $item->getBaseCalculationPrice();
    $name = $item->getName();
    $item_id = $item->getItemId();


    // Get parent sku via parent_id
    $values = unserialize($item->getOptionByCode('info_buyRequest')->getValue());
    $parent_id = $values['super_product_config']['product_id'];
    $product_details = Mage::getModel('catalog/product')->load($parent_id)->getData();
    $parent_sku = $product_details['sku'];

    echo "SKU: $sku<br />";
    echo "PARENT_SKU: $parent_sku<br /><br />";
}
?>

Screencast: Coding Conway’s Game of Life in Ruby the TDD Way with RSpec

Screencast: Coding Conway’s Game of Life in Ruby the TDD Way with RSpec

By Peter Cooper / November 2, 2011

Recently, there have been many screencasts of people coding things in real time. Yesterday, Ryan Bigg released a video of him implementing Conway's Game of Life from scratch by reading through the 'rules' and then using RSpec to take a test driven approach to fleshing out the functionality.

Ryan is a Ruby Hero and technical writer best known for being co-author of the recently released Rails 3 in Action (along with Yehuda Katz) which I'll be reviewing soon for Ruby Inside. But Ryan's also been getting into doing a little screencasting:

If you can't see the video above, view it directly on Vimeo here.

Ryan's technique is just one of many legitimate approaches but many of you will find something to pick up from this, especially if you're not familiar with test driven development or, perhaps, RSpec. If you're already working on koans non-stop and consider yourself well versed in the ways of TDD, you might want to skip it.

The only downside is that Ryan focuses entirely on the logic without doing a live render of the game board to see his work in action, though this was the right rational choice given the time limit. That would make a good separate project to follow on with, though, if you fancy a little challenge, but be careful to not couple the game logic tightly to any interface you choose to try.

Learning TDD Through Test First Teaching

This website provides a path to learning Ruby through self-guided exercises that use a software test framework. This methodology is called "Test First Teaching" and has been applied successfully in a classroom environment.

To learn more about test-first teaching, read the About Test-First Teaching page, or check out...

To learn programming via tests, read the Learn Ruby or Learn JavaScript page.

Want to try more flavors of test-guided learning? Check out...

  • Ruby Koans to learn the Ruby language, syntax, structure, and some common functions and libraries - a useful complement to our learn_ruby labs
  • Coding Bat for online in-browser Java and Python exercises
  • Ruby Kickstart - screencast lectures and test-driven exercises

Introduction to Rails Screencast | Nettuts+

The Intro to Rails Screencast I Wish I Had

Tutorial Details
  • Subject: Ruby on Rails
  • Difficulty: Beginner
  • Format: 40 Minute Screencast

Isn’t it funny how most “introduction to Ruby on Rails” screencasts are overly simplistic, and rely on generators like scaffolding? The teacher typically follows up the tutorial by stating that most Rails developer don’t use scaffolding generators. Well that’s not much help then! I’d like to give you the tutorial I wish I had. Along the way, we’ll also rely heavily on test-driven development to build a simple app.

Choose HD for the clearest picture.

Covered in this Screencast…

  • Create models and generators
  • Use test-driven development to plan and test an application’s features
  • Work with ActiveRecord
  • Autotest with Guard
  • Use Rspec and Capybara to simulate the user.
  • Create partials
  • Take advantage of Flash notices
  • …and plenty more

Conclusion

If you watched the entire screencast, I hope you enjoyed it! There’s certainly much more to cover, but we crammed a great deal into thirty minutes or so! What other tricks and techniques have you picked up, if you’re just digging into Rails?

Magic-Ruby 2011 Conference Talks « Innovative Thought

Magic-Ruby 2011 Conference Talks

Posted: February 6, 2011 | Author: Tim Knight | Filed under: Programming | Tags: , , | 4 Comments »

I was lucky enough to be able to spend the last few days with some amazing Ruby developers. I enjoyed meeting so many new people and getting the chance to learn about some seriously awesome projects that they are working on. In an effort to consolidate some of the slides and information shared by the speakers I’ve created this post. If you have any updates please leave them in the comments and I’ll continue to complete the list.

Friday

  • Cultivating Cucumber: Slides
    Les Hill, Hashrocket
  • Geospacing Your Ruby: Slides and Video of similar talk from July 9, 2010
    Peter Jackson, Intridea
  • Loving your customers, loving your peers
    Alan Johnson, Carsonified
  • Code Isn’t Enough
    Gregg Pollack / Caike Souza
  • Exceptional Ruby: Slides, Code, and Review
    Avdi Grimm
  • What Happened to Desktop Development in Ruby
    Andy Maleh, Obtiva
  • Keynote
    Dave Thomas, Pragmatic Programmers

Saturday

  • Meditation + Code: Slides
    Mike Gehard, Pivotal Labs
  • Crank Up Your Apps with TorqueBox: Slides | Video
    Jim Crossley, Red Hat
  • How I Learned to Stop Worrying and Love the Cloud: Slides
    Wesley Beary, Engine Yard
  • Developing Cocoa Applications with MacRuby: Slides
    Brendan Lim, Intridea
  • Documentation is freaking awesome: Slides and Links
    Kyle Neath, Github
  • Lightning Talks: Videos
  • Keynote – McDonalds, Six Sigma, and Offshore Outsourcing: Notes
    Chad Fowler, InfoEther

A special thanks to all the speakers and Jeremy McAnally for putting it all together. Anyone wishing to stay in touch can find me on Twitter @timknight.

Magento - display sub-categories instead of products on category page

1) Copy the Category.php file from core to local. Create any directories required under app/code/local. (This is so images can be displayed):

$ cp app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Category.php app/code/local/Mage/Catalog/Model/Resource/Eav/Mysql4/Category.php

2) Add -addAttrbuteToSelect('image') to getChildrenCategories function:
    public function getChildrenCategories($category)
    {
        $collection = $category->getCollection();
        /* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        $collection->addAttributeToSelect('url_key')
            ->addAttributeToSelect('name')
            ->addAttributeToSelect('image')
            ->addAttributeToSelect('all_children')
            ->addAttributeToSelect('is_anchor')
            ->addAttributeToFilter('is_active', 1)
            ->addIdFilter($category->getChildren())
            ->setOrder('position', 'ASC')
            ->joinUrlRewrite()
            ->load();
        return $collection;
    }

3) Add or modify the category view template app/design/frontend/yourdiractory_path/default/template/catalog/category/view.phtml:
<?php
$_category  = $this->getCurrentCategory(); 
$collection = Mage::getModel('catalog/category')->getCategories($_category->entity_id);

$rootcat = $_category->entity_id;
$cat = Mage::getModel('catalog/category')->load($rootcat);
$child = $cat->getChildren();

if($child)
{
$helper     = Mage::helper('catalog/category');
$_helper    = $this->helper('catalog/output');
?>
<div class="category-custom-products">
        <span class="page-title">
        <?php echo $_helper->categoryAttribute($_category, $_category->getName(), 'name') ?></span>

<div class="products-grid">

    <?php foreach ($collection as $cat):?>
        <?php if($_category->getIsActive()):?>
        <?php 
            $cur_category = Mage::getModel('catalog/category')->load($cat->getId());
            //echo $cat->getId();
            $_img = $cur_category->getImageUrl();  
        ?>

<div class="item">
                    
                    getName();?>
</div>                
                
                <?php endif?>
    <?php endforeach;?>
    
</div></div>
<?php
}
else
{
?>
    <?php echo $this->getProductListHtml() ?>
<?php
}
?>

The href tags are getting wonked out by the editor, I'll try and fix them when I get a chance.

iPhone - “Application failed codesign verification” when uploading to iTunes Connect

Apparently I'm not alone, as Googling gave me dozens of results, all which were of no help...until I came across the post on stackoverflow:

"I found the solution to this problem after deeply looking at the log file.

Although I created my own Distribution Profile and assigned to the CODE SIGNING IDENTITY the correct value for the developer certificate, it didn't work giving me an error: "Application failed codesign verification".

The problem is at the following line:

Authority=iPhone Developer: My Name (XXXXXXXXX)

Despite the correct selection in the project settings for the Distribution profile, XCode was compiling it with the developer certificate.

I finally solved it: Right click on the "Targets" -> Get info -> and there it was selected (don't ask me why) the wrong distribution certificate instead of the right one.

I corrected that and it finally was accepted."

Thanks to Cy for answering his own, and my question...

http://stackoverflow.com/questions/2272863/how-to-solve-application-failed-co...