Skip to content

Instantly share code, notes, and snippets.

View nickwanhere's full-sized avatar

Nick Wan nickwanhere

  • Hong Kong
View GitHub Profile
@nickwanhere
nickwanhere / x86_build.sh
Created June 17, 2022 08:31
Compile Rust under Mac OS with Open SSL without cross-compile. Use Docker instead.
LAMBDA_ARCH="linux/x86_64"
RUST_TARGET="x86_64-unknown-linux-gnu"
RUST_VERSION="latest"
APP_NAME="app_name"
docker run -it --platform ${LAMBDA_ARCH} --rm --user "$(id -u)":"$(id -g)" -v "${PWD}":/usr/src/myapp -w /usr/src/myapp rust:${RUST_VERSION} cargo build --release --target ${RUST_TARGET} -v
cp -v ./target/${RUST_TARGET}/release/${APP_NAME} ./build/bootstrap
@nickwanhere
nickwanhere / fix.sh
Created September 7, 2021 06:50
Mac Big Sur Pyenv install 2.7.11
CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 2.7.11
@nickwanhere
nickwanhere / gist:1a65fc47b78ba81fc4f41b9ccb02587b
Created May 15, 2019 07:12
Craft 3 Query Super Table in Plugin
$entry = Entry::find()
->section('acount')
->leftJoin('{{%supertableblocks}} as supertableblocks', '[[supertableblocks.ownerId]] = [[entries.id]]')
->leftJoin('{{%stc_SUPERTABLEFILED}} as stc_backstopids', '[[stc_SUPERTABLEFILED.elementId]] = [[supertableblocks.id]]')
->andWhere(['stc_SUPERTABLEFILED.field_TARGET'=>$id])
->one();
@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]);
@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 / 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 / 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 / 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 / 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 / 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
}
?>