Skip to content

Instantly share code, notes, and snippets.

View batandwa's full-sized avatar

Batandwa batandwa

View GitHub Profile
@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 / 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 / checked.js
Created July 18, 2012 12:40
jQuery - Get the checked items in group of checkboxes.
var checked = [];
$("input[name='items[]']:checked").each(function () {
checked.push($(this).val());
});
@batandwa
batandwa / dump.py
Created May 5, 2014 08:51
A configurable python script that wraps around mysqldump with some additional configuration.
#!/usr/bin/python
# Run with:
# python hello.py cameron
# python hello.py
# import modules used here -- sys is a very standard one
import sys
import subprocess
@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 / path_search.php
Last active January 3, 2016 14:09
Drupal - Prints the details of paths that starts with the specified search string.
<?php
function HOOK_menu_alter(&$items) {
$search = 'node/';
foreach ($items as $path => $options) {
if(strpos($path, $search) === 0) {
drupal_set_message('<strong>' . $path . '</strong><pre>'.var_export($options, TRUE).'</pre>', 'status', FALSE);
}
}
}
@batandwa
batandwa / vmtobox.sh
Last active January 3, 2016 00:39
Vigrant - Export a VirtualBox VM and import it as a Vagrant box
#!/bin/bash
if [ -z "$2" ];then
echo "We need two parameters, boet."
echo " Usage: $FUNCNAME vagrant-name vbox-machine-name"
return 1
fi
export lowername=$2
export tempdir=createvmbox.$((RANDOM))
@batandwa
batandwa / flush_style_images.php
Last active January 2, 2016 17:29
Drupal 7 - Removes all the style images generated so new ones can be created when needed.
<?php
module_load_include('module', 'image');
$styles = array_keys(image_styles());
image_style_flush($styles);
drupal_set_message(t('Flushed images for the following styles: %styles.', array('%styles' => implode(', ', $styles))), 'status', FALSE);
@batandwa
batandwa / admin_links.css
Created September 6, 2013 07:08
Drupal 7 Panels fix for contextual/admin links position
@batandwa
batandwa / conemu.py
Created July 3, 2013 08:15
Sublime Text 2 plugin for launching ConEmu.
import sublime, sublime_plugin, os, subprocess
class ConemuCommand(sublime_plugin.TextCommand):
def run(self, edit):
if os.name == "nt":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen(('c:/Program Files (x86)/ConEmu/ConEmu.exe', '/single', self.view.file_name()),