Skip to content

Instantly share code, notes, and snippets.

@facine
facine / pull-db
Last active May 4, 2020
Import a fresh database from jenkins
View pull-db
#!/bin/bash
## Description: Import a fresh database from jenkins
## Usage: pull-db
## Go to https://jenkins.example.org/user/YOUR_USER/configure and add a new token
USER="JENKINS_USER"
TOKEN="JENKINS_TOKEN"
ARTIFACT="LAST_SUCCESSFUL_ARTIFACT_URL"
EXTRACT_PATH=""
@facine
facine / git-exclude
Created Apr 30, 2020
Exclude ddev generated files from the project repo
View git-exclude
#!/bin/bash
## Description: Exclude ddev generated files from the project repo
## Usage: git-exclude
case $OSTYPE in
linux-gnu | "darwin"* )
if [ $DDEV_PROJECT_TYPE == "drupal7" ]; then
grep -qxF ".ddev" .git/info/exclude || echo ".ddev" >> .git/info/exclude
grep -qxF "${DDEV_DOCROOT}/sites/default/.gitignore" .git/info/exclude || echo "${DDEV_DOCROOT}/sites/default/.gitignore" >> .git/info/exclude
@facine
facine / RecurringBillingDate.php
Created Jun 19, 2019
Calculate recurring billing dates
View RecurringBillingDate.php
<?php
// Create a new DateTime object with the first billing date.
$lastDate = new DateTime('2019-01-31');
// Clone the date object or the original date will be altered.
$nextDate = clone $lastDate;
$periodUnit = 'M';
// Add the number of months.
@facine
facine / RecurringBillingDate.php
Created Jun 19, 2019
Calculate recurring billing dates (wrong method)
View RecurringBillingDate.php
<?php
// Create a new DateTime object with the first billing date.
$date = new DateTime('2019-01-31');
// Add one month and display the wrong result.
$date->modify('+1 month');
echo $date->format('Y-m-d');
@facine
facine / tmux.md
Created Mar 9, 2018 — forked from jonhattan/tmux.md
tmux quickstart
View tmux.md

tmux quickstart

$ tmux

CTRL+B C -> create new pane

CTRL+B [num] -> go to a pane

CTRL+D -> finish bash session, closes the pane. Closing all panes will destroy the window and thus the tmux

@facine
facine / __INDEX.txt
Last active Apr 10, 2022
Drupal 8 - Examples
View __INDEX.txt
# Taxonomy terms:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_taxonomy_term-php
# Menu links:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_menu_link-php
# File items:
- https://gist.github.com/facine/35bb291811c146b6fc9e#file-create_file-php
# Nodes:
View str_replace
/*
* Description: Replaces in the string str all the occurrences of the source string old with the destination string new. The lengths of the strings old and new may differ. The string new may be of any length, but the string "old" must be of non-zero length - the penalty for providing an empty string for the "old" parameter is an infinite loop. In addition, none of the three parameters may be NULL.
* Returns: The post-replacement string, or NULL if memory for the new string could not be allocated. Does not modify the original string. The memory for the returned post-replacement string may be deallocated with the standard library function free() when it is no longer required.
* Dependencies: For this function to compile, you will need to also #include the following files: <string.h>, <stdlib.h> and <stddef.h>.
* Licence: Public domain. You may use this code in any way you see fit, optionally crediting its author (me, Laird Shaw, with assistance from comp.lang.c).
* http://creativeandcritical.net/str-repl
View MODULENAME.module
<?php
/**
* Implements hook_menu().
*/
function MODULENAME_menu() {
$items['node/%node/edit-line-item/%commerce_line_item'] = array(
'title' => 'Edit line item in the cart',
'page callback' => 'node_page_view',
'page arguments' => array(1),
View magic.php
<?php
/**
* A base class with getters and setters incorporated.
*/
class ObjectBase {
/**
* Setter function for a generic attribute.
*
* @param string $property_name
View thingie2drupal.php
<?php
$URL = 'http://example.com/login.php';
$user = 'USER';
$pass = 'PASS';
$cookie_path = dirname(__FILE__).'/cookie.txt';
/**
* Hace login en la web enviando un POST con el usuario y contraseña.