Skip to content

Instantly share code, notes, and snippets.

View abulte's full-sized avatar

Alexandre Bulté abulte

View GitHub Profile
@abulte
abulte / forms.html
Last active December 15, 2015 13:08 — forked from gnunicorn/forms.html
Jinja2 macros for TW Bootstrap, updated to work with 2.3.
<!-- https://gist.github.com/abulte/5264753 -->
{%- macro form_field_label(field) -%}
<label class="control-label" for="{{ field.id }}">{{ field.label.text }}
{%- if field.flags.required -%}
<abbr title="Required"> *</abbr>
{%- endif %}</label>
{% endmacro %}
{%- macro form_field_help(help) -%}
@abulte
abulte / geocode.py
Last active December 18, 2015 12:08
Geocode an address in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2013 Alexandre Bulté <alexandre[at]bulte[dot]net>
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
## Requirements
@abulte
abulte / mySampleMenusMigration.class.php
Last active May 30, 2019 13:12
Drupal menu creation with Migrate module from a CSV file - Got it from Google Cache of this page: http://www.mezasefi.com/d/en/blogs/nobu/2012-10-02/sample-migration-module-importing-menu-csv.html
<?php
class mySampleMenusMigration extends Migration {
public function __construct() {
parent::__construct(MigrateGroup::getInstance('mySampleMenusMigration'));
$this->description = t('Creates sample menues.');
// the csv file contains the header.
$dir = drupal_get_path('module', 'mySampleMigrate');
$this->source = new MigrateSourceCSV("$dir/sample_menus.csv", array(), array('header_rows' => 1));
@abulte
abulte / drupal-fetch-children-node-menu.php
Last active December 25, 2015 05:09
Fetch children node from the current menu in Drupal 7
<?php
// requires Menu Node API https://drupal.org/project/menu_node
$children = array();
$trail = menu_get_active_trail();
if (count($trail)) {
$current_item = $trail[count($trail) - 1];
$parameters = array(
'active_trail' => array($current_item['plid']),
@abulte
abulte / drupal-7-fetch-siblings-menu.php
Created October 24, 2013 12:05
Drupal 7 Fetch siblings of node in menu
<?php
// requires Menu Node API https://drupal.org/project/menu_node
// [ALB] ripped from submenutree.module
// Traverse down the tree to find our node, following in_active_trial
// This code stanza is loosely inspired by menu_set_active_trail()
$item = $current_item;
$tree = menu_tree_all_data($item['menu_name'], $item);
$my_tree = FALSE;
@abulte
abulte / entity_menu_links-depends-on-i18n_menu.patch
Last active December 27, 2015 07:28
Patch entity_menu_links to depend on i18n_menu #drupal
@abulte
abulte / htaccess
Created December 24, 2013 11:44
WordPress AngularJS CORS setup
# CORS Headers (add this)
<ifModule mod_headers.c>
Header always set Access-Control-Allow-Origin: "*"
Header always set Access-Control-Allow-Methods "POST, GET, PUT, DELETE, OPTIONS"
Header always set Access-Control-Allow-Headers "X-Requested-With, content-type"
</ifModule>
# BEGIN WordPress (you should have this in your original WP .htaccess)
<IfModule mod_rewrite.c>
RewriteEngine On
@abulte
abulte / gist:8112151
Last active May 14, 2016 16:30
Angular CORS *BAD* pratice
myApp.config(['$httpProvider', function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
]);
@abulte
abulte / directive.js
Last active January 2, 2016 20:29
Test fast click efficiency on mobile
module.directive('mesureTime', function() {
return {
restrict: 'A',
// require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
var timeTouch;
elm.on('click', function() {
if (timeTouch) {
alert(new Date().getTime() - timeTouch, " ms");
} else {
### Keybase proof
I hereby claim:
* I am abulte on github.
* I am abulte (https://keybase.io/abulte) on keybase.
* I have a public key whose fingerprint is 2AF6 528B BA92 D7AC 4F92 DF0B D126 E953 8D0C 3164
To claim this, I am signing this object: