Skip to content

Instantly share code, notes, and snippets.

View tuanphpvn's full-sized avatar

christian tuanphpvn

View GitHub Profile
@tuanphpvn
tuanphpvn / suspend_until
Created February 3, 2017 05:02 — forked from larrybolt/suspend_until
Suspend your pc until a certain hour
#!/bin/bash
# Auto suspend and wake-up script
#
# Puts the computer on standby and automatically wakes it up at specified time
#
# Written by Romke van der Meulen <redge.online@gmail.com>
# Minor mods fossfreedom for AskUbuntu
#
# Takes a 24hour time HH:MM as its argument
@tuanphpvn
tuanphpvn / MAGENTO - update attribute set option value.php
Last active August 5, 2016 00:53
Save a list of option for Attribute Model #Magento #EAV #OPTION
<?php
$updateAttributeOptionValue = function() {
$attribute_model = Mage::getModel('eav/entity_attribute');
$attribute_id = $attribute_model->getIdByCode('catalog_product', 'color');
$attribute = $attribute_model->load($attribute_id);
$arrColor = array(
'Brown',
@tuanphpvn
tuanphpvn / #Magento #Product #Option.php
Last active August 4, 2016 01:46
Get list product have option #Magento #Product #Option
<?php
$checkProductHaveOption = function() {
$productIds = Mage::getModel('catalog/product')->getCollection()->getAllIds();
$productModel = Mage::getModel('catalog/product');
$arrProductIdHaveOption = array();
foreach ($productIds as $key =>$productId ) {
$productObj = $productModel->load($productId);
if($productObj->getHasOptions()) {
@tuanphpvn
tuanphpvn / backend_uploadgallery.php
Last active August 4, 2016 01:38
Pl Upload multiple #Wordpress #PlUpload
require_once(ABSPATH . "wp-admin" . '/includes/image.php');
require_once(ABSPATH . "wp-admin" . '/includes/file.php');
require_once(ABSPATH . "wp-admin" . '/includes/media.php');
if(!$_FILES) {
wp_die(''); // Do nothing
}
// check max allowed
$max_upload_gal_img = of_get_option(Apollo_DB_Schema::_MAX_UPLOAD_GALLERY_IMG, Apollo_Display_Config::MAX_UPLOAD_GALLERY_IMG);
@tuanphpvn
tuanphpvn / wp.jscropt.js
Last active August 4, 2016 01:36
JScrop upload and drop image in wordpress
/*
$primary_img_sel: main image you want to drop
boxWidth: box contain image. which you want. I usally less than image size
boxHeight: same boxWidth
trueSize: True size of image
keySupport: there are on bug in current i write. When i press image it alwasy go to bottom of page
onChange: when we click on the image. I will change coordinate and width and height. c.w, c.h, c.x, c.y, c.x2, c.y2
*/
$primary_img_sel.Jcrop({
@tuanphpvn
tuanphpvn / change_param_in_query_by_key_value.js
Last active August 4, 2016 01:18
Change param in query #Javascript #Params
change_param_in_query_by_key_value = function(key, value, query) {
var arrParams = query.parseQuery();
if(typeof arrParams[key] === "undefined") {
return query;
}
var _value = arrParams[key], _arr = _value.split('-');
var position_occur_in_value_query = $j.inArray(value, _arr);
if(position_occur_in_value_query === -1) {
return query;
@tuanphpvn
tuanphpvn / magento_tree_category_delete.php
Last active August 4, 2016 00:57
Delete category with a name #Magento #Category
<?php
$deleteCatByName = function($catname) {
$category = Mage::getModel('catalog/category');
$tree = $category->getTreeModel();
$tree->load();
$ids = $tree->getCollection()->getAllIds();
if ($ids){
foreach ($ids as $id){
@tuanphpvn
tuanphpvn / gist:97ccd098475264f4f512
Last active August 4, 2016 00:56
Select all checkbox. What you need to add data-ride="ap-checkboxall" to the select all checkbox and point to his child. That zit #Widget
(function($) {
var $arr_checkall = $('[data-ride="ap-checkboxall"]');
/* bind checkall */
$arr_checkall.click(function() {
var $this = $(this),
_data = $this.data();
$(_data.child_selector).prop('checked', $(this).is(':checked'));
@tuanphpvn
tuanphpvn / gist:bb57303bae49c142e16e
Last active August 4, 2016 00:55
Convert current database (not support utf8) to Support UTF8 #Mysql #UTF8
mysqldump -u root -pyourpass --default-character-set=latin1 -c --insert-ignore --skip-set-charset your_database > dev.db
for i in dev; do iconv -f ISO-8859-1 -t UTF-8 <$i.db >${i}8.db; done
for i in *8.db; do perl -pi -w -e 's/CHARSET=latin1/CHARSET=utf8/g;' $i; done
for i in your_database; do mysql --user=root --password=yourpassword --execute "DROP DATABASE $i; CREATE DATABASE $i CHARACTER SET utf8 COLLATE utf8_general_ci;"; done
mysql --user=root --password=yourpassword --max_allowed_packet=16M --default-character-set=utf8 your_database < dev8.db
@tuanphpvn
tuanphpvn / MAGENTO - create category by fastimport extension.php
Last active August 4, 2016 00:53
create category by fastimport extension #Magento #IMport #Category
<?php
$createCategory = function() {
$data = array();
$arrKey = array(
'Men',
'Men/Shirts',
'Men/New Arrivals',
'Men/Tees, Knits and Polos',