Skip to content

Instantly share code, notes, and snippets.

View alihalabyah's full-sized avatar
🎯
Focusing

Ali Halabyah alihalabyah

🎯
Focusing
View GitHub Profile
@alihalabyah
alihalabyah / gist:8285055
Created January 6, 2014 16:09
Get country name by country code - Magento
<?php
$country_name=Mage::app()->getLocale()->getCountryTranslation($country_code);
?>
@alihalabyah
alihalabyah / gist:8423759
Created January 14, 2014 19:00
jQuery countTo plugin
<script type="text/javascript">
(function($) {
$.fn.countTo = function(options) {
// merge the default plugin settings with the custom options
options = $.extend({}, $.fn.countTo.defaults, options || {});
// how many times to update the value, and how much to increment the value on each update
var loops = Math.ceil(options.speed / options.refreshInterval),
increment = (options.to - options.from) / loops;
@alihalabyah
alihalabyah / gist:8435482
Created January 15, 2014 12:40
An alternative for file_get_contents() in PHP
<?php
public function url_get_contents ($url) {
if (!function_exists('curl_init')){
die('CURL is not installed!');
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
# This configuration is what is provided by PageCache by Varnish for Magento module:
# http://www.magentocommerce.com/magento-connect/pagecache-powered-by-varnish.html
# default backend definition. Set this to point to your content server.
backend default {
.host = "127.0.0.1";
.port = "80";
}
# admin backend with longer timeout values. Set this to the same IP & port as your default server.
@alihalabyah
alihalabyah / gist:fba4660d0d3f4c3c85a3
Last active May 9, 2017 13:10
Magento postal code javascript error: error: error in [unknown object].fireEvent(): event name: address_country_changed error message: zipElement.up(1).down("label > span.required") is undefined Fix! ___ Update file: app\design\adminhtml\default\default\template\directory\js\optional_zip_countries.phtml
<?php
/**
* Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE_AFL.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
@alihalabyah
alihalabyah / gist:4d39106eaa8fe48b481d
Created July 8, 2014 12:40
Clear Magento cart and quote items
<?php
// Clear Magento cart and quote items
$cart = Mage::getModel('checkout/cart');
$cart->truncate()->save(); // remove all active items in cart page
$cart->init();
$session= Mage::getSingleton('checkout/session');
$quote = $session->getQuote();
$cart = Mage::getModel('checkout/cart');
@alihalabyah
alihalabyah / gist:1e01721ea007b52cbe3a
Created September 7, 2014 09:22
convert image to base64
/**
* Convert an image
* to a base64 string
* @param {String} url
* @param {Function} callback
* @param {String} [outputFormat=image/png]
*/
function convertImgToBase64(url, callback, outputFormat){
var canvas = document.createElement('CANVAS'),
ctx = canvas.getContext('2d'),
@alihalabyah
alihalabyah / gist:b674bf680e3ec2d5dbfd
Created September 13, 2014 16:34
Product info sample response
array(50) {
["product_id"]=>
string(3) "184"
["description"]=>
string(454) "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam bibendum nunc dictum, elementum tortor at, aliquet odio. Suspendisse accumsan semper leo non ornare. Quisque lacinia quis orci id ultricies. Praesent interdum urna vitae tempus vulputate. In vel lobortis mauris. Cras diam mi, scelerisque quis interdum eu, congue in elit. Mauris tincidunt convallis nulla, quis mollis nisi luctus nec. Donec risus enim, congue ac sodales et, aliquam eget justo"
["image"]=>
string(134) "http://progress.devshopgo.me/media/catalog/product/cache/4/image/265x/9df78eab33525d08d6e5fb8d27136e95/s/h/shutterstock_96360692_1.jpg"
["internal"]=>
array(1) {
["currency"]=>

Writing better python code


Swapping variables

Bad code

function countProperties(obj) {
var prop;
var propCount = 0;
for (prop in obj) {
propCount++;
}
return propCount;
}