Skip to content

Instantly share code, notes, and snippets.

View ajankovic's full-sized avatar

Aleksandar Janković ajankovic

  • 90poe
  • Belgrade, Serbia
View GitHub Profile
@ajankovic
ajankovic / chrasks.js
Created January 22, 2011 11:58
Copy paste from Chrasks plugin
/*
Author: Aleksandar Janković, [email protected]
Description: Main javascript file for Google Chrome plugin Chrasks. It uses
localStorage technology for saving tasks data.
*/
// Declaring Chrasks object
function Chrasks(){
var me = this;
this.taskForm = document.getElementById('task-form');
@ajankovic
ajankovic / current_viewed_node.php
Created April 25, 2012 16:32
Get current viewed node if available
<?php
/**
* Used to get the current viewed node (works when viewed in page mode).
* @param array $node_types[optional] A filter on the type of node you want to see.
* @return object The node or null if not successfull.
*/
function helper_get_current_node($node_types = array()) {
// Store the current node id, to avoid doing the URL testing
// on every call to this function. I didn't store the node itself
// because I was afraid of data changes during page processing.
@ajankovic
ajankovic / replace_magento_urls.sql
Created April 25, 2012 16:36
SQL snipet to search for configured url for the magento store.
SELECT config_id, path, value FROM core_config_data WHERE value LIKE "http%" AND path LIKE "%web%";
@ajankovic
ajankovic / gist:3054204
Created July 5, 2012 15:01
Find string in MySql database table and replace it
update TABLE_NAME set FIELD_NAME = replace(FIELD_NAME, 'find this string', 'replace found string with this string');
" General "{{{
set encoding=UTF-8
set nocompatible " be iMproved
set history=256 " Number of things to remember in history.
set timeoutlen=250 " Time to wait after ESC (default causes an annoying delay)
set clipboard+=unnamed " Yanks go on clipboard instead.
set pastetoggle=<F10> " toggle between paste and normal: for 'safer' pasting from keyboard
set shiftround " round indent to multiple of 'shiftwidth'
set tags=./tags;$HOME " walk directory tree upto $HOME looking for tags
@ajankovic
ajankovic / magento-assign-image.php
Created November 14, 2012 17:39
Assign existing media gallery image to the loaded product.
$product = Mage::getModel('catalog/product')
->setStoreId($store->getId())
->load($product->getId());
$gallery = $product->getMediaGallery();
$mediaAttribute = array('image', 'small_image', 'thumbnail');
if($gallery && count($gallery['images'])) {
$product_attributes = $product->getTypeInstance()->getSetAttributes();
$gal_backend = $product_attributes['media_gallery']->getBackend();
@ajankovic
ajankovic / magento_env.php
Created November 14, 2012 17:40
Init Magento environment for custom scripts
// I want to see errors
error_reporting(E_ALL);
ini_set('display_errors', '1');
// Modify the PHP Environment
ini_set('memory_limit', '2048M');
// Load Up Magento Core
define('MAGENTO', realpath('..'));
require_once(MAGENTO . '/app/Mage.php');
<?php
Mage::getSingleton('catalog/product_status')->addVisibleFilterToCollection($collection);
Mage::getSingleton('catalog/product_visibility')->addVisibleInCatalogFilterToCollection($collection);
Mage::getSingleton('cataloginventory/stock')->addInStockFilterToCollection($collection);
$collection->addAttributeToFilter('is_saleable', TRUE);
@ajankovic
ajankovic / magento_log_tables.txt
Created February 14, 2013 09:31
Full list of log tables for Magento
log_customer
log_visitor
log_visitor_info
log_url
log_url_info
log_quote
report_viewed_product_index
report_compared_product_index
report_event
catalog_compare_item
@ajankovic
ajankovic / gist:61ab0ef7ed5a3547cf10
Created August 5, 2015 08:52
Generate Golang struct (model) from Postgres tables
WITH models AS (
WITH data AS (
SELECT
replace(initcap(table_name::text), '_', '') table_name,
replace(initcap(column_name::text), '_', '') column_name,
CASE data_type
WHEN 'timestamp without time zone' THEN 'time.Time'
WHEN 'timestamp with time zone' THEN 'time.Time'
WHEN 'boolean' THEN 'bool'
-- add your own type converters as needed or it will default to 'string'