Skip to content

Instantly share code, notes, and snippets.

View geraldvillorente's full-sized avatar

Stoick The Vast geraldvillorente

  • Philippines
View GitHub Profile
@geraldvillorente
geraldvillorente / gist:81c45703765282c60b52
Created May 22, 2015 05:46
A decent way to avoid using setTimeout when checking for html element changes
$('selector', context).bind("DOMSubtreeModified", function() {
// Do something.
});
@geraldvillorente
geraldvillorente / facebook.util.php
Created June 7, 2015 23:32
Facebook cache buster.
<?php
/**
* Note: If the image is still missing just rerun this script until the cached has been cleared.
*
* To use this script either you can run this via terminal or browser.
* To run this in a terminal:
* $ php facebook.util.php [URL]
*
* To use the browser just put the URL in the text field.
*/
@geraldvillorente
geraldvillorente / gist:6376aa3e07617b49a9c2
Last active August 29, 2015 14:23
Registering a custom menu group under admin/config page.
/**
* Implements hook_menu().
*/
function my_custom_module_menu() {
$items = array();
$items['admin/config/custom'] = array(
'title' => 'Custom Settings',
'description' => 'App custom settings.',
'weight' => -30,
@geraldvillorente
geraldvillorente / gist:ebc60f26ed4852dbe077
Created June 22, 2015 04:22
Example of how to handle image in Amazon S3
function about_us_fetch_image() {
$image_url = NULL;
$fid = variable_get('about_us_image', '');
if (is_numeric($fid) && $fid > 0) {
$file = file_load($fid);
$dest_uri = 's3://about-us-resized.jpg';
// Check if the target image exists. If not, build it.
if (!file_exists($dest_uri)) {
// Copy the image.
file_copy($file, $dest_uri, FILE_EXISTS_REPLACE);
@geraldvillorente
geraldvillorente / gist:55409a8a26913118f9cb
Created July 3, 2015 09:06
ApacheSolr helper function to index the content immediately.
/**
* Helper function to send entities to ApacheSolr for immediate index.
*/
function _custom_module_apachesolr_index_immediately($entity, $type) {
// Get default environment.
$env_id = apachesolr_default_environment();
// Check that index isn't read only.
if (apachesolr_environment_variable_get($env_id, 'apachesolr_read_only', APACHESOLR_READ_WRITE) == APACHESOLR_READ_ONLY) {
return;
// Generate a random numbers to use as url query parameter. This function
// will attempt to bypass Facebook share caching.
// See the performance test for more info.
// http://jsperf.com/random-characters-generator
function createCacheBuster () {
return Math.random();
}
@geraldvillorente
geraldvillorente / tinyurl
Created July 14, 2015 23:56
Create tiny URL programatically
<?php
function tiny_url($url) {
$ch = curl_init();
$timeout = 4;
curl_setopt($ch, CURLOPT_URL, 'http://tinyurl.com/api-create.php?url=' . $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
@geraldvillorente
geraldvillorente / gist:98ef92cd27439996c549
Created July 14, 2015 23:58
Export database using Drush
drush sql-dump --gzip --result-file=/PATH/TO/FILENAME.sql
@geraldvillorente
geraldvillorente / gist:00e9a85b301a674eb64e
Created July 15, 2015 04:14
Enabling Apache rewrite for clean url in Ubuntu
$ sudo a2enmod rewrite
$ sudo service apache2 reload
@geraldvillorente
geraldvillorente / gist:54fe500dcdeb03955d32
Created July 15, 2015 23:12
Install node.js using NVM in Ubuntu 14.04
$ sudo apt-get update
$ sudo apt-get install build-essential libssl-dev
# NOTE: The next command requires curl.
# The version number may be different (see https://github.com/creationix/nvm for latest version),
# but in general, you can download and install it with the following syntax:
$ curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.25.4/install.sh | bash
# Check the message in your screen. You should see something like this:
# "Appending source string to /home/gerald/.bashrc"
# or
# "Appending source string to /home/gerald/.profile".