Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Gayan gayanhewa

🎯
Focusing
View GitHub Profile
View gist:777be1a93e883d8955941b5252b56cce

Magento Snippets

Set all categories to is_anchor 1

Find attribute_id

SELECT * FROM eav_attribute where attribute_code = 'is_anchor'

Update all of them with anchor_id from above (usually is ID 51)

UPDATE `catalog_category_entity_int` set value = 1 where attribute_id = 51
@gayanhewa
gayanhewa / customermagento.php
Created May 20, 2020 — forked from edrdesigner/customermagento.php
Get Logged In Customer’s Magento 1.9 details
View customermagento.php
if (Mage::getSingleton('customer/session')->isLoggedIn()) {
// Load the customer's data
$customer = Mage::getSingleton('customer/session')->getCustomer();
$customer->getPrefix();
$customer->getName(); // Full Name
$customer->getFirstname(); // First Name
$customer->getMiddlename(); // Middle Name
@gayanhewa
gayanhewa / short-number-format.php
Created Sep 12, 2019 — forked from RadGH/short-number-format.php
Short Number Formatter for PHP (1000 to 1k; 1m; 1b; 1t)
View short-number-format.php
<?php
// Converts a number into a short version, eg: 1000 -> 1k
// Based on: http://stackoverflow.com/a/4371114
function number_format_short( $n, $precision = 1 ) {
if ($n < 900) {
// 0 - 900
$n_format = number_format($n, $precision);
$suffix = '';
} else if ($n < 900000) {
@gayanhewa
gayanhewa / budget.ledger
Created Jul 31, 2019 — forked from tblyons/budget.ledger
YNAB budgeting with ledger-cli
View budget.ledger
; This is a simple method of maintaining a budget using
; double-entry accounting software.
; Usually, double-entry accounting keeps track of
; assets, liabilities, income, and expenses. However,
; income/expense categories are different than budget
; categories. For one thing, income/expense categories
; continually grow, where budget categories tend to rise
; and fall. I decided to replace tracking my income/
; expenses with tracking my budget.
View Google protobuf installation on Mac
$wget https://github.com/google/protobuf/releases/download/v2.5.0/protobuf-2.5.0.tar.bz2
$tar xvf protobuf-2.5.0.tar.bz2
$cd protobuf-2.5.0
$./configure CC=clang CXX=clang++ CXXFLAGS='-std=c++11 -stdlib=libc++ -O3 -g' LDFLAGS='-stdlib=libc++' LIBS="-lc++ -lc++abi"
$make -j 4
$sudo make install
$protoc --version
@gayanhewa
gayanhewa / disable-xdebug.sh
Created Aug 23, 2018 — forked from hacfi/disable-xdebug.sh
OS X homebrew php 7.0 enable/disable xdebug extension script
View disable-xdebug.sh
#!/bin/sh
sed -i.default "s/^zend_extension=/;zend_extension=/" /usr/local/etc/php/7.0/conf.d/ext-xdebug.ini
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.php70.plist
echo "xdebug disabled"
@gayanhewa
gayanhewa / xdebug
Created Aug 22, 2017
xdebug visual studio code using the php debug extension from felix
View xdebug
1. Remote VM must have xdebug running
vagrant@app:/etc/php/7.0/fpm$ cat conf.d/20-xdebug.ini
zend_extension=/usr/lib/php/20151012/xdebug.so
xdebug.remote_enable=1
xdebug.remote_autostart=1
xdebug.remote_connect_back=1
xdebug.remote_port=9000
2. VSCode should have the below launch config.
@gayanhewa
gayanhewa / index.php
Created Aug 8, 2017
Visa Checkout Sample
View index.php
<html>
<head>
<script type="text/javascript">
function createCookie(name,value,days) {
var expires = "";
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
@gayanhewa
gayanhewa / au_phone_validate
Created Feb 16, 2017
jquery validator australian phone number
View au_phone_validate
jQuery.validator.addMethod("au_phone", function(value, element) {
return this.optional(element) || /^(?:\+?(61))? ?(?:\((?=.*\)))?(0?[2-57-8])\)? ?(\d\d(?:[- ](?=\d{3})|(?!\d\d[- ]?\d[- ]))\d\d[- ]?\d[- ]?\d{3})$/.test(value);
}, "Invalid phone number");
View HTML: select, year & month.js
// html
<label for="year">Год</label>
<select name="year" id="year"></select>
<label for="month">Месяц</label>
<select name="month" id="month">
<option value = "1">01</option>
<option value = "2">02</option>
<option value = "3">03</option>
<option value = "4">04</option>
You can’t perform that action at this time.