Skip to content

Instantly share code, notes, and snippets.

View batandwa's full-sized avatar

Batandwa batandwa

View GitHub Profile
@batandwa
batandwa / gosu.sh
Last active September 11, 2017 18:37
Docker and GoSu
#!/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 December 19, 2014 09:40
A work-arount to getting the target element in ng-change.
<input type="text" ng-focus="focusCallback($event)" ng-change="changeCallback()">
@batandwa
batandwa / setup.py
Created November 17, 2014 09:19
Commit changes to files in an SVN working copy
#!/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 August 19, 2014 17:04
Drupal 7 Entities - Fetch entities using EntityFieldQuery.
<?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 August 19, 2014 14:27
Drupal 7 Entities - Create an entity using the entity_metadata_wrapper class.
<?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 July 9, 2014 09:45
Excel: Split a string by a delimiter
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 August 29, 2015 14:03
Check list for debugging Xdebug remote debugging issues

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 June 27, 2014 10:46
Prefill Machine bookmarklet to auto-fill forms
(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 June 21, 2014 12:36
Drupal 7 - Expose the machine names of permissions when viewing the permission table
// 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 June 12, 2014 13:06
Drupal 7 - Custom block hooks
<?php
/**
* Implements hook_block_info().
*/
function YOUR_MODULE_block_info() {
$blocks = array();
$blocks['YOUR_BLOCK_ABC'] = array(
'info' => t('YOUR BLOCK NAME'),
);