Skip to content

Instantly share code, notes, and snippets.

@augustyip
augustyip / gist:8b14e2db3d226a32f6dc
Last active December 23, 2015 19:29
CHECK REMOTE FILE EXISTS
<?php
// CHECK REMOTE FILE EXISTS
function remote_file_exists( $url_file ) {
$url_file = trim( $url_file );
if ( empty( $url_file ) )
return FALSE;
$url_arr = parse_url( $url_file );
if ( !is_array( $url_arr ) || empty( $url_arr ) )
return FALSE;
@augustyip
augustyip / cleaner.php
Created September 24, 2013 09:39
Identifies php files that contain leading or trailing spaces before or after PHP opening or closings tags
<?php
/***********************
*@author: Ritesh Agrawal
*@description: Identifies php files that contain leading or trailing spaces before or after PHP opening or closings tags
*@version: 1.0
*@date: Nov 06, 2007
@todo – check only *.PHP or *.CTP files rather than checking all of the files
– html based output
***********************/
//Set Source Path
@augustyip
augustyip / gist:10242319
Created April 9, 2014 08:38
Drupal generates form by fields' setings
<?php
foreach ($fields as $field_name) {
$field = field_info_field($field_name);
$instance = field_info_instance('node', $field_name, $field['bundles']['node'][0]);
$form_field = field_default_form('node', null, $field, $instance, LANGUAGE_NONE, array(), $form, $form_state);
$form += (array) $form_field;
}
@augustyip
augustyip / gist:10242921
Created April 9, 2014 08:45
Drupal Views data to jqGrid ajax data mapping
<?php
function views_to_jqgrid_ajax_data($view_name){
$result = array();
$_GET['page'] = intval($_REQUEST['page']) > 0
? intval($_REQUEST['page']) - 1 : intval($_REQUEST['page']);
$_GET['order'] = $_REQUEST['sidx'];
$_GET['sort'] = $_REQUEST['sord'];
@augustyip
augustyip / gist:10245177
Created April 9, 2014 09:10
Drupal: Displays the output of a view, assumed to be a block display.
<?php
/**
* Displays the output of a view, assumed to be a block display.
*
* @param $view_name
* Machine name of the view.
* @param $display_name
* Machine name of the display within the view.
* @param $args
* (optional) Array of arguments for the view display.
@augustyip
augustyip / gist:f0c6b532ca0b303820a7
Created May 20, 2014 04:07
To get a nested tree in Drupal 7
<?php
function taxonomy_get_nested_tree($terms = array(), $parent = 0, $parents_index = array(), $max_depth = NULL, $depth = 0) {
foreach ($terms as $term) {
foreach ($term->parents as $term_parent) {
if ($term_parent == $parent) {
$return[$term->tid] = $term;
}
else {
$parents_index[$term_parent][$term->tid] = $term;
}
@augustyip
augustyip / gist:3dd57bca5a07190d873f
Created June 11, 2014 09:25
Adding a parameter to the URL with JavaScript
function addParam(url, param, value) {
var a = document.createElement('a'), regex = /[?&]([^=]+)=([^&]*)/g;
var params = {}, match, str = []; a.href = url; value=value||"";
while (match = regex.exec(a.search))
if (param != match[1]) str.push(match[1] + "=" + match[2]);
str.push(encodeURIComponent(param) + "=" + encodeURIComponent(value));
a.search = (a.search.substring(0,1) == "?" ? "" : "?") + str.join("&");
return a.href;
}
<?php
Class perRequestCache {
private static $cache = array();
public static function get($key) {
return self::$cache[$key];
}
public static function set($key, $value) {
@augustyip
augustyip / gist:1036acee73040af8008a
Created June 25, 2014 04:17
Break x,y,z and x+y+z into an array. Numeric only.
/*
* Break x,y,z and x+y+z into an array. Numeric only.
*
* @param $str
* The string to parse.
*
* @return $object
* An object containing
* - operator: Either 'and' or 'or'
* - value: An array of numeric values.
@augustyip
augustyip / gist:9b730e9a6aabfd00d1e0
Last active August 29, 2015 14:03
Linux Commands
#Copy Files With Rsync Over SSH
rsync -avz -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" --progress /root/bigfile.txt username@198.211.117.129:/
# Mysql search tables
SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'drupal_bcsiem' AND TABLE_NAME LIKE "commerce%";
# Export only modified and added files with folder structure in Git