Skip to content

Instantly share code, notes, and snippets.

View ranelpadon's full-sized avatar

ranelpadon

View GitHub Profile
@ranelpadon
ranelpadon / issues_with_deleting_objects.py
Last active August 29, 2015 14:19
Python's __del__ has some nasty issues when dealing with objects, list, garbage collection, etc.
# Hypothetical class for saving the Universe.
class Particle:
def __init__(self, name):
self.name = name
print self.name, 'created'
def __del__(self):
print self.name, 'deleted'
# Create new particle objects.
@ranelpadon
ranelpadon / drupal_image_with_caption_block.php
Last active August 29, 2015 14:13
Create a Drupal block programmatically. This will create a block with an image and a tagline, demonstrating the use of theme function and render arrays
<?php
// HOW TO USE:
// Create a MY_MODULE.info file. See https://www.drupal.org/node/542202.
// Create a MY_MODULE.module file.
// Put the codes below in MY_MODULE.module file
// THE BIG PICTURE:
// For a block to work in Drupal, you have to do a minimum of 3 things:
// 1. Declare the block in hook_block_info().
@ranelpadon
ranelpadon / drupal_get_node_type.php
Last active August 29, 2015 14:12
Get the node type of the current node using EntityFieldQuery (EFQ) API.
<?php
// Get the node id from the current page's URL.
$nid = arg(1);
// Create a new EFQ object.
$query = new EntityFieldQuery();
// Select the node entity with the target node id.
$query->entityCondition('entity_type', 'node');
@ranelpadon
ranelpadon / toolkit.drush.inc.php
Last active August 29, 2015 14:12
Custom Drush Commands Demo. Rename the file as toolkit.drush.inc ($ mv toolkit.drush.inc.php toolkit.drush.inc). Make it executable ($ sudo chmod a+x toolkit.drush.inc). Put this file in ~/.drush folder so that you will have now a ~/.drush/toolkit.drush.inc file.
<?php
/**
* Implements COMMANDFILE_drush_command().
*/
function toolkit_drush_command() {
$items = array();
// Command for Clear Cache All.
// The 'cca' array key is what you type in the terminal, like: drush cca.
@ranelpadon
ranelpadon / twitter_typeahead_with_tripadvisor_data.js
Created January 2, 2015 19:33
Sample integration of Twitter TypeAhead Library with a remote data server (TripAdvisor API).
MAPWIDGET = MAPWIDGET || {};
// Constructor function for TripAdvisor's TypeAhead behavior.
MAPWIDGET.Autocomplete = function(domElement) {
// TypeAhead Source URL per documentation of TripAdvisor.
// See http://api.tripadvisor.com/api/partner/2.0/doc?key=TA_KEY.
// %QUERY is a wildcard needed by the suggestion engine.
var typeAheadUrl = TripAdvisor_API_BASE_URL + '/typeahead/%QUERY?key=' + tripAdvisorKey;
// Create a new suggestion engine dedicated for the specified category.
@ranelpadon
ranelpadon / js_closures_in_loops.html
Last active August 29, 2015 14:12
Alternative implementations using immediately-invoked function expressions (IIFE) to Mozilla's sample codes for JS Closures in loops .
<html>
<head>
</head>
<body>
<!-- Base DOM markup and code logic here: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Closures -->
<p id="help">Helpful notes will appear here</p>
<p>E-mail: <input type="text" id="email" name="email"></p>
<p>Name: <input type="text" id="name" name="name"></p>
<p>Age: <input type="text" id="age" name="age"></p>