Skip to content

Instantly share code, notes, and snippets.

Avatar

Diego Garcia drgarcia1986

View GitHub Profile
@drgarcia1986
drgarcia1986 / TesteCotacao.dpr
Created Feb 13, 2014
Classe feita em Delphi para recuperar a cotação de algumas moedas estrangeiras baseada nas versões brasileiras do site CashCash.cc
View TesteCotacao.dpr
program TesteCotacao;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Utils.Cotacao in 'Utils.Cotacao.pas';
@drgarcia1986
drgarcia1986 / UDP.Server.Exemplo.pas
Last active Aug 29, 2015
Classe feita em Delphi que encapsula um servidor UDP, trabalhando com método anônimo para regatar as mensagens recebidas e determinar a resposta que o servidor deve devolver para o cliente.
View UDP.Server.Exemplo.pas
procedure TForm1.BitBtn1Click(Sender: TObject);
begin
TUDPServer.GetInstance().SetReponseToMessage(
function(const AMsg : string):String
begin
Memo1.Lines.Insert(0,AMsg);
if AMsg = 'UDP-MSG' then
Result := 'DONE'
else
Result := ReverseString(AMsg);
@drgarcia1986
drgarcia1986 / UDP.Client.Exemplo.pas
Created Feb 19, 2014
Classe feita em Delphi que encapsula um cliente UDP enviando e recebendo mensagens de um servidor.
View UDP.Client.Exemplo.pas
procedure TForm1.Button1Click(Sender: TObject);
var
wPort: Word;
sIp: string;
sMsg: string;
begin
TUDPClient.GetInstance().EndOfProtocol := '.';
sMsg := TUDPClient.GetInstance().SendBroadcast('UDP-MSG',sIp,wPort);
Memo1.Lines.Add(Format('[%s] [%d] : %s',[sIp,wPort,sMsg]));
@drgarcia1986
drgarcia1986 / Rastreio.Correios.pas
Created Feb 24, 2014
Classe escrita em Delphi que recupera e interpreta o rastreio de encomendas do site dos correios.
View Rastreio.Correios.pas
unit Rastreio.Correios;
interface
uses
IdHTTP,
System.Generics.Collections;
type
TStatus = record
@drgarcia1986
drgarcia1986 / singleton_example.py
Created Mar 11, 2014
Esqueleto para criação de uma classe Singleton em Python
View singleton_example.py
class MyClass:
__instance = None
@staticmethod
def instance():
if not MyClass.__instance:
MyClass.__instance = MyClass()
return MyClass.__instance
@drgarcia1986
drgarcia1986 / datas.py
Created Mar 28, 2014
Exemplo básico de como trabalhar com os métodos strptime e strftime da biblioteca datetime do python
View datas.py
__author__ = 'diego.garcia'
import datetime
dt = datetime.datetime.strptime('February 28, 2014, 7:05 AM', '%B %d, %Y, %I:%M %p')
print(dt.strftime("%d/%m/%Y %I:%M %p"))
@drgarcia1986
drgarcia1986 / tracking_with_mongo.py
Last active Aug 29, 2015
Simple example of using PyMongo and PyTracking
View tracking_with_mongo.py
__author__ = 'Diego Garcia'
from pymongo import MongoClient
import ptracking
def make_tracking(cod, user, package):
t = ptracking.PyTracking(ptracking.BRAZIL)
p = t.tracking(cod)
p['package'] = package
@drgarcia1986
drgarcia1986 / Strategy.Concrete.Lower.pas
Created Apr 15, 2014
A example of Pattern Strategy (GoF). context is IText, strategy is IFormatter and client is Application.
View Strategy.Concrete.Lower.pas
unit Strategy.Concrete.Lower;
interface
uses
Strategy.Interfaces;
type
TFormatterLower = class(TInterfacedObject, IFormatter)
public
function GetFormattedText(AText: IText): string;
@drgarcia1986
drgarcia1986 / ptwitter.py
Created Apr 28, 2014
Twitter integration with Python
View ptwitter.py
#based on: https://github.com/sixohsix/twitter
__author__ = 'Diego Garcia'
from twitter import *
from my_twitter_tokens import * # TOKENS CONSTS
t = Twitter(
auth=OAuth(ACCESS_TOKEN,
ACCESS_TOKEN_SECRET,
API_KEY,
@drgarcia1986
drgarcia1986 / Command.bat
Created Apr 28, 2014
Scripts for Start/Stop Windows service remote (bath or powershell)
View Command.bat
net use \\%Machine% [PasswordOfRemoteMachine] /USER:[UserOfRemoteMachine]
sc \\%Machine% %Action% %Service%