Skip to content

Instantly share code, notes, and snippets.

View henryhu712's full-sized avatar

henryhu henryhu712

View GitHub Profile

Spf13.vim lost syntax when editing PHP

Fix it with set

:syn on

Reference: spf13/PIV#15

@henryhu712
henryhu712 / wp_get_all_posts_of_a_type.php
Last active March 23, 2016 05:22
Wordpress - Get all posts of a custom type 'campaign' #wordpress
$loop = new WP_Query( array(
'post_type' => 'campaign',
'posts_per_page' => -1, // It will return all posts.
));
while ( $loop->have_posts() ) {
$loop->the_post();
$post_id = get_the_ID();
$post_title = get_the_title();
}
@henryhu712
henryhu712 / git_config.md
Last active March 27, 2016 22:03
git config

How many config files for git?

There are 3 places where we can set git config:

  • /etc/gitconfig

This is globe config. Write and read its settings:

git config --system ...
@henryhu712
henryhu712 / multiple_value_select.md
Created March 28, 2016 09:27
Multiple values select

HTML

HTML structure

<label for="select-age">AGE</label>
<select id="select-age" multiple="multiple" size="5" name="age[]">
    <option value="under20" selected="selected">Under 20</option>
    <option value="20-24" selected="selected">20-24</option>

25-34

$HOME/.my.cnf

Put the following content in the .my.cnf file:

[client]
user = username
passowrd = yourpassword

Then, you can login like this:

It does not work to set expandtab off if you just comment out "set expandtab" in .vimrc. Instead, set under it as follows:

set expandtab

set noexpandtab

git show bd61ad98 // Show detailed modification

@henryhu712
henryhu712 / redirect_form_submit.md
Created April 11, 2016 07:59
Redirect form submit on Drupal 7

In hook_form_alter(), there are 2 methods:

function MYMODULE_form_alter(&$form, &$form_state, $form_id) {
  if ($form_id == 'user_pass') {
    $form['#submit'][] = 'reflesh_current_path';
  }
}
function reflesh_current_path($form, &$form_state) {
  $current_path = current_path();

$form_state['redirect'] = $current_path;

@henryhu712
henryhu712 / email_login.md
Last active April 12, 2016 03:03
Email login only, not email registration

The solution is from the issue:

logintoboggan module allows to register & login with email. user_registrationpassword module allows to set password and emai validation both configuration. But it does NOT work for both modules together.

Solution:

  • Enabled user_registrationpassword;
  • Abandon logintoboggan, instead, implement email login with the following:
@henryhu712
henryhu712 / drupal_global_variables.md
Created April 14, 2016 02:51
Drupal 7 global variables

Custom Global Variables in Drupal

It is strange that I can't get global variables in Drupal 7 with &drupal_static or $GLOBALS. Eventually $_SESSION['myVar'] successes.

Note that to remember to initiate your $_SESSION variables before using them.