Skip to content

Instantly share code, notes, and snippets.

View andersonfraga's full-sized avatar
🧩
Focusing

Anderson Fraga andersonfraga

🧩
Focusing
View GitHub Profile
@andersonfraga
andersonfraga / cronjob.sh
Created May 27, 2016 20:23
Execute notify-send via cronjob
#!/bin/bash
# * * * * * /bin/sh cronjob.sh "Teste 1 2 3"
{
PID=$(/usr/bin/pgrep gnome-session)
dbus=$(/bin/grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
export DBUS_SESSION_BUS_ADDRESS=$dbus
DISPLAY=:0.0 /usr/bin/notify-send --urgency=critical "Alert using crontab" "$1"
} >> $HOME/crontab/alert.log 2>&1
@andersonfraga
andersonfraga / divisible.go
Created May 17, 2016 02:54
Brincando com go... But, tem será maneira mais 'go-style' de fazer isso?
package main
import "os"
import "fmt"
import "math"
import "strconv"
func main() {
number, _ := strconv.ParseFloat(os.Args[1:2][0], 64)
denom := float64(2)
@andersonfraga
andersonfraga / gist:8603259
Created January 24, 2014 18:32
Bug ao usar array_diff_assoc?
<?php
$diff = array_diff_assoc(array(array('dsa' => '2')), array(array(),array()));
if (count($diff)) {
print_r($diff);
}
echo '<br />Gerou um "PHP Notice: Array to string conversion" na linha 3';
echo '<br />----';
@andersonfraga
andersonfraga / Module.php
Created November 8, 2013 11:59
Redirects HTTPS in Zend2
<?php
$request = $e->getRequest();
$needHttps = (preg_match($listNeedHttps, $request->getRequestUri()) != false);
$isHttps = ($request->getUri()->getScheme() == 'https');
$isGetMethod = ('GET' == $request->getMethod());
$url = new Http($request->getUri());
if ($needHttps and !$isHttps and $isGetMethod) {
$url->setScheme('https');
@andersonfraga
andersonfraga / checkout.sh
Created October 3, 2013 15:31
New branch and deploy! \m/
if [ $# -eq 0 ]
then
echo "C'mmon! Specific new branch, please!"
else
echo "~ git pull composer"
git pull composer
echo "~ git pull origin"
git pull origin
@andersonfraga
andersonfraga / gist:6231913
Last active December 21, 2015 01:59
Parser
<?php
$txt = array(
'08 11',
'08110054 00432 0000 15 27 4597 00 065001017',
'08110629 00017 0000 I 4597 1528 00 4597',
'08110641 00015 0000 J 4597 4595 00 4597',
'08110643 00005 0000 J 4595 4597 00 4595',
'08110647 00008 0000 J 4595 4597 00 4595',
'08110713 01058 0000 I 4597 1528 00 4597',
<?php
class Teste {
public $outro;
function __construct($outraclasse) {
$this->outro = $outraclasse;
}
}
class Loader {
@andersonfraga
andersonfraga / gist:5716387
Last active December 18, 2015 03:09
Usando o Respect/Validation para validação.. Tem maneira mais simples de recuperar as falhas na validação?
<?php
namespace Site\Controller;
use Respect\Validation\Validator as v;
class FormController extends BaseController
{
public function faleAction()
@andersonfraga
andersonfraga / gist:5204725
Created March 20, 2013 13:43
install_apache_php
apt-get -y -q install make g++ flex bison build-essential zlib1g-dev binutils \
cmake automake autoconf libmcrypt-dev libmhash-dev libxslt1-dev \
libtidy-dev libbz2-dev libxml2-dev libssl-dev curl vim git perl \
libpng12-dev libpng12-0 libpng3 libjpeg62 libjpeg62-dev libxpm-dev libpcre3 \
libpcre3-dev zlib1g zlib1g-dev libltdl-dev libltdl7 pkg-config \
libcurl4-openssl-dev libfreetype6 libfreetype6-dev libc-client2007e \
libc-client2007e-dev libkrb5-3 libkrb5-dev openssl \
libcurl4-openssl-dev libicu-dev libpspell-dev curl-dev \
linux-libc-dev libc-dev-bin libc-bin libc-client2007e-dev eglibc-source \
libkrb5-3 libkrb5-dev libkrb53 libkrb5support0 libncurses5-dev libncurses5 \
@andersonfraga
andersonfraga / uksort_fault.php
Created February 8, 2013 16:36
Segmentation fault using PHP 5.3.6 :/
<?php
$list = array(
array(
'idCliente' => 12,
),
array(
'idCliente' => 2,
),
array(