Skip to content

Instantly share code, notes, and snippets.

View lslucas's full-sized avatar

Lucas Serafim lslucas

View GitHub Profile
<?php
$num=103;
if($num & 1) {
#impar
return true;
} else {
#par
return false;
<?php
/**
* Retorna todos os status do Correios para ID enviado
*
* @param string $id_correios ID do Correios
* @return array $array_retorno
*/
function status_correios( $id_correios ) {
$conteudo = file_get_contents('http://websro.correios.com.br/sro_bin/txect01$.QueryList?P_LINGUA=001&P_TIPO=001&P_COD_UNI='.$id_correios);
Upload multiple files with php
<?php
fixFilesArray($_FILES['array_of_files']);
foreach ($_FILES['array_of_files'] as $position => $file) {
// should output array with indices name, type, tmp_name, error, size
var_dump($file);
}
?>
<?php
//Bad Email...
$badEmail = "bad@email";
//Run the email through an email validation filter.
if( !filter_var($badEmail, FILTER_VALIDATE_EMAIL) ){
echo "Email is no good.";
}else{
echo "Nice email.";
}
source: http://www.markbrilman.nl/2011/08/howto-convert-a-pfx-to-a-seperate-key-crt-file/
`openssl pkcs12 -in [yourfile.pfx] -nocerts -out [keyfile-encrypted.key]`
What this command does is extract the private key from the .pfx file. Once entered you need to type in the importpassword of the .pfx file. This is the password that you used to protect your keypair when you created your .pfx file. If you cannot remember it anymore you can just throw your .pfx file away, cause you won’t be able to import it again, anywhere!. Once you entered the import password OpenSSL requests you to type in another password, twice!. This new password will protect your .key file.
Now let’s extract the certificate:
`openssl pkcs12 -in [yourfile.pfx] -clcerts -nokeys -out [certificate.crt]`

Deploy Rails app to digitalocean with nginx, unicorn, capistrano & postgres

Create droplet of your liking (ubuntu 12.10 x32)

ssh to root in terminal with your server ip

ssh root@123.123.123.123

Add ssh fingerprint and enter password provided in email

@lslucas
lslucas / iptables-security
Created June 22, 2014 15:19
iptables - Rate-limit incoming connections
$ iptables -I INPUT -p tcp --dport 80 -m state --state NEW -m recent --set
$ iptables -I INPUT -p tcp --dport 80 -m state --state NEW -m recent --update --seconds 30 --hitcount 10 -j DROP
#Source: http://codingfreak.blogspot.ca/2010/01/iptables-rate-limit-incoming.html
@lslucas
lslucas / file_exists.bash
Created March 6, 2014 18:49
Check if file exists in bash/terminal/unix
[ -f /etc/hosts ] && echo "Found" || echo "Not found"