Skip to content

Instantly share code, notes, and snippets.

@arispublic
arispublic / release-memory-preg_replace.php
Last active November 7, 2019 02:00
Fix Out of memory issue in preg_replace syntax
<?php
/**
* If you have a PHP Fatal error: Out of memory (allocated 147161088) (tried to allocate 42524112 bytes) in /wp-includes/wp-db.php on line 3042
* It's probably due to the preg_replace is still keep the memory used in previous process.
* I added the code below to wp-db.php file and the problem is gone. But you have to hack the wordpress core code, which is not a good practice.
*/
for ($i = 0; $i < 4096; $i++) {
preg_replace('/\d/', '', 1);
@arispublic
arispublic / create-merchant-identity.php
Last active May 17, 2016 14:56
Error on create merchant identity based on example in http://developer.payline.io/
<?php
Payline\Settings::configure('https://api-test.payline.io', 'USr4EjVVrLxAAC2AGMezoMhQ', '2a788ff6-b6f8-4b19-a15f-6df8a3944c0f');
Payline\Bootstrap::init();
$identity = new \Payline\Resources\Identity(array("entity" => array(
"business_type"=> "LIMITED_LIABILITY_COMPANY",
"business_phone"=> "+1 (408) 756-4497",
"first_name"=> "Aris",
"last_name"=> "Pee",
"dob"=> array(
@arispublic
arispublic / capture.php
Created April 5, 2016 06:41
Capture issue
<?php
// here is the auth ID in the payment AU55jNSyU95a4o2ZFhUFgrMH
//init
Payline\Settings::configure(variable_get('aaa', ''), variable_get('bbb', ''), variable_get('ccc', ''));
Payline\Bootstrap::init();
//here are the code to capture the auth based on tutorial here: http://developer.payline.io/.
$auth = Payline\Resources\Authorization::retrieve("AU55jNSyU95a4o2ZFhUFgrMH");
@arispublic
arispublic / update-feature.sh
Created February 18, 2016 20:36
Steps to update feature in drupal
#1. recreate the feature_module with additional fields/views/menu. Don't forget to increase the version number
#2. Download the feature_module
#3. Replace the feature_module with the new one.
#4. Update the feature_module
drush fu feature_module
#5. Update module the feature_module
drush updb -y
#6. done.
@arispublic
arispublic / drush.sh
Created February 18, 2016 20:31
Drush Feature Export with additional fields and also increment the version
drush fe -y f_registration_views views_view:content_list --version-increment
@arispublic
arispublic / mergefile.bat
Created September 11, 2015 08:42
How to merge files into a file in windows? Please see command below
copy /b *.txt newfile.txt
@arispublic
arispublic / vpsbench.sh
Created August 4, 2015 15:45
Benchmark your VPS
wget freevps.us/downloads/bench.sh -O - -o /dev/null|bash
@arispublic
arispublic / truncate-tables.sh
Created June 19, 2015 05:43
Truncate all tables in a MySQL database when you don't have permission to drop and create database.
mysqldump -h[DB-HOST] -u[DB-USER] -p[DB-PASS] --add-drop-table --no-data [DB-NAME] | grep -e '^DROP \| FOREIGN_KEY_CHECKS' | mysql -h[DB-HOST] -u[DB-USER] -p[DB-PASS] [DB-NAME]
@arispublic
arispublic / preprocess_field.php
Last active August 29, 2015 14:21
Drupal 7: Preprocess custom fields before render it
<?php
/**
* Hide first name & last name from user account (additional fields), on render it.
* @param type $vars
*/
function mymodule_preprocess_field(&$vars) {
if (in_array($vars['element']['#field_name'], array('field_first_name', 'field_last_name'))) {
$vars['items'] = array(); //remove the value
$vars['label_hidden'] = true; //hide the label
@arispublic
arispublic / webscrapping.php
Last active June 4, 2018 03:47
Easy web scrapping using phpQuery (https://code.google.com/p/phpquery/)
<?php
//load phpquery library here.
require('phpQuery/phpQuery.php');
//sample URL
$url = 'http://www.b*ngg**d.com/Wholesale-Mobile-Phones-c-140.html';
// load the url using curl
$ch = curl_init();