Skip to content

Instantly share code, notes, and snippets.

@rules = [
{"<TYPE>": "TYPE"},
{"<NUMBER>": "FATURO_NO"},
{"<DATE>": "FATURA_TARIHI"},
{"<ARP_CODE>": "MUSTERI_KODU"},
{"<DATE_CREATED>": "SIPARIS_TARIHI"},
{"<SALESMAN_CODE>": "NOTLAR"},
{"<DATE>": "SEVK_TARIHI"},
{"<TYPE>": "TYPE"},
{"<MASTER_CODE>": "VARYANT_STOK_KODU"},
doc = File.open("/home/yasin/İndirilenler/Satıs_Faturaları.XML")
count = 0
# doc.each do |line|
# count += 1 if line.include?("<INVOICE DBOP=\"INS\" >")
# break if count == 5001
# File.open("1.xml", "a") { |f| f.write(line.to_s) }
# end
#
one:
name: MyString
email: MyString
two:
name: MyString
email: MyString
valid:
name: ysn
@ysnerdem
ysnerdem / print_pattern.rb
Created March 17, 2018 22:58
Print Pattern
def pattern1(num)
(1..num).each do |x|
puts (x.to_s) * x
end
end
def pattern2(num)
n = 0
while n < num
n += 1
@ysnerdem
ysnerdem / word_freq_counter.rb
Last active March 19, 2018 15:34
Word Frequency Counter
def word_freq_counter(text, word)
counter = 0
text = text.downcase.split(/\W+/)
text.each {|w| counter += 1 if w == word}
counter
end
text = gets.chomp
word = gets.chomp.downcase
@ysnerdem
ysnerdem / deficient_numbers.rb
Created March 15, 2018 22:29
Deficient Numbers #3 different method
def is_deficient(num)
sum = 0
(1..num).each {|i| sum += i if num % i == 0}
if sum < (2 * num)
"#{num} is deficient number"
else
"#{num} is not deficient number"
end
end
@ysnerdem
ysnerdem / armstrong_nums.rb
Created March 15, 2018 21:51
Armstrong numbers
def is_armstrong(num)
num = num.to_s
sum = 0
num.each_char do |i|
i = i.to_i
sum += (i ** 3)
end
num = num.to_i
if sum == num
puts "#{num} is armstrong number"
@ysnerdem
ysnerdem / remove_spaces.rb
Last active March 15, 2018 17:08
RemoveSpacesFromString
def remove_spaces(str)
result = ""
str.each_char {|letter| result << letter if letter != " "}
result
end
#Alternative
def remove_spaces_v2(str)
str.delete! ' '
str
@ysnerdem
ysnerdem / lst_comprehension_2.py
Created January 24, 2018 15:50
find the odd divisors of the given number with list comprehension
num = int(input("enter a number:"))
lst = [i for i in range(1, num) if num % i == 0 and i % 2 != 0]
print(lst)
lst1 = list(map(lambda x: x*2, (i for i in range(1, 100))))
lst2 = [i for i in lst1 if i % 3 == 0 and i % 5 == 0]
print(lst2)