Skip to content

Instantly share code, notes, and snippets.

@leonirlopes
leonirlopes / ImageManipulator.php
Created April 8, 2016 18:38
Image manipulation class, provides cropping, resampling and canvas resize
<?php
class ImageManipulator
{
/**
* @var int
*/
protected $width;
/**
* @var int
<?php
function validar_cnpj($cnpj)
{
$cnpj = preg_replace('/[^0-9]/', '', (string) $cnpj);
// Valida tamanho
if (strlen($cnpj) != 14)
return false;
@leonirlopes
leonirlopes / Konsole output
Created January 19, 2017 18:24 — forked from ManfMert/Konsole output
Extended version of sshfilter.sh to recognized private ip addresses and realy unknown ip addresses
/var/log/messages
Dec 12 16:03:39 bananapi logger: DENY sshd connection from 113.108.21.16 (CN)
Dec 12 16:12:59 bananapi logger: DENY sshd connection from 185.110.132.202 (IP Address not found)
Dec 12 16:20:12 bananapi logger: DENY sshd connection from 121.18.238.98 (CN)
Dec 12 16:24:57 bananapi logger: DENY sshd connection from 185.110.132.202 (IP Address not found)
Dec 12 16:26:20 bananapi logger: DENY sshd connection from 121.18.238.114 (CN)
Dec 12 16:29:10 bananapi logger: DENY sshd connection from 221.194.44.195 (CN)
Dec 12 16:30:55 bananapi logger: DENY sshd connection from 221.194.47.249 (CN)
Dec 12 16:37:06 bananapi logger: DENY sshd connection from 185.110.132.202 (IP Address not found)
@leonirlopes
leonirlopes / stream_to_youtube.sh
Created February 23, 2017 17:05 — forked from olasd/stream_to_youtube.sh
Stream video to youtube via ffmpeg
#! /bin/bash
#
# Diffusion youtube avec ffmpeg
# Configurer youtube avec une résolution 720p. La vidéo n'est pas scalée.
VBR="2500k" # Bitrate de la vidéo en sortie
FPS="30" # FPS de la vidéo en sortie
QUAL="medium" # Preset de qualité FFMPEG
YOUTUBE_URL="rtmp://a.rtmp.youtube.com/live2" # URL de base RTMP youtube
@leonirlopes
leonirlopes / php-html-css-js-minifier.php
Created March 15, 2017 20:56 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
// Based on <https://github.com/mecha-cms/extend.minify>
define('MINIFY_STRING', '"(?:[^"\\\]|\\\.)*"|\'(?:[^\'\\\]|\\\.)*\'');
define('MINIFY_COMMENT_CSS', '/\*[\s\S]*?\*/');
define('MINIFY_COMMENT_HTML', '<!\-{2}[\s\S]*?\-{2}>');
define('MINIFY_COMMENT_JS', '//[^\n]*');
define('MINIFY_PATTERN_JS', '\b/[^\n]+?/[gimuy]*\b');
define('MINIFY_HTML', '<[!/]?[a-zA-Z\d:.-]+[\s\S]*?>');
<?php
if (function_exists("date_default_timezone_set")) {
date_default_timezone_set("UTC");
}
function simple() {
$a = 0;
for ($i = 0; $i < 1000000; $i++)
$a++;
@leonirlopes
leonirlopes / delete-targz.php
Created March 23, 2017 11:53 — forked from Xeroday/delete-targz.php
Deletes .tar.gz files older than 7 days.
<?php
$files = glob("*.tar.gz");
foreach($files as $file) {
if(is_file($file)
&& time() - filemtime($file) >= 7*24*60*60) { // 7 days
unlink($file);
}
}
?>
@leonirlopes
leonirlopes / curl-smtp-email.sh
Created March 31, 2017 12:24 — forked from james2doyle/curl-smtp-email.sh
Send SMTP email using cURL
curl --connect-timeout 15 -v --insecure "smtp://smtp.example.com:25" -u "username:password"
\ --mail-from "sender@example.com" --mail-rcpt "destination@example.com"
\ -T email-contents.txt --ssl
@leonirlopes
leonirlopes / ckeditor-responsive-images.js
Created March 16, 2017 17:12 — forked from fabiomaggio/ckeditor-responsive-images.js
Make inserted images in CKEditor automatically responsive
// If you want inserted images in a CKEditor to be responsive
// you can use the following code. It creates a htmlfilter for the
// image tag that replaces inline "width" and "style" definitions with
// their corresponding attributes and add's (in this example) the
// Bootstrap "img-responsive" class.
CKEDITOR.on('instanceReady', function (ev) {
ev.editor.dataProcessor.htmlFilter.addRules( {
elements : {
img: function( el ) {
// Add bootstrap "img-responsive" class to each inserted image
<?php
$str_conn="firebird:host=localhost;dbname=/var/lib/firebird/2.5/data/employee.fdb;charset=UTF8";
$dbh = new PDO($str_conn, "sysdba", "masterkey");
?>