Skip to content

Instantly share code, notes, and snippets.

View mmenavas's full-sized avatar

Maximo Mena mmenavas

  • IntraEdge
  • San Tan Valley, Arizona, USA
View GitHub Profile
@mmenavas
mmenavas / rename.php
Created May 19, 2014 16:19
CLI PHP script to non-recursively rename files
<?php
/**
* Script to non-recursevly rename files in the directory where the script is.
* TODO:
* - Provide help flag (option -h or -help)
* - Check special characters
*/
// Search and replace parameters
PHP 7.1
valet stop && brew services stop php56 && brew unlink php56 && brew link php71 && brew services start php71 && valet start
valet stop && brew unlink php56 && brew link php71 && brew services start php71 && valet start
PHP 5.6
valet stop && brew services stop php71 && brew unlink php71 && brew link php56 && brew services start php56 && valet start
valet stop && brew unlink php71 && brew link php56 && brew services start php56 && valet start
@mmenavas
mmenavas / settings.local.php
Last active May 23, 2017 20:35
Get hash salt from Drupal 8 site in Pantheon using terminus
<?php
$databases['default']['default'] = array (
'database' => '',
'username' => '',
'password' => '',
'host' => 'localhost',
'port' => '3306',
'driver' => 'mysql',
'prefix' => '',
<?php
$num_updated = db_update('users')
->fields(array(
'timezone' => 'America/Phoenix',
))
->execute();
drupal_set_message(t('@var users where updated.', array('@var' => $num_updated)), 'status');
@mmenavas
mmenavas / drupal7-add-email-address-to-users.php
Created July 17, 2017 20:46
Use this script to fill in the 'mail' field in the users table.
<?php
$query = new EntityFieldQuery();
$query->entityCondition('entity_type', 'user', '=');
$query->propertyCondition('mail', NULL);
$query->propertyCondition('uid', 0, '>');
$query_result = $query->execute();
if (isset($query_result['user'])) {
<?php
$users = array(
'username1',
'username2',
);
foreach ($users as $username) {
$user = user_load_by_name($username);
$role = user_role_load_by_name("event coordinator");
@mmenavas
mmenavas / gen-d8-salt.sh
Created July 24, 2017 20:37 — forked from pfaocle/gen-d8-salt.sh
Generate Drupal 8 hash salt
drush eval "var_dump(Drupal\Component\Utility\Crypt::randomBytesBase64(55))"
@mmenavas
mmenavas / PrimeNumbers.php
Last active January 6, 2019 23:46
Prime Numbers
<?php
// This utility class provides a function that calculates all prime numbers up to a given number.
// Disclaimer: Depending on your system, you may not want to find prime numbers greater than 10000 as
// this operation can take several minutes if not hours.
class PrimeNumbers {
public static function getPrimeNumbers($ceiling) {
@mmenavas
mmenavas / Rectangle.php
Last active September 27, 2017 07:22
PHP class that allows you to draw a rectangle on the command line.
<?php
class rectangle {
public function __construct($size, $width = 0, $height = 0) {
$sizes = $this->getSizes();
if (isset($sizes[$size])) {
$this->width = $sizes[$size]['width'];
$this->height = $sizes[$size]['height'];
@mmenavas
mmenavas / .lando.yml
Last active February 2, 2018 19:54
Research Academy Lando files
name: research-academy
recipe: drupal7
config:
webroot: .
php: '5.6'
xdebug: true
services:
appserver:
build:
- "mkdir -p ~/.drush/site-aliases"