Skip to content

Instantly share code, notes, and snippets.

@brycefisher
brycefisher / .vimrc
Last active December 18, 2015 05:39
Drupal Optimized Crossplatform vimrc
"-------About-----
" I use this .vimrc and the accompanying git repo of plugins,
" colorschemes, and other config files on Windows Vista,
" Windows 7, Ubuntu 12.04, and Mac OSX 10.7 on a daily basis.
"
" Pull requests and comments welcome!
"------INSTALLATION---
" $ git clone --recursive https://github.com/brycefisher/vimfiles.git ~/.vim
@brycefisher
brycefisher / .htaccess
Created June 8, 2013 07:24
Supercharge your DIY CDN with mod_expires, mod_deflate, and then lock it down a bit.
# Security
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule \.bat$ - [R=404]
</IfModule>
# Leverage Browser Caching
<IfModule mod_expires.c>
# Enable Expirations
@brycefisher
brycefisher / .bashrc
Last active December 20, 2015 16:09
msysgit .bashrc
alias gvim='/c/Program\ Files\ \(x86\)/Vim/vim73/gvim.exe '
alias expl='explorer '
alias ga='git add '
alias gb='git branch '
alias gc='git commit -m'
alias gp='git push'
alias gs='git status '
alias dld='cd /d/MySQL/drupal && ./drupal-db-download.sh'
<p>To setup this bookmarklet in your browser, you'll need to:</p>
<ol>
<li>Clone (or download) this gist using the information on this page</li>
<li>Fill in your username and password</li>
<li>Change the drupal_domain variable to the domain of your drupal install</li>
<li>(Possibly) change the path to the path to your drupal login form</li>
<li>Drag the link to your bookmark bar</li>
</ol>
<p>To use, simply click the bookmark anywhere on your drupal_domain.</p>
<a href="javascript: (function(){ var user = 'username', pw = 'password', path = '/user/login', drupal_domain = '.example.com', domain = window.location.host, frame = document.createElement('iframe'), frame_length = frames.length; if(domain.indexOf(drupal_domain) !== -1){ document.body.appendChild( frame ); frame.src = '//' + domain + path; frame.style.display = 'none'; setTimeout(function() { frames[frame_length].document.getElementById('edit-name').value = user; frames[frame_length].document.getElementById('edit-pass').value = pw; frames[fr
@brycefisher
brycefisher / scan_dir_for_non_utf8.php
Created September 19, 2013 17:15
Scan a directory for NON utf8 files using PHP
<?php
// Note this is NOT recursive.
function scan_dir_for_non_utf8($dir_path) {
if ($dir = opendir($dir_path)) {
echo "opening $dir_path";
$files_scanned = 0;
while (($file = readdir($dir)) !== false) {
// Don't go up directory levels
if (in_array($file, array('.','..')))
continue;
@brycefisher
brycefisher / find_deep_needle.php
Last active December 25, 2015 00:29
Like var_dump, but it prints out the whole expression "path" to the given string.
<?php
/**
* Like var_dump, but it prints out the whole expression "path" to the given string.
*
* @param mixed $haystack
* The object or array with many levels of nested arrays or objects containing your needle
* @param str $php_exp
* The php expression for the initial $haystack param
* @return str
* No return value. Prints output to stdout (assumed to be a browser).
@brycefisher
brycefisher / gist:7030684
Created October 17, 2013 19:20
Create Related Partner Nodequeue
/**
* Create a nodequeue.
*/
function _brightcove_marketing_solutions_create_nodequeue() {
$nodequeue = new stdClass;
// $nodequeue->api_version = 2;
$nodequeue->name = 'marketing_solutions_related_partners';
$nodequeue->title = 'Marketing solutions - related partners';
$nodequeue->subqueue_title = '';
$nodequeue->size = 0;
@brycefisher
brycefisher / gist:7328057
Created November 5, 2013 23:12
drupal - create arbitrary number of placeholders for a SQL injection resistant db_query() call
<?php
$nids = array(1, 2, 3, 4, 5);
// This is the key piece to understand -- it creates as many placeholder as you want based on the length of $nids array.
$placeholders = implode(',', array_fill(0, count($nids), '%d'));
$results = db_query("
select r.title
from {node_revisions} r
join {node} n
@brycefisher
brycefisher / gist:7344428
Created November 6, 2013 21:29
Drupal6: Create dummy translations of all nodes in a content type via drush script
<?php
/**
* @file
* This is a drush script designed to create fake translations of the genera pages for development purposes ONLY.
*
* NOTE:
* -----
* This file must be located somewhere inside the drupal root.
*
* USAGE:
@brycefisher
brycefisher / settings.php
Created November 12, 2013 16:55
How to Retrieve Environment Variables in Drupal settings.php
<?php
//...
// Store the database credentials serialized in an environmental variable.
$db_creds = unserialize(getenv('DRUPAL_DB_CRED'));
$databases = array (
'default' =>
array (
'default' => $db_creds,