Skip to content

Instantly share code, notes, and snippets.

View pedroppinheiro's full-sized avatar

Pedro Victor Pontes Pinheiro pedroppinheiro

View GitHub Profile
@pedroppinheiro
pedroppinheiro / ssh_commands.md
Last active August 29, 2015 14:26 — forked from learncodeacademy/gist:5850f394342a5bfdbfa4
SSH Basics - Getting started with Linux Server Administration

###SSH into a remote machine###

ssh user@mydomain.com
#or by ip address
ssh user@192.168.1.1

exit: exit ###Install Something###

#If it's a new server, update apt-get first thing
@pedroppinheiro
pedroppinheiro / git_commands.md
Last active March 31, 2021 11:20
Comandos ensinados no curso do codeschool sobre git

GIT - Cheat sheet - by Pedro Pinheiro pedrovictor.pinheiro@gmail.com

Instalação e ajuda:

sudo apt-get install git - Instalando o git no Ubuntu

git help - Mostra uma lista de comandos úteis do git e descrições do mesmo

git help command - Mostra detalhes de um comando específico
@pedroppinheiro
pedroppinheiro / create_thumbnail.php
Last active June 21, 2019 17:14
This php funtion creates a thumbnail of an image. It supports JPEG, JPG, PNG and GIF formats and can be used to define a specific background color, including transparent when dealing with PNG.
<?php
/**
* This code is an improvement over Alex's code that can be found here -> http://stackoverflow.com/a/11376379
*
* This funtion creates a thumbnail with size $thumbnail_width x $thumbnail_height.
* It supports JPG, PNG and GIF formats. The final thumbnail tries to keep the image proportion.
*
* It has been pointed out that if the thumbnail already exists it doesn't get overwritten, but the method still returns true.
* so keep an eye on that.
*
@pedroppinheiro
pedroppinheiro / sieve.js
Created August 7, 2015 14:26
The sieve of eratosthenes
// The Sieve of Eratosthenes!
// This gist was created so I can remember the algorithm cited here: http://qr.ae/RA6nsm
function sieve(max) {
var D = [], primes = [];
for (var q=2; q<max; q++) {
if (D[q]) {
for (var i=0; i<D[q].length; i++) {
var p = D[q][i];
if (D[p+q]) D[p+q].push(p);
else D[p+q]=[p];
@pedroppinheiro
pedroppinheiro / npm_commands.md
Last active December 17, 2015 17:34
Npm commands

###Getting help npm help

###Updating npm npm install npm -g

###Verifying the account your logged into npm whoami

###Creating a new account

@pedroppinheiro
pedroppinheiro / valida_cpf.php
Created March 3, 2016 01:17
Method to validate cpf in php
<?php
/** Retorna que valida CPF retorna FALSE se errado e TRUE se correto
* Fonte: http://www.geradorcpf.com/script-validar-cpf-php.htm
*/
static function validaCPF($cpf) {
// Verifica se um número foi informado
if(empty($cpf)) {
return false;
}
@pedroppinheiro
pedroppinheiro / select_year.php
Created March 3, 2016 01:22
code to display a select of year based on the current year
/** source: http://stackoverflow.com/a/18608587/1252947 **/
<?php
<select id="year">
<?
$currentValue = date("Y");
$past = 20;
$future = 0;
if ($currentValue && ($currentValue < date('Y') - $past || $currentValue > date('Y') + $future)) {
echo "<option value=\"$currentValue\" selected=\"selected\">$currentValue</option>\n";
}
Comandos acessíveis do terminal estão localizados em alguma pasta cadastrada no PATH do sistema. Para descobrir de qual pasta o comando está sendo chamado use o comando which:
- which php
- which java
Apache
Ativar o mod_rewrite do apache:
- sudo a2enmod rewrite
Para fazer o mod_rewrite funcionar completamente talvez seja preciso alterar o AllowOverride None para All:
<Directory />
@pedroppinheiro
pedroppinheiro / currency_operations_example.php
Last active July 22, 2016 14:40
Exemplos de operações envolvendo valores monetários que se não fosse usado o método adequado do php iriam dar valores imprecisos no cálculo.
<?php
$a = 1.01; +
$b = '1.1';
echo bcadd($a, $b, 2);
echo "</br>";
$first = bcsub('1000', 333.33, 2);
echo $first . '</br>';
@pedroppinheiro
pedroppinheiro / useful_methods.php
Created September 1, 2016 00:05
A compilation of useful methods that I have created during my time as a php programmer
<?php
static function dataToString($set, $input, $key_type = 'number') {
if($key_type === 'number') {
return isset($set[intval($input)]) ? $set[intval($input)] : '';
} else {
return isset($set[$input]) ? $set[$input] : '';
}
}