Skip to content

Instantly share code, notes, and snippets.

@batandwa
batandwa / gosu.sh
Last active Sep 11, 2017
Docker and GoSu
View gosu.sh
#!/bin/sh
# Explained at https://stackoverflow.com/questions/36781372/docker-using-gosu-vs-user#37931896
set -x
# get gid of docker socket file
SOCK_DOCKER_GID=`ls -ng /var/run/docker.sock | cut -f3 -d' '`
# get group of docker inside container
CUR_DOCKER_GID=`getent group docker | cut -f3 -d: || true`
@batandwa
batandwa / ng-change-target.html
Created Dec 19, 2014
A work-arount to getting the target element in ng-change.
View ng-change-target.html
<input type="text" ng-focus="focusCallback($event)" ng-change="changeCallback()">
@batandwa
batandwa / setup.py
Created Nov 17, 2014
Commit changes to files in an SVN working copy
View setup.py
#!/usr/bin/python
# -*- coding: iso-8859-1 -*-
from distutils.core import setup
import py2exe
setup(
options = {"py2exe": {"compressed": 0, "optimize": 0, "bundle_files": 1, } },
zipfile = None,
console=["svnautocommit.py"]
)
@batandwa
batandwa / entityfieldquery.php
Created Aug 19, 2014
Drupal 7 Entities - Fetch entities using EntityFieldQuery.
View entityfieldquery.php
<?php
$entity_type = "node";
$bundle = "my_custon_content_type";
$query = new EntityFieldQuery();
$query
->entityCondition('entity_type', $entity_type)
->entityCondition('bundle', $bundle)
->fieldCondition('field_dwnl_file_content', 'value', 9);
@batandwa
batandwa / entity_wrapper_create.php
Created Aug 19, 2014
Drupal 7 Entities - Create an entity using the entity_metadata_wrapper class.
View entity_wrapper_create.php
<?php
// The entity and bundle we are working with
$entity_type = "node";
$bundle = "node";
// Instantiate the wrapper for the bundle
$entity = entity_create($entity_type, array('type' => $bundle));
$wrapper = entity_metadata_wrapper($entity_type, $entity);
// Check what fields are available to us.
@batandwa
batandwa / str_split.vb
Created Jul 9, 2014
Excel: Split a string by a delimiter
View str_split.vb
Function STR_SPLIT(str, sep, n) As String
Dim V() As String
V = Split(str, sep)
If (n < 0) Then
STR_SPLIT = V(UBound(V) + 1 + n)
Else
STR_SPLIT = V(n - 1)
End If
End Function
@batandwa
batandwa / xdebug_debugging.md
Last active Aug 29, 2015
Check list for debugging Xdebug remote debugging issues
View xdebug_debugging.md

Host

  1. Check that the Xdebug is installed and loaded on your host. Run a phpinfo() script?
  2. Is xdebug.remote_enable enabled?
  • Is the IP in xdebug.remote_host correct?

Client

  1. Does your xdebug.remote_port match what is set in your client?
  2. Is xdebug.remote_port open on your client?
@batandwa
batandwa / prefill_machine.js
Created Jun 27, 2014
Prefill Machine bookmarklet to auto-fill forms
View prefill_machine.js
(function(win, doc, $) {
'use strict';
// Don't run script if jQuery isn't loaded
if (typeof win.jQuery === 'undefined') {
return;
}
var data, fillForm, FormData, len, _rand;
@batandwa
batandwa / perm_names.js
Created Jun 21, 2014
Drupal 7 - Expose the machine names of permissions when viewing the permission table
View perm_names.js
// Go through each of the rows on the permissin table
rows = jQuery('#permissions tr');
rows.each(function() {
// Get the first checkbox in the row.
checkbox = jQuery('.checkbox .form-checkbox', this).first();
// Get the first cell, containing the permission label.
nameCell = jQuery('td:first-child', this);
// In case this is not a permission row
if(checkbox.length == 0) {
return;
@batandwa
batandwa / custom_block.php
Created Jun 12, 2014
Drupal 7 - Custom block hooks
View custom_block.php
<?php
/**
* Implements hook_block_info().
*/
function YOUR_MODULE_block_info() {
$blocks = array();
$blocks['YOUR_BLOCK_ABC'] = array(
'info' => t('YOUR BLOCK NAME'),
);