Skip to content

Instantly share code, notes, and snippets.

View mrsinguyen's full-sized avatar
🎯
Focusing

Si Nguyen mrsinguyen

🎯
Focusing
View GitHub Profile
/**
* Get URI parameter.
*
* @param string $str
* Example to use $str urldecode(drupal_get_destination()).
* @return array
*/
function _more_node_buttons_get_params($str) {
$chunks = explode("?", $str);
$params = explode("&", $chunks[1]);
<?php
/**
* Implements hook_url_outbound_alter() - from URL Alter module
*/
function YOURMODULE_url_outbound_alter(&$path, &$options, $original_path) {
// Rewrite paths for rices4peru.com
if ($_SERVER['HTTP_HOST'] == "www.rices4peru.com") {
$options['absolute'] = TRUE;
<?php
/**
* SplClassLoader implementation that implements the technical interoperability
* standards for PHP 5.3 namespaces and class names.
*
* http://groups.google.com/group/php-standards/web/final-proposal
*
* // Example which loads classes for the Doctrine Common package in the
* // Doctrine\Common namespace.
<?php
class ServicesContext implements ArrayAccess {
protected $handlers;
protected $namespaces;
private $values = array();
function __construct($handlers = array(), $namespaces = array()) {
$this->handlers = $handlers;
$this->namespaces = $namespaces;
<?php
/**
* Implements hook_url_outbound_alter() - from URL Alter module
*/
function YOURMODULE_url_outbound_alter(&$path, &$options, $original_path) {
// Rewrite paths for rices4peru.com
if ($_SERVER['HTTP_HOST'] == "www.rices4peru.com") {
$options['absolute'] = TRUE;
<?php
// Parsing this spreadsheet: https://spreadsheets.google.com/pub?key=0Ah0xU81penP1dFNLWk5YMW41dkcwa1JNQXk3YUJoOXc&hl=en&output=html
$url = 'http://spreadsheets.google.com/feeds/list/0Ah0xU81penP1dFNLWk5YMW41dkcwa1JNQXk3YUJoOXc/od6/public/values?alt=json';
$file= file_get_contents($url);
$json = json_decode($file);
$rows = $json->{'feed'}->{'entry'};
foreach($rows as $row) {
echo '<p>';
@mrsinguyen
mrsinguyen / gist:1028786
Created June 16, 2011 06:38
Github search scraping
/*
Usage: io github <query> [language]
io github django
io github coffeescript
To limit search results to a certain language:
io github django python
To see debug info:
io --debug github django
@mrsinguyen
mrsinguyen / .vimrc
Created July 27, 2011 03:10 — forked from jeresig/.vimrc
VIM Config
au BufRead,BufNewFile jquery.*.js set ft=javascript syntax=jquery
set nocompatible
set autoindent
set tabstop=2
set showmatch
set vb t_vb=
set ruler
set nohls
set incsearch
syntax on
@mrsinguyen
mrsinguyen / drupal-syslog-parser.js
Created November 30, 2011 02:05 — forked from benbuckman/drupal-syslog-parser.js
node.js script to parse Drupal logs in linux syslog (and find distinct 404'd URLs)
// drupal log parser w/ node.js
// takes a filtered syslog file
// run as node `drupal-syslog-parser.js LOGPATH`
// [install dependencies (lazy,underscore) first with `npm install ___`]
var lazy = require('lazy')
, fs = require('fs')
, path = require('path')
, _ = require('underscore');
@mrsinguyen
mrsinguyen / custom.module
Created December 28, 2011 02:35 — forked from mattfarina/custom.module
Protocol Relative URLs in Drupal 7
<?php
/**
* Implements hook_file_url_alter().
*
* Make all URLs be protocol relative.
* Note: protocol relatice URLs will cause IE7/8 to download stylesheets twice.
* @see http://www.stevesouders.com/blog/2010/02/10/5a-missing-schema-double-download/
*/
function custom_file_url_alter(&$url) {