Skip to content

Instantly share code, notes, and snippets.

@drgarcia1986
drgarcia1986 / Project1.dpr
Created April 2, 2014 14:37
Generic Singleton Pattern in Delphi
program Project1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
uSingletonGeneric in 'uSingletonGeneric.pas',
uMyClass in 'uMyClass.pas';
@drgarcia1986
drgarcia1986 / tracking_with_mongo.py
Last active August 29, 2015 13:58
Simple example of using PyMongo and PyTracking
__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 / TestUntORM.pas
Last active January 5, 2022 07:43
This is a example of Dependency Injection and Unit Tests with Delphi-Mocks (https://github.com/VSoftTechnologies/Delphi-Mocks) and Spring4D (https://bitbucket.org/sglienke/spring4d)
unit TestUntORM;
interface
uses
TestFramework,
untORM,
untDB,
untLog,
Delphi.Mocks;
@drgarcia1986
drgarcia1986 / Strategy.Concrete.Lower.pas
Created April 15, 2014 02:45
A example of Pattern Strategy (GoF). context is IText, strategy is IFormatter and client is Application.
unit Strategy.Concrete.Lower;
interface
uses
Strategy.Interfaces;
type
TFormatterLower = class(TInterfacedObject, IFormatter)
public
function GetFormattedText(AText: IText): string;
@drgarcia1986
drgarcia1986 / pytesser.py
Created April 25, 2014 21:55
Wrapper for Google-Tesseract
from subprocess import Popen, PIPE
import os
import sys
PROG_NAME = 'tesseract'
TEMP_IMAGE = 'tmp.bmp'
TEMP_FILE = 'tmp'
PSM_OSD_ONLY = 0
@drgarcia1986
drgarcia1986 / ptwitter.py
Created April 28, 2014 18:35
Twitter integration with Python
#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 April 28, 2014 19:56
Scripts for Start/Stop Windows service remote (bath or powershell)
net use \\%Machine% [PasswordOfRemoteMachine] /USER:[UserOfRemoteMachine]
sc \\%Machine% %Action% %Service%
@drgarcia1986
drgarcia1986 / my_thread.py
Created May 6, 2014 22:04
Exemplo simples de uso de Threads em python
#!/usr/bin/python
__author__ = 'Diego Garcia'
from threading import Thread
from time import sleep
from random import randint
class MinhaThread(Thread):
def __init__(self, identificador, vezes):
@drgarcia1986
drgarcia1986 / app.py
Last active August 29, 2015 14:02
Encolhedor de links ultra simples
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import Flask, redirect, abort, jsonify, url_for, request
import string
import random
app = Flask("encolinks")
links = {}
@drgarcia1986
drgarcia1986 / format.js
Created June 16, 2014 22:56
Habilitando método "Format" para JavaScript
String.prototype.format = function() {
var formatted = this;
for (var i = 0; i < arguments.length; i++) {
var regexp = new RegExp('\\{'+i+'\\}', 'gi');
formatted = formatted.replace(regexp, arguments[i]);
}
return formatted;
};
var txt = "Nome: {0} | Sobrenome: {1}".format("Diego", "Garcia");