Skip to content

Instantly share code, notes, and snippets.

@marioangulo
marioangulo / cheatsheet_react.markdown
Last active March 22, 2018 20:26
Cheat sheet for React

Setting Up Server

To Start Server

live-server /public

Babel

Babel Presets

babel src/app.js --out-file=public/scripts/app.js --presets=env,react
@marioangulo
marioangulo / drupal_ajax.js
Created June 7, 2017 22:01
Drupal Ajax Example
(function($) {
Drupal.behaviors.myModule = {
'attach': function(context) {
$('#edit-field', context).click(function(e) {
$.ajax({
url: 'http://www.example.com',
success: function(data) {
console.log(data);
},
error: function(data) {
@marioangulo
marioangulo / multiple_decoding.php
Last active January 15, 2016 21:53
Decoding Items Encoded Multiple Times
<?php
/**
* Loops through string to detect multiple encoding to be able to decode all levels.
*
* @param String $string
* The string you want to detect encoding on to be able to decode all its levels.
*
* @return String $string
* Clean decoded string.
*/
@marioangulo
marioangulo / hide_group_fields.php
Last active September 30, 2015 19:29
Drupal Hide Group/Sub Groups
<?php
/**
* Helper function to hide group and sub groups from a form.
*
* @param $form
* Reference to a nested array of form elements that comprise the form.
* @param $group_names
* Array containing the names of the groups you want to hide.
*/
function field_group_hide_field_groups(&$form, $group_names) {
@marioangulo
marioangulo / field_type_changer.php
Created July 30, 2015 16:50
Field Type Changer
<?php
class FieldChangeHelper {
/**
* Change a field's type, even if it has data.
*
* @param $field_name
* The name of the field to change.
* @param $type

In a module file:

This will enable an additional view mode for use on the specified entity type(s). Many examples will show the custom settings here being set to TRUE. If TRUE is used then that view mode is added to all entities of the specified type regardless of if it should be on the bundle or not.

/**
 * Implements hook_entity_info_alter().
 */
function HOOK_entity_info_alter(&$entity_info) {
@marioangulo
marioangulo / drush_field_info.drush
Created October 8, 2014 19:36
Drush Field Info
<?php
/**
* @file
* Drush commands for displaying info on fields and field instances.
*
* To use, save this file as drush_field_config.drush.inc in your home directory's .drush/ folder.
*/
/**
* Implements hook_drush_command().
@marioangulo
marioangulo / change_max_length.php
Created September 18, 2014 21:09
Drupal 7 Change Field Max Length Function
<?php
/*
* Utility to change the max length of a text field
*/
function change_text_field_max_length($field_name, $new_length) {
$field_table = 'field_data_' . $field_name;
$field_revision_table = 'field_revision_' . $field_name;
$field_column = $field_name . '_value';
// Alter value field length in fields table
@marioangulo
marioangulo / screen_size_redirect.js
Created September 16, 2014 19:03
Redirect Based of Screen Size
function determineIfSmallSize(redirect_url) {
// Detect pixel ratio for true resolution
window.dpr = 1;
if(window.devicePixelRatio !== undefined) {
window.dpr = window.devicePixelRatio;
}
// Screen orientation - innerWidth and innerHeight works for any device and its orientation, including desktops
@marioangulo
marioangulo / 0_reuse_code.js
Last active August 29, 2015 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console