Skip to content

Instantly share code, notes, and snippets.

View AndreiTelteu's full-sized avatar

Andrei Telteu AndreiTelteu

View GitHub Profile
@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 / 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;
filter: #{'invert()'}
@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);
}
<?php
function caesar_cipher_smart($shift, $input) {
$a = str_split('ABCDEFGHIJKLMNOPQRSTUVWXYZ');
$p = str_split($input);
foreach ($p as &$v)
if (($k = array_search($v, $a)) !== false) {
$t = $k+$shift;
if ($t < 0) $t = count($a)+$t;
$v = $a[$t];
@AndreiTelteu
AndreiTelteu / Laravel MongoDB User Following Relationships .md
Last active November 23, 2017 12:45
User following relationships for Laravel 5.2 with jenssegers/laravel-mongodb database driver
@AndreiTelteu
AndreiTelteu / Linux-prompt-git-status.md
Last active February 10, 2018 18:06
My git prompt script

Run command:

$ bash <(curl -L -s https://goo.gl/eax5A8)
@AndreiTelteu
AndreiTelteu / Google Maps Marker as AngularJS 1.x directive .html
Last active April 12, 2018 10:19
I extracted the svg icon of the markers shown by Google Maps directions display, and i use it as a directive. Demo: https://codepen.io/AndreiTelteu/pen/GxLdKK
<div ng-app="GoogleMapsMarkerDemo">
<!-- Usage -->
<div ng-repeat="marker in ['marker1', 'marker2', 'marker3']">
<google-marker label="$index | indexToAlphabet"></google-marker>
</div>
<!-- You can have this svg as a separate file -->
<script type="text/ng-template" id="google-marker-template">
<svg version="1.1" width="27px" height="43px" viewBox="0 0 27 43" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
@AndreiTelteu
AndreiTelteu / cPanel WHM change documentroot .md
Created September 17, 2018 15:59
cPanel/WHM change documentroot
  1. Edit this files:
/var/cpanel/userdata/username/domain.tld
/var/cpanel/userdata/username/domain.tld_SSL

Change documentroot and scriptalias for cgi-bin

  1. (optional) Remove cache files:
@AndreiTelteu
AndreiTelteu / disable bad inline code .html
Created September 19, 2018 13:31
disable some bad inline code that ruins websites
<script>
function disableBadInlineCode() {
$('style:contains("display: none!important")').each(function (i) { this.disabled = true; });
};
document.addEventListener('DOMContentLoaded', disableBadInlineCode, false);
setInterval(disableBadInlineCode, 1000);
</script>