Skip to content

Instantly share code, notes, and snippets.

View zverok's full-sized avatar

Victor Shepelev zverok

View GitHub Profile
@zverok
zverok / unmunch.py
Created May 9, 2021 13:01
"Unmunch" (linearize) word list from Hunspell dictionary with the help of Spylls library
# This is "unmunching" script for Hunspell dictionaries, based on Spylls (full Python port of Hunspell):
# https://github.com/zverok/spylls
#
# "Unmunching" (Hunspell's term) is a process of turning affix-compressed dictionary into plain list
# of all language's words. E.g. for English, in the dictionary we have "spell/JSMDRZG" (stem + flags
# declaring what suffixes and prefixes it might have), and we can run this script:
#
# python unmunch.py path/to/en_US spell
#
# Which will produce this list:
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Inspired by Lucian Ghinda's article about code review/refactoring with AI, just an experimenting on looking at the code the way I usually do that.

It is not an attempt to demonstrate "how everybody should write code," rather a way of sharing how I approach code style and refatoring. (I.e. not to communicate "you should do this," but just "here are some techniques and considerations I use, maybe you'll find it interesting").

So...

Here's the original code:

class Parser

Some small additions/comments to an article by Kevin Newton "Ruby operators"

% - The modulo operator. This is usually only found on numeric types.

And Ranges :)

(1..30) % 5
# => ((1..30).%(5)) -- an ArithmeticSequence
# It is show-the-point demo for my article
# "On DataFrame datatype in Ruby" http://zverok.github.io/blog/2016-01-10-dataframe.html
require 'good_data_frame' # `require': cannot load such file -- good_data_frame (LoadError)
# Initialization (with default index): hashes of column: values
# Values of each column are homogenous
# First and most important thing is "what columns is"
table = GDF.new(
manager: ['Tom', 'Jerry', 'Magda'],
@zverok
zverok / err1.md
Last active January 19, 2020 12:12
Example of how Ruby's error formatting breaks Markdown

(Just quick copy-paste into the dialog/GitHub issue.)

Ugh, do you know why am I having undefined local variable or method foo' for main:Object?.. I expected it to work for Logger`.

Source:

Ugh, do you know why am I having undefined local variable or method `foo' for main:Object?.. I expected it to work for `Logger`.
# Just porting examples of .unfold usability from
# http://weblog.raganwald.com/2007/11/really-simple-anamorphisms-in-ruby.html
# http://weblog.raganwald.com/2007/11/really-useful-anamorphisms-in-ruby.html
# ...to Ruby 2.7+ Enumerator.produce (and numbered block args):
# Simple examples: http://weblog.raganwald.com/2007/11/really-simple-anamorphisms-in-ruby.html
# 10.unfold { |n| n-1 unless n == 1 }.inspect => [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
p Enumerator.produce(10) { _1 - 1 }.take_while { _1 >= 1 }
#=> [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
body = 'Рабочая встреча с Председателем Правительства Дмитрием Медведевым. Владимир Путин провёл рабочую встречу с Председателем Правительства Дмитрием Медведевым. Премьер-министр, в частности, представил главе государства ряд итоговых предложений по оптимизации структуры Правительства. В.ПУТИН: Дмитрий Анатольевич, я знаю, что у Вас есть предложения по структурным изменениям [Правительства], мы с Вами их раньше обсуждали. Похоже, что есть окончательные предложения. Пожалуйста. Д.МЕДВЕДЕВ: Да, Владимир Владимирович, хотел бы с учётом того обсуждения, которое у нас было, представить на суд Президента ряд предложений по оптимизации структуры Правительства. Правительство – не застывшая структура, оно должно меняться. В соответствии с рядом Ваших указов за последнее время были созданы органы управления, которые занимаются решением экономических и социальных задач по территориальному признаку, а именно Министерство по развитию Дальнего Востока, Министерство по делам Крыма и Министерство по развитию Северного Кавка
module Refinements
refine Object do
def derp
yield self
end
end
end
module A
using Refinements
require 'infoboxer'
page = Infoboxer.wikipedia.get('List of urban areas by population')
res = page
.sections(/Urban areas/).tables.first
.rows[1..-1].map { |r|
{
city: r.cells[2].to_s,
country: r.cells.templates.first.name, # What you see as Japan on page, in page code looks like {{JPN}}