Today I faced with such problem – logs were delayed by about 30 minuted which maked development impossible, solution was pretty simple – I had to change timezone back to Pacific Time GMT-7
Error launching remote program: failed to get the task for process
How to display text as texture using GLKit with OpenGL 2.0 in iPhone iOS?
It’s quite easy if you know where to start. There are two ways, you can use UILabel or NSString. With UILabel you can control width and height of rendered texture, also you have words wrap and text aligning.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
NSError *error; UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)]; myLabel.text = @"Hello world!"; myLabel.font = [UIFont fontWithName:@"Helvetica" size:18]; myLabel.textColor = [UIColor colorWithRed:0/255.0 green:0/255.0 blue:0/255.0 alpha:1]; myLabel.backgroundColor = [UIColor clearColor]; UIGraphicsBeginImageContext(myLabel.bounds.size); CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0, 30); CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0); [myLabel.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage *layerImage = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); if (error) { NSLog(@"Label::initWithText - Error loading texture from image: %@",error); } |
So step by step:
1. first we need our UILabel, in CGRectMake we are setting our text size (rectangle)
2. then we need our text to display, also font using UIFont class
3. setting text color is also easy, but then comes little trick – you can use “clearColor” with background to make it transparent
4. next thing is to start new image context with UIGraphicsBeginImageContext
5. next 2 line are important if you don’t want your text to be vertically flipped (third parameter in CGContextTranslateCTM is our UILabel height)
6. then we need to render our label using renderInContext
7. and finally we have ready to use texture using UIImage
How to get payment method in Magento?
Just call:
$payment = $order->getPayment()->getMethodInstance()->getTitle();
How to get country name from country ID in Magento?
This one is quite simple:
$countryName = Mage::getModel(’directory/country’)->load($country_id)->getName();
How to fix broken serialized string in php?
From time to time previously serialized array will get broken. The most common problem occurs when string length is invalid so instead of
1 |
a:2:{i:758;s:4:"test";i:759;s:4:"test";} |
you have
1 |
a:2:{i:758;s:4:"test";i:759;s:9:"test";} |
becouse someone edited something directly in db, in this case to make php unserialize() function to work again, just do this magic:
1 2 3 |
$data = html_entity_decode($data, ENT_QUOTES, 'UTF-8'); $data = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $data ); $data = unserialize($data); |
and you will get all strings lenths to be fixed again.
iOS throws: “sgx error: background gpu access not permitted”
Well, this one can be really painful. But solution is simple, just make sure you are stopping every OpenGL AND sound activity in applicationWillResignActive
function, not in applicationDidEnterBackground
(becouse it’s too late, app is already in background and no OpenGL/Sound is allowed, you can add playing sounds in background into plist but OpenGL won’t be allowed anyway).
Sorting custom collection in Magento
It seems to be trivial, but it’s not. If you want to use custom table and custom model, and sort collection by one of your table’s column, you can’t just use addAttributeToSort as you do with native Magento collection (like “catalog/product”). Instead of this, you should use setOrder, so your code should look like this:
1 2 3 4 5 6 |
$items = Mage::getModel('module/model') ->getCollection() ->setOrder('date_added', 'DESC') ->addFieldToFilter('category_id', array('eq' => $category_id)) ->setPageSize($pageSize) ->setCurPage($currentPage); |
How to check if product is in stock in Magento?
Well, that is pretty simple but in case someone will need this, just:
1 2 |
$product = Mage::getModel('catalog/product')->load(123); $inStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($product)->getIsInStock(); |
How to create Magento shipment programmaticaly?
In case someone will need this, it’s quite simple:
1 2 3 4 5 6 |
$order = Mage::getModel('sales/order')->load( 1234 ); $shipment = Mage::getModel('sales/service_order', $order)->prepareShipment(array()); $shipment->register(); $shipment->getOrder()->setCustomerNoteNotify(false); $shipment->getOrder()->setIsInProcess(true); $transactionSave = Mage::getModel('core/resource_transaction')->addObject($shipment)->addObject($shipment->getOrder())->save(); |