Skip to content

Instantly share code, notes, and snippets.

View vkareh's full-sized avatar

Victor Kareh vkareh

View GitHub Profile
<?php
/**
* Implements hook_form_FORM_ID_alter() for views_exposed_form.
*/
function MODULE_form_views_exposed_form_alter(&$form, &$form_state) {
$form['#after_build'] = array('_MODULE_apply_js');
}
function _MODULE_apply_js($form, &$form_state) {
function MODULE_form_alter(&$form, &$form_state, $form_id) {
if ($form_id == 'views_exposed_filters') {
$form['field_date_value_year']['#attributes']['autocomplete'] = 'off';
$form['field_date_value_month']['#attributes']['autocomplete'] = 'off';
}
}
/**
* Hook to register the CKEditor plugin - it would appear in the plugins list on the profile setting page.
*/
function hook_ckeditor_plugin() {
return array(
'plugin_name' => array(
// Name of the plugin used to write it.
'name' => 'plugin_name',
// Description of the plugin - it would be displayed in the plugins management section of profile settings.
'desc' => t('Plugin description'),
@vkareh
vkareh / console.js
Last active December 18, 2015 05:09
console.log() of object snapshots... needs jQuery
var consoleLog = console.log;
console.log = function() {
consoleLog.apply(this, $.map(arguments, function(obj) {
return $.isPlainObject(obj) ? $.extend(true, {}, obj) : obj;
}));
}
@vkareh
vkareh / passport-drupal-middleware.js
Last active December 19, 2015 07:28
passport-drupal express middleware
var passport = require('passport')
, express = require('express')
, app = express();
// Passport session setup.
passport.serializeUser(function(user, done) {
done(null, user);
});
passport.deserializeUser(function(user, done) {
done(null, user);
if (!('indexOf' in Array.prototype)) {
Array.prototype.indexOf= function(find, i) {
if (i===undefined) i= 0;
if (i<0) i+= this.length;
if (i<0) i= 0;
for (var n= this.length; i<n; i++)
if (i in this && this[i]===find)
return i;
return -1;
};
@vkareh
vkareh / noop.js
Created August 15, 2014 18:00
(a)synchronous noop function for node.js
module.exports = function(callback) {
if (callback) {
process.nextTick(callback);
}
}
@vkareh
vkareh / trello-highlight.js
Last active August 29, 2015 14:07
Highlights Trello cards in which you are a member
setTimeout(function() {
var name = $('.header-user img.member-avatar').attr('title');
$('.js-member-on-card-menu img[title="' + name + '"]').each(function() {
$(this).parents('.list-card-details').css('background-color', '#fcaf3e');
});
}, 2000);
@vkareh
vkareh / node-async-json.js
Created November 14, 2014 19:33
Wrapper around JSON.parse and JSON.stringify to make them run asynchronously. Also gets rid of having to use a try/catch on JSON.parse()
module.exports = {};
module.exports.parse = function parse() {
var args = Array.prototype.slice.call(arguments);
var callback = args.pop();
var _this = this;
process.nextTick(function() {
try {
var obj = JSON.parse.apply(_this, args);
return callback.apply(_this, [null, obj]);
@vkareh
vkareh / dbFields.js
Last active December 3, 2021 19:46
MongoDB script that returns a flattened list of all fields ever used on a specific collection
// Return a flattened list of all fields ever used on a MongoDB collection.
// Usage: `mongo --quiet <database> dbFields.js`
// Collection for which to get fields
var collection = 'users';
// Determines how to represent the keys of an array of objects.
// This allows for differentiating between nested objects and nested arrays of objects.
//
// e.g. for a document