Skip to content

Instantly share code, notes, and snippets.

@dejancencelj
dejancencelj / strip_word_html.php
Created July 27, 2017 19:57 — forked from dave1010/strip_word_html.php
Strip MS Word HTML. From php.net
<?php
function strip_word_html($text, $allowed_tags = '<b><i><sup><sub><em><strong><u><br>')
{
mb_regex_encoding('UTF-8');
//replace MS special characters first
$search = array('/&lsquo;/u', '/&rsquo;/u', '/&ldquo;/u', '/&rdquo;/u', '/&mdash;/u');
$replace = array('\'', '\'', '"', '"', '-');
$text = preg_replace($search, $replace, $text);
//make sure _all_ html entities are converted to the plain ascii equivalents - it appears
//in some MS headers, some html entities are encoded and some aren't
@dejancencelj
dejancencelj / MSWordHtmlCleaners.js
Created July 27, 2017 19:51 — forked from ronanguilloux/MSWordHtmlCleaners.js
2 js solutions to clean nasty MS Word HTML pasted in any CMS + 2 server-side tips
var CleanWordHTML = function ( str )
{
str = str.replace(/<o:p>\s*<\/o:p>/g, "") ;
str = str.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
str = str.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
str = str.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
str = str.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
str = str.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
check process redis-server
with pidfile "/var/run/redis.pid"
start program = "/etc/init.d/redis-server start"
stop program = "/etc/init.d/redis-server stop"
if 2 restarts within 3 cycles then timeout
if totalmem > 100 Mb then alert
if children > 255 for 5 cycles then stop
if cpu usage > 95% for 3 cycles then restart
if failed host 127.0.0.1 port 6379 then restart
if 5 restarts within 5 cycles then timeout
if (typeof RedactorPlugins === 'undefined') var RedactorPlugins = {};
RedactorPlugins.twitter = function () {
return {
init: function () {
var that = this;
var callback = $.proxy(function () {
var tweet_url = $('#tweet_url').val();
$.get('https://api.twitter.com/1/statuses/oembed.json', {
url: tweet_url,
@dejancencelj
dejancencelj / gist:91f8caec28a7c50baa8bd67dbd2c0b1e
Created January 19, 2017 17:14 — forked from alfredo/gist:1548139
Installing redis from debian backports
To install redis from debian backports we need to add the backports sources.
1. Add to /etc/apt/sources.list:
deb http://backports.debian.org/debian-backports squeeze-backports main
2. Retrieve debian key
$ gpg --keyserver pgp.mit.edu --recv-keys AED4B06F473041FA
@dejancencelj
dejancencelj / ratelimit.nginxconf
Created January 16, 2017 09:07 — forked from ipmb/ratelimit.nginxconf
Nginx reverse proxy with rate limiting
upstream myapp {
server 127.0.0.1:8081;
}
limit_req_zone $binary_remote_addr zone=login:10m rate=1r/s;
server {
listen 443 ssl spdy;
server_name _;
@dejancencelj
dejancencelj / mysql-export-import
Created October 10, 2016 11:09 — forked from el22or/mysql-export-import
Remote MySQL database dump directly into local database
## SSH - Remote export > local import
ssh USER@HOST mysqldump -uREMOTEDATABASEUSER -pREMOTEDATABASEPASSWORD -hREMOTEHOST REMOTEDATABASENAME | mysql -uLOCALDATABASEUSER -pLOCALDATABASEPASSWORD LOCALDATABASENAME
## Export to CSV
mysql -uUSER -pPASS DATABASENAME -B -e "select * from \`korisnici\`;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g' > filename.csv
## Export to CSV 2
mysql -uUSER -pPASS DATABASE -B -e "SELECT users.uid AS 'ID', users.name AS 'Username', users.mail AS 'Email', from_unixtime(users.created) AS 'Created', from_unixtime(users.login) AS 'Last login' FROM users WHERE users.status=1 AND users.login!=0 ORDER BY users.login DESC;" | sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g" > vehicle_categories.csv
## Export to SQL gzipped file with compression
@dejancencelj
dejancencelj / gist:1859d0569f5eb93df9ee
Created May 26, 2015 13:59
ngCordova $cordovaBatteryStatus correct use
angular.module('starter', ['ionic', 'starter.controllers', 'starter.services',])
.run(function ($ionicPlatform, $cordovaBatteryStatus, $ionicLoading) {
$ionicPlatform.ready(function () {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);