Skip to content

Instantly share code, notes, and snippets.

@admataz
admataz / gist:e3e196033faf11d5a2b7
Last active August 29, 2015 14:23
gmail search unlabelled mail
-has:userlabels -in:sent -in:chat -in:draft -in:inbox -in:bin
@admataz
admataz / gist:ece2ada06470c43ceace
Created June 5, 2015 20:07
merging passed with default options for javascript functions

As extracted from keystone.js utils

/**
 * Copies and merges options with defaults.
 *
 * @param {Object} defaults
 * @param {Object} options
 * @return {Object} the options argument merged with defaults
@admataz
admataz / gist:0ea2f12708115addc618
Last active August 29, 2015 14:22
Collected cURL commands

POST file contents as attachment to an endpoint

curl -X "POST" -i -F filedata="@test/data/fake_users_api.json" http://localhost:3000/api/v1/users/uploadBulk`
@admataz
admataz / gist:810d7a1bfeae0130cc43
Last active August 29, 2015 14:22
collected docker commands

create persistent mysql data container run it as a volume to the database:

docker create --name data-container-name -v /var/lib/mysql -p 3306:3306 mysql
docker run -it --name=mysql --volumes-from data-container-name -e MYSQL_ROOT_PASSWORD=123 -p 3306:3306  -d mysql

launch mysql command from host:

@admataz
admataz / config.js
Last active August 29, 2015 14:21
Using nconf to manage hierarchical configuration
/**
* Using nconf to manage hierarchical configuration
* https://www.npmjs.com/package/nconf
*/
'use strict';
var nconf = require('nconf');
var config = {
@admataz
admataz / calc_aspect_ratio
Created March 10, 2015 13:14
simple function helps calculate resized dimensions while keeping w/h aspect ratio
<?php
function calc_aspect_ratio($w=0,$h=0,$image_dimensions=array()){
//work out some ratios for the resized dimensions
if($w){
$w_ratio=$w/$image_dimensions[0];
} else {
$w_ratio=1;
}
if($h){
$h_ratio=$h/$image_dimensions[1];
@admataz
admataz / gist:140def49ef7de3987e30
Created September 22, 2014 16:29
Drupal: useful functions I discover every day
  • usehook_inline_entity_form_table_fields_alter(&amp;$fields, $context) to customise the way it looks in the CMS form
@admataz
admataz / gist:7cb85499e97d71087270
Created September 10, 2014 13:19
Drupal: Create a node programmatically
<?php
function make_node_programmatically()($title) {
global $user;
$node = new stdClass(); // We create a new node object
$node->type = "pages"; // Or any other content type you want
$node->title = $title;
$node->language = LANGUAGE_NONE;
node_object_prepare($node); // Set some default values.
$node->uid = $user->uid; // Or any id you wish
$node = node_submit($node); // Prepare node for a submit
@admataz
admataz / jqp.js
Last active December 25, 2015 22:19
Load a locally-scoped version of jquery using AMD/require.js - for when the existing site has an older version, and you need the more recent version for your modules. see http://requirejs.org/docs/jquery.html#noconflictmap.
//define a module that returns a noConflict version of jQuery
define(['jquery'], function (jq) {
return jq.noConflict( true );
});
@admataz
admataz / functions.php
Created February 18, 2013 17:33
Base Starter for a WordPress Theme functions.php file
<?php
new ThemeName();
class ThemeName {
/**
* Starting off…
*/
function __construct() {
//add_editor_style();