Skip to content

Instantly share code, notes, and snippets.

View alvinnguyen's full-sized avatar

Alvin Nguyen alvinnguyen

View GitHub Profile
@alvinnguyen
alvinnguyen / EastBay Size Notification
Created April 12, 2015 23:23
Notify stock availability for a specific size
<?php
function checkStock($url,$sku,$size, $nick = null){
$content = file_get_contents($url);
$find = $sku.'":["<span class';
$start = strpos($content,$find);
$end = strpos($content,"]]",$start);
$substr = substr($content,$start,$end-$start);
if (strpos($substr,$size) !== false){
function validateEmail(email) {
var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
return re.test(email);
}
@alvinnguyen
alvinnguyen / varnish_reload.sh
Last active August 2, 2016 13:40
Reload Varnish server using command line (not service varnish reload)
varnishadm
vcl.load reload01 /usr/local/etc/varnish/default.vcl
vcl.use reload01
varnishadm "ban.url ." # Matches all URLs
varnishadm "ban req.http.host == opensourcehacker.com"
@alvinnguyen
alvinnguyen / cli_debug.sh
Last active November 29, 2017 08:33
xdebug for PHP command line
#!/bin/bash
export XDEBUG_CONFIG="idekey=PHPSTORM" &&
export PHP_IDE_CONFIG="serverName=Unnamed" &&
php "$@"
Also put this into
/etc/php/5.6/fpm/conf.d/20-xdebug.ini
xdebug.remote_host=192.168.56.1
@alvinnguyen
alvinnguyen / mysql_replace.sql
Created September 9, 2016 00:44
How to replace value in mysql query
update core_config_data
set value = replace(value, 'intl.forever', 'oscarintl.forever')
where value like '%intl.forevernew%'; -- this is so the query doesn't spend time checking all other rows
@alvinnguyen
alvinnguyen / 0_reuse_code.js
Created September 13, 2016 23:43
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<?xml version="1.0"?>
<config>
<frontend>
<events>
<!--disable logs-->
<controller_action_predispatch>
<observers><log><type>disabled</type></log></observers>
</controller_action_predispatch>
<controller_action_postdispatch>
<observers><log><type>disabled</type></log></observers>
@alvinnguyen
alvinnguyen / magento_copy_product_images.php
Created December 30, 2016 00:03 — forked from jreinke/magento_copy_product_images.php
Magento: copy images from one product to another
<?php
/**
* Copy all images from $productSrc to $productDest
*
* @param Mage_Catalog_Model_Product $productSrc
* @param Mage_Catalog_Model_Product $productDest
*/
public function copyProductImages(Mage_Catalog_Model_Product $productSrc, Mage_Catalog_Model_Product $productDest)
{
$images = array();
@alvinnguyen
alvinnguyen / grab-all-product-attributes.sql
Created February 1, 2017 03:22 — forked from tegansnyder/grab-all-product-attributes.sql
Magento grab all product attributes for a SKU in direct SQL. "static" backend_type attributes are stored in catalog_product_entity
SELECT * FROM ( SELECT
ce.sku,
ea.attribute_id,
ea.attribute_code,
CASE ea.backend_type
WHEN 'varchar' THEN ce_varchar.value
WHEN 'int' THEN ce_int.value
WHEN 'text' THEN ce_text.value
WHEN 'decimal' THEN ce_decimal.value
WHEN 'datetime' THEN ce_datetime.value
@alvinnguyen
alvinnguyen / magento-delete-attribute-options.php
Last active March 27, 2017 05:55 — forked from jonathansayag/magento-delete-attribute-options.php
Magento PHP script to delete all values of an attribute
<?php
$attribute_code = 'fashion_colour';
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', $attribute_code);
$options = $attribute->getSource()->getAllOptions();
$optionsDelete = array();
$optionsValue = array();
foreach($options as $option) {
if (in_array($option['label'], $optionsValue)) {
$optionsDelete['delete'][$option['value']] = true;
$optionsDelete['value'][$option['value']] = true;