Skip to content

Instantly share code, notes, and snippets.

View johnyaucc's full-sized avatar

John Yau johnyaucc

  • BeansBox Studio Limited
  • Hong Kong
View GitHub Profile
@johnyaucc
johnyaucc / drupal-image.php
Created September 10, 2018 08:04 — forked from colorfield/drupal-image.php
Drupal 7 and 8 theme image
<?php
/**
* Drupal 7
*/
$fid = 1;
$uri = file_load($fid)->uri; // or fetched via the uri property of a field
$image_url = image_style_url('thumbnail', $uri);
$image = theme_image(array(
'path' => $image_url,
<audio controls>
<source src="http://yourdomain.net/folder-path/audio.mp4" type="audio/mp4">
<source src="http://yourdomain.net/folder-path/audio.oga" type="audio/ogg; codecs=vorbis">
</audio>
@johnyaucc
johnyaucc / gist:0ca7de48fa09c8f641faae4ccea1044e
Created August 16, 2016 08:39 — forked from tonymtz/gist:d75101d9bdf764c890ef
Uninstall nodejs from OSX Yosemite
# first:
lsbom -f -l -s -pf /var/db/receipts/org.nodejs.pkg.bom | while read f; do sudo rm /usr/local/${f}; done
sudo rm -rf /usr/local/lib/node /usr/local/lib/node_modules /var/db/receipts/org.nodejs.*
# To recap, the best way (I've found) to completely uninstall node + npm is to do the following:
# go to /usr/local/lib and delete any node and node_modules
cd /usr/local/lib
sudo rm -rf node*
@johnyaucc
johnyaucc / getColumnized.snippet.php
Last active July 13, 2016 06:52
MODX Snippet - Group items into columns from placeholders
<?php
/**
* @modxDescription Group a list of items into columns where the items are stored in separate placeholders (zero-based).
*/
/**
* getColumnized
*
* Group a list of items into columns where the items are stored in separate placeholders (zero-based).
*
* @author John Yau
@johnyaucc
johnyaucc / GitRepoUpdateTimestamp.sh
Created June 29, 2016 06:06 — forked from jeffery/GitRepoUpdateTimestamp.sh
Update Timestamp of files in Checked-out Git Repository
#!/bin/bash -e
####
# Helper script to update the Last modified timestamp of files in a Git SCM
# Projects working Copy
#
# When you clone a Git repository, it sets the timestamp of all the files to the
# time when you cloned the repository.
#
# This becomes a problem when you want the cloned repository, which is part of a
# Web application have a proper cacheing mechanism so that it can re-cache files
@johnyaucc
johnyaucc / getsize.sql
Created April 20, 2015 06:44
Get MySQL Table Sizes
SELECT TABLE_NAME AS "Table",
round(((data_length + index_length) / 1024 / 1024), 2) AS Size_in_MB
FROM information_schema.TABLES
WHERE table_schema = 'my_db_name'
ORDER BY Size_in_MB DESC
@johnyaucc
johnyaucc / Sample.R
Created August 14, 2014 09:59
Draw boxplot with mean marking
setwd("/path/to/data")
Data <- read.table("sample_data.txt", header=TRUE, sep="\t")
total_cat <- length(levels(Data$Cat))
means <- by(Data$Val, Data$Cat, mean)
boxplot(Data$Val ~ Data$Cat)
points(1:total_cat, means, pch = 23, bg = "red")
$ wget \
--recursive \
--no-clobber \
--page-requisites \
--html-extension \
--convert-links \
--restrict-file-names=windows \
--domains website.org \
--no-parent \
www.website.org/tutorials/html/
#
# Install Apache 2.2.26, PHP 5.4.23 and MySQL 5.5.33
#
## RHEL/CentOS 5 64-Bit ##
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
## Other Repos
#rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
#rpm -Uvh http://repo.webtatic.com/yum/centos/5/latest.rpm
# check for swap space
swapon -s
# check filesystem
df -h
# create and enabled the swap file (e.g. 512MB)
sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
sudo mkswap /swapfile