Skip to content

Instantly share code, notes, and snippets.

View nickwanhere's full-sized avatar

Nick Wan nickwanhere

  • Hong Kong
View GitHub Profile
root@myserver:~# dd if=/dev/zero of=/swap.dat bs=1024 count=512k
root@myserver:~# mkswap /swap.dat
root@myserver:~# swapon /swap.dat
root@myserver:~# vim /etc/fstab
vim is started to edit, add the following to the end of /etc/fstab file
/swap.dat none swap sw 0 0
Then, edit the mysql config file
root@myserver:~# vim /etc/mysql/my.cnf
@nickwanhere
nickwanhere / all_attribute_options
Created June 24, 2016 08:08 — forked from pierreandreroy/all_attribute_options
Get all possible value (dropdown options) of a product attribute in Magento.
<?php
//Possible color value
$attribute = Mage::getModel('eav/config')->getAttribute('catalog_product', 'color'); //"color" is the attribute_code
$allOptions = $attribute->getSource()->getAllOptions(true, true);
foreach ($allOptions as $instance) {
$id = $instance['value']; //id of the option
$value = $instance['label']; //Label of the option
}
?>
@nickwanhere
nickwanhere / gist:b31f8c6ad4998c0e1a39
Created November 7, 2014 14:27
Magento Pepperjam Network Code
<?php
/*********Start Pepperjam Network Codes #1 ******/
$lastOrderId = Mage::getSingleton('checkout/session')->getLastOrderId();
$order = Mage::getSingleton('sales/order');
$order->load($lastOrderId);
$_totalData = $order->getData();
$_currency = $_totalData['order_currency_code'];
$_productData = $order->getAllItems();
@nickwanhere
nickwanhere / main.yml
Created January 20, 2017 07:36 — forked from rothgar/main.yml
Generate /etc/hosts with Ansible
# Idempotent way to build a /etc/hosts file with Ansible using your Ansible hosts inventory for a source.
# Will include all hosts the playbook is run on.
# Inspired from http://xmeblog.blogspot.com/2013/06/ansible-dynamicaly-update-etchosts.html
- name: "Build hosts file"
lineinfile: dest=/etc/hosts regexp='.*{{ item }}$' line="{{ hostvars[item].ansible_default_ipv4.address }} {{item}}" state=present
when: hostvars[item].ansible_default_ipv4.address is defined
with_items: groups['all']
@nickwanhere
nickwanhere / Documentation.md
Created April 9, 2017 16:19 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@nickwanhere
nickwanhere / DNS prefetching
Created October 10, 2017 08:24
Common Prefetch Links
<!-- Amazon S3 -->
<link rel="dns-prefetch" href="//s3.amazonaws.com">
<!-- Google CDN -->
<link rel="dns-prefetch" href="//ajax.googleapis.com">
<!-- Microsoft CDN -->
<link rel="dns-prefetch" href="//ajax.microsoft.com">
<link rel="dns-prefetch" href="//ajax.aspnetcdn.com">
@nickwanhere
nickwanhere / pagespeed-requirement.vcl
Created October 10, 2017 08:58 — forked from section-io-gists/pagespeed-requirement.vcl
Using the PageSpeed module alongside Varnish, you will need to configure Varnish to handle PageSpeed optimizations.
# Note: You will want to add the snippet: `include "pagespeed-requirement.vcl";` above your `vcl_recv` in the default.vcl file.
sub vcl_recv {
call pagespeed_capability_detection;
}
# Function derived from requirements here https://modpagespeed.com/doc/downstream-caching#ps-capabilitylist
# Additional detection logic for crawlers, tablet and mobile devices.
sub pagespeed_capability_detection {
if (req.http.User-Agent ~ "(?i)Chrome/[3][2-9]+\.|Chrome/[4-9][0-9]+\.|Chrome/[0-9]{3,}\.") {
@nickwanhere
nickwanhere / functions.php
Created October 26, 2017 14:04 — forked from jarnesjo/functions.php
Clean up WordPress header
remove_action( 'wp_head', 'rsd_link' );
remove_action( 'wp_head', 'wlwmanifest_link' );
remove_action( 'wp_head', 'wp_generator' );
remove_action( 'wp_head', 'start_post_rel_link' );
remove_action( 'wp_head', 'index_rel_link' );
remove_action( 'wp_head', 'adjacent_posts_rel_link' );
remove_action( 'wp_head', 'wp_shortlink_wp_head' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
@nickwanhere
nickwanhere / gist:85bfbe8143ded6a30acb
Created October 27, 2015 08:29
Programmatically set magento locale
<?php
$locale = 'nl_NL';
Mage::app()->getLocale()->setLocaleCode($locale);
Mage::getSingleton('core/translate')->setLocale($locale)->init('frontend', true);
//http://www.kennydeckers.com/programatically-set-locale-language-magento/
?>
@nickwanhere
nickwanhere / some.php
Created May 8, 2019 10:02
Craft 3 Plugin Render Template
$view = Craft::$app->getView();
$view->setTemplateMode($view::TEMPLATE_MODE_SITE);
$html = $view->renderTemplate('report', ['entry' => $entry]);