Skip to content

Instantly share code, notes, and snippets.

Avatar

Victor Shepelev zverok

View GitHub Profile
@zverok
zverok / unmunch.py
Created May 9, 2021
"Unmunch" (linearize) word list from Hunspell dictionary with the help of Spylls library
View unmunch.py
# 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:
@zverok
zverok / err1.md
Last active Jan 19, 2020
Example of how Ruby's error formatting breaks Markdown
View err1.md

(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`.
View produce.rb
# 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]
View jruby-vs-refine.rb
module Refinements
refine Object do
def derp
yield self
end
end
end
module A
using Refinements
View infoboxer-list-of-areas.rb
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}}
View gimme_gem.rb
# Small thing for installing gems on-the-fly.
# Useful for "self-contained" scripts, too small to be
# distributed with own Gemfile & README and stuff.
#
# Usage:
#
# gimme_gem 'sequel' # Checks OR installs the gem
# Sequel.connect 'mysql://....'
#
# All credits for managing RubyGems code goes to author
View good_data_frame.rb
# 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'],
View gist:6785c213fd78430cd423
require 'pp'
class Path < Struct.new(:start_node, :end_node, :color, :type)
def to_s
[start_node, end_node, color, type].join(' ')
end
end
class Test
View gist:4b42441bbbbc9a319ed7
// до всего - присваиваем темам последовательные индексы
// нумерация раздельная для своих и конкурентов
labels.
filter(function(l){return l.is_competitor;}).
forEach(function(l, i){l.number = i});
labels.
filter(function(l){return !l.is_competitor;}).
forEach(function(l, i){l.number = i});
View gist:3f458782c8f63ceaddda
build_color_map: function(labels){
var colors = _colors.slice(0),
colors_c = _colors.slice(0);
angular.forEach(labels, function(label){
if(label.is_competitor){
_color_map_c[label.label] = colors_c.shift();
} else {
_color_map[label.label] = colors.shift();
}