Skip to content

Instantly share code, notes, and snippets.

View purplexa's full-sized avatar

Lexa Whitehurst purplexa

View GitHub Profile
<?php
if ($hour < 9) {
$time = 0;
}
else if ($hour > 21) {
$time = 5;
}
else {
$time = floor(($hour - 6) / 3)
}
@purplexa
purplexa / gist:9128965
Created February 21, 2014 04:50
Reversing an EntityReference direction in Drupal Migrate
<?php
/**
* This is the content type which should have the EntityReference field in the new site.
*/
class MainContentTypeMigration extends DrupalNode6Migration {
public function __construct(array $arguments) {
parent::__contstruct($arguments);
$this->addFieldMapping('my_new_field', 'my_old_field');
@purplexa
purplexa / gist:92772edb36315c3cee7e
Created June 10, 2014 18:35
Variable-based solr settings
<?php
/**
* Implements hook_default_search_api_server_alter().
*
* Override the Solr server options to load from a variable.
*/
function example_default_search_api_server_alter(array &$defaults) {
$defaults['drupal_solr']->options['host'] = variable_get('drupal_solr_host', 'localhost');
$defaults['drupal_solr']->options['port'] = variable_get('drupal_solr_port', '8983');
$defaults['drupal_solr']->options['path'] = variable_get('drupal_solr_path', '/solr/drupal');

Bagels

Ingredients

  • 2 tsp. active dry yeast
  • 1 ½ tsp. sugar
  • 1 ¼ C. warm water (¼ C. extra if needed)
  • 3 ½ C. bread flour
  • 1 ½ tsp. salt

Instructions

@purplexa
purplexa / bash_prompt.sh
Last active August 29, 2015 14:05
My fancy bash prompt
function prompt_command {
local RED="\[\033[0;31m\]"
local GREEN="\[\033[0;32m\]"
local YELLOW="\[\033[0;33m\]"
local BLUE="\[\033[0;34m\]"
local MAGENTA="\[\033[0;35m\]"
local CYAN="\[\033[0;36m\]"
local CRESET="\[\033[0m\]"
if git branch >/dev/null 2>/dev/null; then
@purplexa
purplexa / sample.pl
Created August 13, 2015 06:45
perl logical operator confusion
0 && 1 || 1 # true
0 && 1 or 1 # true
0 and 1 || 1 # false
0 and 1 or 1 # true
@purplexa
purplexa / grep_between.sh
Last active October 29, 2015 00:17
Use grep to print lines between two regular expressions
function grep_between () {
if [ -z $1 -o -z $2 -o -z $3 ]; then
echo "Usage:\ngrep_between 'starting regex' 'ending regex' file1 [file2 file3 ...]"
exit 2
fi
startregex=$1
endregex=$2
for i in ${@:3}; do
@purplexa
purplexa / grep_to_end.sh
Created October 29, 2015 00:19
Use grep to print all lines after a match
function grep_to_end () {
if [ -z $1 -o -z $2 ]; then
echo "Usage:\ngrep_to_end 'regex' file1 [file2 file3 ...]"
exit 2
fi
for i in $(grep -n -m1 $1 "${@:2}"); do
filename="$(cut -d':' -f1 <<< $i)"
lnum="$(cut -d':' -f2 <<< $i)"
echo "\n--\n$filename:"
@purplexa
purplexa / grep_from_start.sh
Created October 29, 2015 00:31
Use grep to print all lines up to a match
function grep_from_start () {
if [ -z $1 -o -z $2 ]; then
echo "Usage:\ngrep_from_start 'regex' file1 [file2 file3 ...]"
exit 2
fi
for i in $(grep -n -m1 $1 "${@:2}"); do
filename="$(cut -d':' -f1 <<< $i)"
lnum="$(cut -d':' -f2 <<< $i)"
omit_lines="$(( $(wc -l $filename | awk '{print $1}') - $lnum + 1 ))"
@purplexa
purplexa / query_spec.rb
Created April 21, 2016 00:59
rspec-puppet JSON attribute value comparison
require 'spec_helper'
require 'json'
fixture_dir = File.expand_path(File.join(__FILE__, '..', '..', 'fixtures', 'data'))
describe 'jmxtrans::query' do
def check_json_string(expected)
return Proc.new do |actual|
begin
expected_obj = JSON.parse(expected)