Skip to content

Instantly share code, notes, and snippets.

@facine
facine / magic.php
Created October 8, 2013 11:18 — forked from e0ipso/magic.php
<?php
/**
* A base class with getters and setters incorporated.
*/
class ObjectBase {
/**
* Setter function for a generic attribute.
*
* @param string $property_name
/*
* 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
<?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.
<?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),
@facine
facine / tmux.md
Created March 9, 2018 11:03 — forked from jonhattan/tmux.md
tmux quickstart

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 / RecurringBillingDate.php
Created June 19, 2019 19:07
Calculate recurring billing dates (wrong method)
<?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 / RecurringBillingDate.php
Created June 19, 2019 19:08
Calculate recurring billing dates
<?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 / pull-db
Last active May 4, 2020 17:00
Import a fresh database from jenkins
#!/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
Last active February 23, 2023 15:32
Exclude ddev generated files from the project repo
#!/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 / dialog.html
Created September 19, 2023 11:37 — forked from coinsandsteeldev/dialog.html
Google Sheets script to allow multi-select in cells with data-validation (adapted from https://www.youtube.com/watch?v=dm4z9l26O0I)
<!DOCTYPE html>
<html>
<head>
<script>
var data
var formId = 'form'
function drawForm() {
if (!data) return
var outputEl = document.getElementById(formId);