Skip to content

Instantly share code, notes, and snippets.

View edumelzer's full-sized avatar

Eduardo Melzer edumelzer

View GitHub Profile
@edumelzer
edumelzer / bubble_sort.py
Created May 27, 2013 15:37
Bubble Sort Python (working)
print 'Digite os valores a serem ordenados separados por virgula:'
valores = [2,5,3,9,8]
def bubbleSort(numbers): # Bubble Sort Algorithm
nums = list(numbers)
for i in range(len(nums)):
for j in range(i+1, len(nums)):
if numbers[j] < numbers[i]:
numbers[j], numbers[i] = numbers[i], numbers[j]
@edumelzer
edumelzer / select_on_sort.py
Created May 27, 2013 15:41
select_on_sort python (working)
print 'Digite os valores a serem ordenados separados por virgula:'
valores = [2,5,3,9,8]
def selection_sort(list):
l=list[:] # create a copy of the list
sorted=[] # this new list will hold the results
while len(l): # while there are elements to sort...
lowest=l[0] # create a variable to identify lowest
for x in l: # and check every item in the list...
if x<lowest: # to see if it might be lower.
@edumelzer
edumelzer / merge_sort.py
Created May 27, 2013 15:57
Merge Sort Python
print 'Digite os valores a serem ordenados separados por virgula:'
valores = [2,5,3,9,8,4]
def merge_sort(li):
if len(li) < 2: return li
m = len(li) / 2
return merge(merge_sort(li[:m]), merge_sort(li[m:]))
def merge(l, r):
result = []
@edumelzer
edumelzer / resolver_no_dt_found_regra_calculo.sql
Created May 16, 2014 17:35
Resolvendo no_data_found em Regras de cálculo após mudança na inicialização de pagamentos.
...
while vcod_pagamento <= 999 loop
--
begin
--
ps_var.valor_pagamento(vcod_pagamento) := ps_var.valor_pagamento(vcod_pagamento);
--
exception when no_data_found then
--
ps_var.valor_pagamento(vcod_pagamento) := 0;
@edumelzer
edumelzer / ExemploActionsController.groovy
Last active November 11, 2017 19:07
Actions declaration SwingBuilder / Griffon
package org.example
import griffon.core.artifact.GriffonController
import griffon.metadata.ArtifactProviderFor
@ArtifactProviderFor(GriffonController)
class ExemploActionsController {
ExemploActionsModel model
void somarAction() {
@edumelzer
edumelzer / isPisValid.groovy
Last active November 16, 2018 18:03
Validar se numero PIS é valido
Closure isPisValid = { String pis ->
final List tap = [3,2,9,8,7,6,5,4,3,2]
String nroPis = pis.replaceAll("[^0-9]*", "").padLeft(11, '0')
int checker = Integer.parseInt(
String.valueOf(nroPis.charAt(nroPis.length()-1))
)
@edumelzer
edumelzer / getArrayCombinations.js
Last active April 12, 2018 18:49
Get all combinations in array with a given size
const getArrCombos = (arr, comboSize) => {
let combos = arr.reduce( (acc, v, i) => {
if (comboSize === 1) {
return acc.concat([[v]])
} else {
arrCombo = getArrCombos(arr.slice(i+1), comboSize - 1);
return acc.concat(arrCombo.map( w => [v].concat(w)));
}
}, []);
Closure generateRandomEan13 = {
// Primeiro executamos os metodos de geracao
List<Integer> listaAleatoria = new ArrayList();
for (int i = 0; i < 12; i++) {
listaAleatoria.add((int) (Math.random() * 10));
}
int totalSomatoria = 0;
// Metade dos números vai ser somado sem ser multiplicado