Skip to content

Instantly share code, notes, and snippets.

@shadcn
shadcn / gist:de147c42d7b3063ef7bc
Last active September 17, 2022 11:50
Convert a Hex string to UIColor in Swift
// Creates a UIColor from a Hex string.
func colorWithHexString (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(1)
}
if (countElements(cString) != 6) {
return UIColor.grayColor()
/**
* Display a day view.
*/
function template_preprocess_calendar_day(&$vars) {
$vars['view']->style_with_weekno = FALSE;
$view = $vars['view'];
$rows = $vars['rows'];
$item_count = 0;
$by_hour_count = 0;
@shadcn
shadcn / gist:8b4c6e2404825c387450
Created September 2, 2014 19:46
Switch Panopoly Layouts to Radix Layouts.
/**
* Replace Panopoly layouts with Radix Layouts
* @param $plugin
* @param $info
*/
function radix_ctools_plugin_post_alter(&$plugin, &$info) {
// If Radix Layouts module is installed.
// Switch all Panopoly Panels layouts to Radix Layouts.
if (module_exists('radix_layouts')) {
$radix_layouts_path = drupal_get_path('module', 'radix_layouts');
@shadcn
shadcn / gist:3f78074de48ae295b341
Created December 1, 2014 14:50
Cocoapods stuck on “analyzing dependencies”

Run the following:

$ pod repo remove master
$ pod setup
$ pod install
@shadcn
shadcn / gist:5ea3aa3a4ce4cd345aa8
Created December 9, 2015 06:33
Drupal + Bootstrap + Sass + Gulp + Browsersync + FontAwesome
Download and enable radix: drush en radix -y; drush vset theme_default radix
Create a subtheme: drush cc all; drush radix "Subtheme"
Set default theme: drush en subtheme -y; drush vset theme_default subtheme
Install required modules: cd /path/to/subtheme; npm run setup
Update browserSyncProxy in /path/to/subtheme/config.json
Watch: gulp
<?php
/**
* Implements hook_forms().
*/
function node_ajax_loader_forms($form_id, $args) {
$forms = array();
if (strncmp($form_id, 'node_ajax_loader_form_', 22) === 0) {
$forms[$form_id] = array('callback' => 'node_ajax_loader_form');
}
@shadcn
shadcn / create_menu_link.php
Last active September 10, 2018 09:33
Programmatically create a menu link in Drupal 8
@shadcn
shadcn / assign_permission.php
Last active April 20, 2016 18:28
Progammatically assign permissions to users in Drupal 8
<?php
use Drupal\user\RoleInterface;
// Allow anonymous and authenticated users to access contact form.
user_role_grant_permissions(RoleInterface::ANONYMOUS_ID, array('access site-wide contact form'));
user_role_grant_permissions(RoleInterface::AUTHENTICATED_ID, array('access site-wide contact form'));
@shadcn
shadcn / gist:cde26afc528a7bc7ae8d68ce658a8f2d
Created April 21, 2016 20:22
field_info_instance or how to get field info in Drupal 8
<?php
use Drupal\field\Entity\FieldConfig;
$info = FieldConfig::loadByName($entity_type, $bundle, $field_name);
@shadcn
shadcn / gist:4c79632956564f1d2ef321ad6aa83941
Created May 11, 2016 08:36
Drupal Element::children in Twig templates
{% for key, child in element if key|first != '#' %}
<div>{{ child }}</div>
{% endfor %}