Skip to content

Instantly share code, notes, and snippets.

@weaver299
weaver299 / gist:e44185e548196db038afcfba145c11c2
Created May 7, 2018 15:41
check what a URL redirects to
check_redirect () {
echo -n "$1: ";
curl -is "$1" | grep '^Location:' | perl -pe 's/^Location: //;chop;'
echo;
}
@weaver299
weaver299 / bash_escaping.sh
Last active September 5, 2018 16:19
Can't output desired string with "..." in bash??
#!/usr/bin/env bash
# This outputs "\$conf" as desired
echo $'s/^(\\$conf\\[\'simplesamlphp_auth_installdir\'\\] = .*)/if(whatever){ $1 } else { whatever };/'
# Yes, it can also be done with this craziness
echo 's/^(\$conf\['"'"'simplesamlphp_auth_installdir'"'"'\] = .*)/if(whatever){ $1 } else { whatever };/'
# But it doesn't seem to be possible with "..." ?
echo "s/^(\$conf\['simplesamlphp_auth_installdir'\] = .*)/if(whatever){ \$1 } else { whatever };/"
gen_dev_config() {
if [[ -z "$1" ]]; then
echo "Usage: gen_site_config <site_name>";
echo;
return 1;
fi
password=$(</dev/urandom tr -dc '0-9!@#$%a-zA-Z' | head -c16; echo "");
underscores=$(echo "$1" | sed 's/\./_/g' | sed 's/-//g');
dev_underscores=$(echo "dev_$underscores");
@weaver299
weaver299 / Dfence.php
Last active January 22, 2019 19:27
defensive programming
<?php
if (empty($json_object->fields) && empty($json_object->field_deltas)) {
echo "Embedded Reference -- fields NO, field_deltas NO.\n";
print_r($json_object);
die();
}
else if (!empty($json_object->fields) && empty($json_object->field_deltas)) {
echo "Embedded Reference -- fields YES, field_deltas NO.\n";
}
id: media_files
label: Migrate managed files
description: Migrate managed files
migration_group: media
migration_tags:
- Drupal 7
- Content
migration_dependencies:
required:
id: media_images
label: Migrate image file entities
description: Migrate image file entities
migration_group: media
migration_tags:
- Custom
source:
plugin: file_entity
<?php
namespace Drupal\asc_migrate_standardd7\Plugin\migrate\source;
use Drupal\Core\Database\Query\Condition;
use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\d7\FieldableEntity;
/**
* Drupal 7 file_entity source from database.
*
id: users
label: User Migration
source:
key: source_db
plugin: d7_user
destination:
plugin: entity:user
process:
id: media_youtube
label: Migrate Youtube Videos
description: Migrate Youtube Videos
migration_group: media
migration_tags:
- Custom
source:
plugin: file_entity
function ffclip {
# some links about calculating durations in bash
# https://stackoverflow.com/questions/8903239/how-to-calculate-time-difference-in-bash-script
# http://giantdorks.org/alain/script-to-calculate-clip-duration-from-startstop-times/
# http://giantdorks.org/alain/bash-script-to-calculate-duration-between-two-time-stamps-and-also-report-minutes-hours-days-weeks-months-and-years/
# http://www.daveeddy.com/2014/06/29/human-readable-duration-in-bash/
# https://gist.github.com/bezhermoso/2d61cf44646c2f07c0820d81c644c1de
if [ "$#" -lt 3 ]; then
echo "Usage: ffclip <file> <start> <finish>";