Skip to content

Instantly share code, notes, and snippets.

View henrytran9x's full-sized avatar

Andy Tran henrytran9x

  • Mercury
  • Vietnam
View GitHub Profile
@henrytran9x
henrytran9x / read.md
Created June 15, 2016 01:46
Add more triggers in ajax.js.

There have been a couple instances recently where I wanted to fire some custom handlers when particular events in ajax.js were invoked. It's possible I'm a bit off track with this and there may be an alternate solution, as admittedly jQuery is not my strongest language.

To give an example, suppose you wanted to manipulate a page element when Drupal.ajax.prototype.beforeSend is called. Up to this point, I would handle this by adding something along these lines in a custom .js file:

(function ($) {

// Drupal's core beforeSend function var beforeSend = Drupal.ajax.prototype.beforeSend;

@henrytran9x
henrytran9x / template.php
Created June 13, 2016 10:43
Superblog php
<?php
function superblog_preprocess_html(&$variables){
global $user;
$header = drupal_get_http_header('status');
if($header == '404 Not Found'){
$variables['classes_array'][] = 'page-full-fluid error404';
}
/** Tools Switch Style */
@henrytran9x
henrytran9x / .htaccess
Last active August 28, 2016 14:57
This config default Drupal .htaccess
#
# Apache/PHP/Drupal settings:
#
# Protect files and directories from prying eyes.
<FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl)(~|\.sw[op]|\.bak|\.orig|\.save)?$|^(\..*|Entries.*|Repository|Root|Tag|Template)$|^#.*#$|\.php(~|\.sw[op]|\.bak|\.orig\.save)$">
Order allow,deny
</FilesMatch>
# Don't show directory listings for URLs which map to a directory.
@henrytran9x
henrytran9x / demo.php
Last active May 16, 2016 07:05
This demo process multi radios used states
<?php
/*
....
This form had used 'vertical_tabs' and fieldset group to element 'group_check'
*/
$form['group_check'] = array(
'#type' => 'radios',
'#options' => array('type-a' => 'Type A','type-b' => 'Type B'),
);
@henrytran9x
henrytran9x / my.inc
Created March 28, 2016 08:16
This config mysql for jv_bigc
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# You can copy this file to
# D:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is D:/xampp/mysql/data) or
@henrytran9x
henrytran9x / gist:f40e4296e32313f5e470
Created March 26, 2016 07:40
Fix A weird lock-out Drupal 7
Very strange. Never heard of anything like this before. I would try the following after backing up your database:
Using phpMyAdmin, disable all the contributed and custom modules
UPDATE system SET status = 0 WHERE type = 'module' AND filename LIKE 'sites/%'
The clear the cache tables:
TRUNCATE TABLE cache;
TRUNCATE TABLE cache_block;
TRUNCATE TABLE cache_bootstrap;
TRUNCATE TABLE cache_field;
@henrytran9x
henrytran9x / config.txt
Created March 12, 2016 06:53
Config Setting User My Sublime Text
{
"color_scheme": "Packages/Theme - Cobalt2/cobalt2.tmTheme",
"theme": "Cobalt2.sublime-theme",
"highlight_line": true,
"indent_guide_options": [ "draw_normal", "draw_active" ],
"highlight_modified_tabs": true,
"line_padding_bottom": 1,
"line_padding_top": 1,
"wide_caret": true,
"caret_extra_bottom": 2,
@henrytran9x
henrytran9x / filter_array.php
Created February 25, 2016 02:59
Filter regex keys array
<?php
function array_filter_key($matches,array $array)
{
$matchedKeys = preg_grep($matches, array_keys($array));
return array_intersect_key($array, array_flip($matchedKeys));
}
@henrytran9x
henrytran9x / truncate-string-words.php
Created February 1, 2016 10:17 — forked from luizventurote/truncate-string-words.php
Truncate a string provided by the maximum limit without breaking a word.
<?php
/**
* truncate a string provided by the maximum limit without breaking a word
* @param string $str
* @param integer $maxlen
* @return string
*/
function truncateStringWords($str, $maxlen) {
if (strlen($str) <= $maxlen) return $str;
@henrytran9x
henrytran9x / mymodule.php
Created December 28, 2015 08:27
This module load field follow condition type field Drupal 7
<?php
public function load_fields($entity_type, $bundle_name) {
$instances = field_info_instances($entity_type, $bundle_name); // Load entity tye and bundle_name
$fields = array();
foreach($instances as $key => $instance) {
foreach($instance as $field_name => $instance_field)
{
$field_info = field_info_field($field_name);
if($field_info['type'] === 'text') { // Get Type Fields 'text' , You can conndition type other