Skip to content

Instantly share code, notes, and snippets.

View AndreiTelteu's full-sized avatar

Andrei Telteu AndreiTelteu

View GitHub Profile
@AndreiTelteu
AndreiTelteu / PHP htmlentities recursive .php
Last active July 6, 2016 13:39
Small PHP function to apply htmlentities function to an array recursively
<?php
function htmlentities_recursive($code) {
if (is_array($code))
{
foreach ($code as &$c) $c = htmlentities_recursive($c);
return $code;
}
return htmlentities($code);
}
filter: #{'invert()'}
@AndreiTelteu
AndreiTelteu / MySQLdump hook on git commit .md
Last active October 12, 2015 22:47
Dumping the structure of a database on each commit, and staging that modification for the next commit.

Create or open the file .git/hooks/pre-commit and paste the following code inside it:

#!/bin/sh

mysqldump \
	--no-data \
	--dump-date=false \
	--result-file=$PWD/dbdump.sql \
	--log-error='/dev/null' \

--user='username' \

@AndreiTelteu
AndreiTelteu / CakePHP function for calling WP-API .md
Last active August 29, 2015 14:17
Protected function for calling WP REST API plugin
  1. Install the json rest api wordpress plugin.

  2. Include the following function in app/Controller/AppController.php in your CakePHP instalation.

    	protected function _wpAPI($method='get', $url='/', $data=null)
    	{
    		App::uses('HttpSocket', 'Network/Http');
    		$http = new HttpSocket();
    		
    		$http->configAuth('Basic', 'admin', 'password');
@AndreiTelteu
AndreiTelteu / Ajenti Web Install Ubuntu .md
Last active August 29, 2015 14:17
Install Ajenti Web Ubuntu Install

Instead of searching on the ajenti.org website every time i want to install it, i copy and paste the code from this page.

wget -O- https://raw.github.com/Eugeny/ajenti/master/scripts/install-ubuntu.sh | sudo sh

You may need apt-get remove apache2, and finaly

apt-get install ajenti-v ajenti-v-nginx ajenti-v-mysql ajenti-v-php-fpm php5-mysql

service ajenti restart

Keybase proof

I hereby claim:

  • I am AndreiTelteu on github.
  • I am andreitelteu (https://keybase.io/andreitelteu) on keybase.
  • I have a public key whose fingerprint is 6D38 3885 8AB5 904A 4933 C7BA 101C E7AA 653C DAB7

To claim this, I am signing this object:

@AndreiTelteu
AndreiTelteu / Redirecting WWW to NON-WWW the right way .md
Last active August 29, 2015 14:10
How to redirect www to non-www in the right way.

Add this in your .htaccess file:

	RewriteCond %{HTTPS} off
	RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
	RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
	
	RewriteCond %{HTTPS} on
	RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
	RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
@AndreiTelteu
AndreiTelteu / OpenShift NginX PHP-FPM configuration for Wordpress .md
Last active November 3, 2015 08:58
The configuration needed for runing a Wordpress (standard/multisite) app over NginX PHP-FPM on OpenShift.
  1. Create an app/gear on OpenShift with this cartidge: OpenShift Nginx PHP-FPM Cartridge

  2. Open the file: <your-app-folder>/config/nginx.d/default.conf.erb, earse all the content, and paste this instead:

server {
  root              <%= ENV['OPENSHIFT_REPO_DIR'] %>/php;
  listen            <%= ENV['OPENSHIFT_PHP_IP'] %>:<%= ENV['OPENSHIFT_PHP_PORT'] %>;
  server_name       <%= ENV['OPENSHIFT_APP_DNS'] %>;
  index             index.php index.html index.htm;
@AndreiTelteu
AndreiTelteu / CDN for Bootstrap IE Compatibility .md
Last active August 29, 2015 14:06
Bootstrap compatibility in IE, from MaxCDN

Add this code before </head>:

<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
  <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
  <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
@AndreiTelteu
AndreiTelteu / Mark a word .md
Last active January 25, 2022 22:50
Mark a word with <mark>

You can easily mark a specified word (or array of words) in a string.

<?php
function mark($pattern, $source) {
    if (is_array($pattern)) {
        $finalPatterns = array_map(function ($value) { return "/(".preg_quote($value).")(?![^<]*>|[^<>]*<\/)/i"; }, $pattern);
    } else {
        $finalPatterns = "/(".preg_quote($pattern).")(?![^<]*>|[^<>]*<\/)/i";
 }