Skip to content

Instantly share code, notes, and snippets.

@aaoliveira
aaoliveira / utf8-regex.js
Created September 30, 2016 00:39 — forked from chrisveness/utf8-regex.js
Utf8 string encode/decode using regular expressions
/**
* Encodes multi-byte Unicode string into utf-8 multiple single-byte characters
* (BMP / basic multilingual plane only).
*
* Chars in range U+0080 - U+07FF are encoded in 2 chars, U+0800 - U+FFFF in 3 chars.
*
* Can be achieved in JavaScript by unescape(encodeURIComponent(str)),
* but this approach may be useful in other languages.
*
* @param {string} unicodeString - Unicode string to be encoded as UTF-8.
@aaoliveira
aaoliveira / auth.php
Created September 13, 2016 23:40 — forked from anonymous/auth.php
Exemplo autenticação http basic
$login = 'hjk3kj3h534h53kj4j345';
$password = '3k45jh3k4j5h3k4j5h34kh5k34';
$url = 'https://apic1.hml.stelo.com.br/';
$encode = base64_encode("$login:$password");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
@aaoliveira
aaoliveira / git_meld_install.sh
Created April 27, 2016 16:49 — forked from MarcosX/git_meld_install.sh
Install Meld as the default git diff tool. Must be executed as sudo
#!/bin/bash
echo "Installing meld..."
apt-get install meld -y -qq
echo "Meld [OK]"
echo "Creating meld custom script..."
rm ~/.config/git_meld_diff.sh
touch ~/.config/git_meld_diff.sh
echo "#!/bin/bash" >> ~/.config/git_meld_diff.sh
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/blog.*
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/blog.*
RewriteCond %{REQUEST_URI} !-d
RewriteRule (.*) app/webroot/$1 [L]
#!/bin/sh
# Just copy and paste the lines below (all at once, it won't work line by line!)
# MAKE SURE YOU ARE HAPPY WITH WHAT IT DOES FIRST! THERE IS NO WARRANTY!
function abort {
echo "$1"
exit 1
}
set -e
<?php
/**
* @todo CakePHP Permissions Array by Kevin Wentworth (Saco Design, Inc.)
* @todo Handles retrieving all ACL Permissions and storing them in an array.
* @todo Comments and bug reports welcome at kevin at sacode sign dot com
*
* @licensed Licensed under UYOR (Use at Your Own Risk)
* @link http://www.mainelydesign.com/blog/view/getting-all-acl-permissions-in-one-lookup-cakephp-1-3#null
*/
<?PHP
class Minhamodel extends AppModel{
//Primeira opção, caso nunca mude o "alias" da model
public $virtualFields = array(
'data_formatada'=>"DATE_FORMAT(Minhamodel.data,'%d/%m/%Y')",
);
//Alternativa caso mude o "alias" da model, melhor opção
public function __construct($id=false,$table=null,$ds=null){
# when I tried to start postgres, I had an error telling me there were no postgres clusters created
# so I had to create one using the `pg_createcluster` command, like the following
pg_createcluster 9.1 main --start
#after creating the cluster, it will start the server because of `--start`
#so I had to change to postgresql user
sudo su - postgres
#to change it's pasword, doing `psql -d <database_name> -U <username>
psql -d postgres -U postgres
<?php
/**
* Breadcrumbs helper
* Allows to generate and display breadcrumbs with a convenient syntax
*
* It uses a <ul><li> syntax but can be extended and protected method overriden to
* generate the markup adapted to your situation
*
*/
class BreadcrumbsHelper extends AppHelper {
@aaoliveira
aaoliveira / cidade-estado.php
Created December 3, 2013 18:14 — forked from emersonsoares/gist:2051743
Lista cidade estado cakephp
<?php
//Primeiramente o controller usuarios, que é onde vou utilizar os selects de cidades e estados
class UsuariosController extends AppController {
public function cadastro() {
$this->set('estados', $this->Estado->find('list'));
}
}
//No controller CidadesController: