Skip to content

Instantly share code, notes, and snippets.

View rmgimenez's full-sized avatar

Ricardo Moura Gimenez rmgimenez

View GitHub Profile
@rmgimenez
rmgimenez / upload_arquivos.php
Last active May 2, 2024 10:54
Script PHP que faz o upload de um arquivo e retorna um json com a url do arquivo ou a mensagem de erro
<?php
$pastaUpload = '/c:/wamp64-3.3.0-20230516/www/aps/uploads/';
$endereco = 'http://localhost/aps/uploads/';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
// Check if file was uploaded without errors
if (isset($_FILES['file']) && $_FILES['file']['error'] === UPLOAD_ERR_OK) {
$uploadDir = $pastaUpload; // Directory to save uploaded files
@rmgimenez
rmgimenez / data_extenso.pas
Created June 7, 2016 12:24
Data por extenso no delphi
function DataExtenso(Data:TDateTime): String;
var
NoDia : Integer;
DiaDaSemana : array [1..7] of String;
Meses : array [1..12] of String;
Dia, Mes, Ano : Word;
begin
DiaDasemana [1]:= 'Domingo';
DiaDasemana [2]:= 'Segunda-feira';
DiaDasemana [3]:= 'Terçafeira';
<html>
<head>
<title>Título do site</title>
</head>
<body>
<?php echo $conteudo; ?>
</body>
</html>
@rmgimenez
rmgimenez / execution_time.py
Created January 5, 2018 00:09
Script em python que mostra quanto tempo demorou para executar um script
"""
ExecutionTime
This class is used for timing execution of code.
For example:
timer = ExecutionTime()
print 'Hello world!'
print 'Finished in {} seconds.'.format(timer.duration())
"""
<!-- Arquivo salvo em: views/sobre.html -->
<h2>Sobre</h2>
<p>Informações sobre o site...</p>
<p>Exemplo de variável: <$php echo $exemplo_variavel; ?></p></pre><br />
No controller eu faço assim para chamar a view da página "Sobre" e o template:<br />
<br />
from peewee import *
import datetime
db = SqliteDatabase('banco_dados.sqlite')
class BaseModel(Model):
class Meta:
database = db
class Cotacao(BaseModel):
@rmgimenez
rmgimenez / Cotacao.java
Created July 14, 2016 18:43
Le o arquivo de cotação da bovespa e exporta para o metastock
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package bovespa;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@rmgimenez
rmgimenez / ler_xml_reddit_imgur.py
Created July 5, 2016 18:27
Ler xml reddit imgur
from urllib.request import urlopen
import xml.etree.ElementTree as ET
link_xml = 'http://imgur.com/r/cosplay/top/day.xml';
arq_xml = urlopen(link_xml)
xml = ET.parse(arq_xml)
items = []
for item_xml in xml.findall('item'):
lista = {
@rmgimenez
rmgimenez / funcoes.php
Created June 25, 2016 16:12
Retorna dados de sites de imagens
<?php
function extract_link_from_text($text)
{
//The Regular Expression filter
$reg_exUrl = "/(http|https|ftp|ftps)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,4}(\/\S*)?/";
// Check if there is a url in the text
if(preg_match($reg_exUrl, $text, $url)) {
return $url[0];
} else {