Skip to content

Instantly share code, notes, and snippets.

View MatthieuScarset's full-sized avatar
🤷‍♂️
Probably me

MattGyver MatthieuScarset

🤷‍♂️
Probably me
View GitHub Profile
@MatthieuScarset
MatthieuScarset / emmet-html-default
Last active May 25, 2021 09:07
Emmet shortcode to create a default HTML5 template file.
<!--
EMMET CODE
Copy the two lines below
-->
<!DOCTYPE html>
html>(head(meta[charset=UTF-8]+title+meta[author]+meta[generator]+meta[name=keywords][content]+meta[name=description][content]+link[href][type=text/css][rel=stylesheet]+script[src][type=text/javascript])+body(header+main(section#.(h1(lorem5)+p*3(lorem))+section#.(h2(lorem5)+div.(p*2(lorem))))+footer>p(ul.nav-footer>li*3>a(lorem2))))
<!--
RESULT
@MatthieuScarset
MatthieuScarset / gist:162735b0796e82159e8f
Created July 16, 2015 07:35
Drupal - Select and update all users by role
<?php
// Select and update user by role
$role = user_role_load_by_name('blogger');
$query = 'SELECT ur.uid FROM {users_roles} AS ur WHERE ur.rid = :rid';
$result = db_query($query, array(':rid' => $role->rid));
$uids = $result->fetchCol();
$users = user_load_multiple($uids);
foreach($users as $user) {
// $user->field_to_update['und'][0]['value'] = 1;
// user_save($user);
@MatthieuScarset
MatthieuScarset / gist:7cbdab8b99c84451c858
Last active August 29, 2015 14:26
Drupal - Export $field and $instance
// Export fields and their instances
// for Drupal module development
// @see http://steindom.com/articles/exporting-and-creating-field-definitions-drupal-7
$entity_type = 'node';
$field_name = 'field_gallery_user_lname';
$bundle_name = 'gallery';
$info_config = field_info_field($field_name);
$info_instance = field_info_instance($entity_type, $field_name, $bundle_name);
$order_id = 8442; // change this to your order_id value
$order = commerce_order_load($order_id);
$shipping_profile_id = $order->commerce_customer_shipping[LANGUAGE_NONE][0]['profile_id'];
$address_shipping_profile = commerce_customer_profile_load($shipping_profile_id);
$as = $address_shipping_profile->commerce_customer_address['und'][0];
$billing_profile_id = $order->commerce_customer_billing[LANGUAGE_NONE][0]['profile_id'];
$address_billing_profile = commerce_customer_profile_load($billing_profile_id);
$ab = $address_billing_profile->commerce_customer_address['und'][0];
@MatthieuScarset
MatthieuScarset / gist:4709ec3bee691c1c7707
Created November 12, 2015 14:45
Load all Drupal Commerce License
$q = db_select('commerce_license', 'l');
// $q->condition('l.type', your_type');
// $q->condition('l.status', 2); // 2 = active
$q->fields('l', array('license_id') );
$lids = $q->execute()->fetchCol();
$ls = entity_load('commerce_license', $lids);
dpm($ls);
foreach($ls as $l){
$info = $l->wrapper->getPropertyInfo();
@MatthieuScarset
MatthieuScarset / gist:831d77bedc6338e66d00
Created December 16, 2015 16:54
make an element clickable
// How to use?
makeClick($('.clickable')); //Make things clickable
/*
* Make an HTML element clickable
* Usefull for a fully clickable div without to wrap it in a <a>
* @param $el jQuery DOM object(s)
* return void
*/
function makeClick($el) {
@MatthieuScarset
MatthieuScarset / WP - Plugin Dev - Show errors after activation
Last active June 19, 2016 08:13
WordPress - Show plugin activation errors
function show_activation_error() {
update_option( 'plugin_error', ob_get_contents() );
$error = get_option( 'plugin_error' );
wp_die($error);
}
add_action( 'activated_plugin', 'show_activation_error' );
@MatthieuScarset
MatthieuScarset / encode_file64
Last active February 15, 2016 08:05
PHP - encode_file64
<?php
// Encode a file to base64
function encode_file64($path, $print = false) {
$file = file_get_contents($path);
$e = base64_encode($file);
if( $print )
print ($e);
return $e;
}
@MatthieuScarset
MatthieuScarset / error.module
Created February 25, 2016 10:37
Drupal - Go to error page
/*
* Redirect to error page
* @param $site string Wether is for mobile or desktop site
* @param $err_code int Error code
* @param $path bool|string Force a path for redirection
* @see http://www.kobashicomputing.com/creating-custom-drupal-6-error-pages
* @return header()
*/
function _goto_error_page($site = 'mobile', $err_code = 404, $path = false) {
$variable_name = ($site == 'mobile') ? "site_mobile_$err_code" : "site_$err_code";
@MatthieuScarset
MatthieuScarset / JS - Get header
Created March 15, 2016 09:12
Get current page's header in Javascript
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send(null);
req.getResponseHeader('Date');