Skip to content

Instantly share code, notes, and snippets.

View martsie's full-sized avatar

Marton Bodonyi martsie

View GitHub Profile
@martsie
martsie / gist:af08035fbab0fe396cb6
Last active August 29, 2015 14:24
Making views table filters take precedence over sort criteria
<?php
/**
* Implements hook_views_query_alter().
*
* By default, views will make sort criteria take precedence over views table sorts when
* "Override normal sorting if click sorting is used" is unticked. This is not ideal when
* you want the user initiated sorting to be secondary sorted on another column.
*/
function hook_views_query_alter(&$view, &$query) {
// Reverse the query order. Note if you have more than one sort criteria,
@martsie
martsie / gist:8d4306b1bc0134d189ac
Created July 6, 2015 01:59
Drupal add distinct filtering for a single field of a Views database query.
<?php
/**
* Implements hook_query_alter().
*
* This hook will make it so your Drupal views are filtered by unique on a single field value.
*
* Make sure to tag your views query first by going to 'Query Settings: settings' configuration
* in Views UI and, under 'Query Tags', adding 'MY_AWESOME_TAG' or whatever you're using.'
*/
function hook_query_alter(QueryAlterableInterface $query) {
@martsie
martsie / my_custom_module.install.php
Last active August 29, 2015 14:27
Give all permissions back to the admin role
<?php
/**
* Give admin role permissions to all modules on site.
*/
function my_custom_module_update_7001() {
$permissions = array();
foreach (module_implements('permission') as $module) {
$module_permissions = module_invoke($module, 'permission');
@martsie
martsie / assign.js
Created January 25, 2017 08:30
Batch assign Drupal module permissions to admin role from permissions page
// Paste this into your console.
// Change 'rid' variable value to be the role id you are modifying.
var rid = 3; jQuery('input.rid-' + rid).prop('checked', true);
@martsie
martsie / backbone-model.coffee
Created January 25, 2017 08:34
Most basic backbone model implementation in CoffeeScript
# Define the model.
class Comment extends Backbone.Model
# Create a new instance of the model.
comment = new Comment
@martsie
martsie / backbone-model-defaults.coffee
Created January 25, 2017 08:35
Backbone model in CoffeeScript with default values
# Define the model.
class Comment extends Backbone.Model
defaults:
name: 'test'
email: '[email protected]'
body: 'BODY'
# Create a new instance of the model.
comment = new Comment
name: 'Overriden name'
@martsie
martsie / backbone-collection.coffee
Created January 25, 2017 08:36
Backbone collection in CoffeeScript
# Define the collection.
class CommentCollection extends Backbone.Collection
model: Comment
# Create a new instance of the collection.
comments = new CommentCollection
# Add a few comments to the collection.
collection.add [
{name: 'Comment 1'},
@martsie
martsie / backbone-model-collection-resource.coffee
Created January 25, 2017 08:38
Backbone model and collection implementation with external resource in CoffeeScript
# Define the model.
class Comment extends Backbone.Model
defaults:
name: 'test'
email: '[email protected]'
body: 'BODY'
# Define the collection.
class CommentCollection extends Backbone.Collection
model: Comment
@martsie
martsie / coffee-script-class.coffee
Created January 25, 2017 08:43
Simple example of a class in CoffeeScript
class @Person
firstName: 'John'
lastName: 'Doe'
constructor: (@firstName, @lastName) ->
fullName: ->
return "#{@firstName} #{@lastName}"
@martsie
martsie / coffee-script-class-test.coffee
Created January 25, 2017 08:44
Qunit test class for a CoffeeScript class
QUnit.module 'Person class'
test 'Full name is printed correctly', ->
person = new Person('James', 'Bond')
equal 'James Bond', do person.fullName, 'Full name was printed correctly'