Skip to content

Instantly share code, notes, and snippets.

View martinusso's full-sized avatar
🏠
Working from home

Breno Martinusso martinusso

🏠
Working from home
View GitHub Profile
@martinusso
martinusso / firebird_round_number.sql
Created September 30, 2011 14:22
Rounding numbers in Firebird
cast(cast(9223373.03685 as double precision) * cast(1.0000000000 as double precision) as numeric(18, 0)) as round_number
@martinusso
martinusso / clearing_print_queue.bat
Created October 3, 2011 11:20
Cancel Printing from Microsoft Windows
@echo off
cls
echo All documents in print queue will be canceled! Please wait...
net stop spooler
echo .
echo Clearing the print queue...
del %windir%\system32\spool\printers\*.* /q /s
echo .
net start spooler
@martinusso
martinusso / recursive_binary_search.py
Last active September 27, 2015 10:58
Recursive binary search in Python
def get_index_recursive(vector, number, index = -1, prior_index = 0):
index_helper = index if index > -1 else int(len(vector)/2)
if vector[index_helper] < number:
prior_index_helper = prior_index if prior_index > 0 else len(vector)
index_helper = int((prior_index_helper - index_helper)/2) + index_helper
elif vector[index_helper] > number:
prior_index_helper = index_helper +1
index_helper = int(index_helper/2)
@martinusso
martinusso / disable_all_triggers_on_firebird.sql
Last active April 17, 2019 07:19
Enable/Disable all Triggers on a Firebird database
update
rdb$triggers
set
rdb$trigger_inactive = 1
where
rdb$trigger_source is not null
and (coalesce(rdb$system_flag,0) = 0)
and rdb$trigger_source not starting with 'CHECK'
@martinusso
martinusso / ascii_to_char.py
Created November 8, 2011 19:26
Convert ASCII to Char in Python
'''
Convert ASCII to Char in Python
'''
chr(97) # return 'a'
ord('a') # return 97
# ...
chr(122) # return 'z'
@martinusso
martinusso / random_string.py
Created November 8, 2011 23:09
Just for fun #1 - random string
# -*- coding: utf-8 -*-
import random
class RandomString:
__ALPHABETIC = 'aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ'
__NUMBERS = '0123456789'
def random_char(self, allow_numbers = True):
@martinusso
martinusso / firebird_having.sql
Last active February 4, 2021 17:00
Using the HAVING clause in Firebird
select
TABLENAME.FIELDNAME
from
TABLENAME
group by
TABLENAME.FIELDNAME
having
count(TABLENAME.FIELDNAME) > 1
@martinusso
martinusso / fizz_buzz.py
Created November 14, 2011 19:17
Fizz Buzz
'''
There's something wrong here that's gonna be alright. Less ammo guy!
Fizz Buzz is a mathematical game which is played with a group of people.
Each person says a number in sequence, but:
when the number is a multiple of 3, they have to say "Fizz",
when it is a multiple of 5 they have to say "Buzz", and
if it is a multiple of both 3 and 5, "FizzBuzz".
If someone makes a mistake and it is noticed, they are out.
@martinusso
martinusso / refactoring_001.pas
Created November 16, 2011 19:00
Refactoring #1
// Improving the reading and understanding of your code
{ Before }
Utils = class
public
class property MessageUtils: TMessageUtils read FMessageUtils;
TMessageUtils = class
public
@martinusso
martinusso / EnterAsTab.pas
Created November 21, 2011 10:33
Make the Enter key work like Tab in Delphi applications
{
In the Main Form of application
}
procedure TMainUI.DoEnterAsTab(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.Message = WM_KEYDOWN then
begin
if (not (Screen.ActiveControl is TCustomMemo)) and (not (Screen.ActiveControl is TButtonControl)) then
begin