Skip to content

Instantly share code, notes, and snippets.

@ckng
ckng / script.js
Created April 29, 2014 10:34
IE8 last-child selector
(function ($) {
// IE8 last-child selector
Drupal.behaviors.lastChildIE8 = {
attach: function (context, settings) {
if (/msie [1-8]{1}[^0-9]/.test(navigator.userAgent.toLowerCase())) {
$('*:last-child').addClass('last-child');
}
}
};
@ckng
ckng / revert_locale_lang.php
Created April 14, 2014 08:04
Drupal 7: revert language column to "und" on locale uninstallation, this is not for site with multilanguage, only for site with unused/unconfigured locale
<?php
// Use this to identify possible table needs to be updated
// SELECT DISTINCT TABLE_NAME
// FROM INFORMATION_SCHEMA.COLUMNS
// WHERE COLUMN_NAME IN ('language')
// AND TABLE_SCHEMA='<YOUR_DATABASE>';
// include other custom fields
$tables = array(
@ckng
ckng / swapused.sh
Last active August 29, 2015 13:59
Get current swap usage for all running processes
#!/bin/bash
# swapused.sh
# -- Get current swap usage for all running processes
# --
# -- rev.0.4, 2014-04-11, Chin Kiong Ng - sort kb asc
# -- rev.0.3, 2012-09-03, Jan Smid - alignment and intendation, sorting
# -- rev.0.2, 2012-08-09, Mikko Rantalainen - pipe the output to "sort -nk3" to get sorted output
# -- rev.0.1, 2011-05-27, Erik Ljungstrom - initial version
@ckng
ckng / gist:10243417
Created April 9, 2014 08:50
Ubuntu: Zend OPcache install
# Install "pecl" via php-pear
$ sudo apt-get install -y php-pear
# Install build dependencies
$ sudo apt-get install -y build-essential php5-dev
# Install Zend OpCache
$ sudo pecl install zendopcache-7.0.3
# 12.04
# Fail2Ban configuration file
#
# Author: Charles Chou
# Modified: Norman Yee
# fix original cloudflare-blacklist.conf
# $Revision$
#
[Definition]
#! /bin/bash
### BEGIN INIT INFO
# Provides: memcached
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start memcached daemon
@ckng
ckng / gist:8691983
Created January 29, 2014 16:46
snippet: javascript to get cookie
function getCookie(name) {
name = name.replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
var regex = new RegExp('(?:^|;)\\s?' + name + '=(.*?)(?:;|$)','i'),
match = document.cookie.match(regex);
return match && unescape(match[1]);
}
@ckng
ckng / script.js
Created January 29, 2014 16:35
snippet: Drupal jQuery wrapper/closure
(function ($) {
// Apply once
Drupal.behaviors.customOnce = {
attach: function (context, settings) {
}
};
}(jQuery));
@ckng
ckng / script.js
Created January 29, 2014 16:20
snippet: quick simple way to detect mobile device
// quick simple way to detect mobile device
function is_touch_device() {
return !!('ontouchstart' in window) // works on most browsers
|| !!('onmsgesturechange' in window); // works on ie10
};
@ckng
ckng / gist:8236202
Created January 3, 2014 11:00
Remove Unused Linux Kernel Headers, Images and Modules
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge