This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# find arrangements of numbers from 1 to 8, so that | |
# if they're put into matrix like this, no consequentive numbers | |
# would "touch" directly or diagonally. | |
# 0 1 | |
# 2 3 4 5 | |
# 6 7 | |
next_neighbours = [[1,2,3,4], [3,4,5], [3,6], [4,6,7], [5,6,7], [7], [7]] | |
result = [*1..8].permutation.filter do |row| | |
next_neighbours.each_with_index.none? do |neighbours, current| |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
! function() { | |
function e(e) { | |
var n = "", | |
t = "?"; | |
for (var r in e) { | |
var o = e[r], | |
a = "boolean" == typeof o ? o ? r : null : o; | |
a && (n += t + "cv[]=" + encodeURIComponent(a), t = "&") | |
}(new Image).src = "http://d.mobilebanner.ru/p.gif" + n | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%% generated code, do not edit! | |
-ifndef(kpro_hrl). | |
-define(kpro_hrl, true). | |
-include("kpro_common.hrl"). | |
-record(kpro_packet, | |
{ size :: kpro:int32() | |
, payload :: kpro_packet_payload() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env rspec | |
shared_examples "#flatten" do | |
it "should flatten empty array" do | |
expect( flatten([]) ).to eq [] | |
end | |
it "should flatten single level array" do | |
expect( flatten([1, 2, 3]) ).to eq [1, 2, 3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
name: example-DIH-db | |
version: 1.6 | |
uniqueKey: id | |
fieldTypes: | |
- name: alphaOnlySort | |
class: solr.TextField | |
omitNorms: true | |
sortMissingLast: true | |
analyzer: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[busfor_prod] # explain analyze SELECT * FROM cities where id in (select from_id FROM timetable_segments UNION ALL SELECT to_id FROM timetable_segments); | |
QUERY PLAN | |
------------------------------------------------------------------------------------------------------------------------------------------------------------- | |
Nested Loop (cost=747.24..1988.45 rows=19318 width=442) (actual time=12.208..13.778 rows=606 loops=1) | |
-> HashAggregate (cost=746.95..748.95 rows=200 width=4) (actual time=12.194..12.311 rows=606 loops=1) | |
Group Key: timetable_segments.from_id | |
-> Append (cost=0.00..665.16 rows=32716 width=4) (actual time=0.012..7.302 rows=32716 loops=1) | |
-> Seq Scan on timetable_segments (cost=0.00..332.58 rows=16358 width=4) (actual time=0.012..2.133 rows=16358 loops=1) | |
-> Seq Scan on timetable_segments timetable_segments_1 (cost=0.00..332.58 rows=16358 width=4) (actual time=0.00 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cube(relation, keys) | |
rs = relation.group("cube (#{keys.join(', ')})").pluck(*keys, 'count(*)', "grouping(#{keys.join(', ')})") | |
hs = {} | |
rs.group_by(&:pop).each do |grouping, rows| | |
hs[select_by_bitmask(grouping, keys)] = | |
rows.map do |*indexes, value| | |
[select_by_bitmask(grouping, indexes), value] | |
end.to_h | |
end | |
hs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Regroup | |
module_function | |
# Makes a tree out of a flat hashes with array keys. | |
# Useful for transformation of things like | |
# relation.group(:a).group(:b).group(:c).count | |
# to a hash of hash of hahes of any depth. | |
# Safe for usage with plain hashes, too. | |
# |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# stupid but working updating postgresql to 9.5.0 with homebrew on OSX | |
brew update | |
# if you already updated and have your old databases inacessible, just do | |
# ls /usr/local/Cellar/postgresql | |
# for versions, then | |
# brew switch postgresql 9.4.5 | |
# or whatever version you had before |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
raw = {"city"=>{"geoname_id"=>524901, "names"=>{"de"=>"Moskau", "en"=>"Moscow", "es"=>"Moscú", "fr"=>"Moscou", "ja"=>"モスクワ", "pt-BR"=>"Moscovo", "ru"=>"Москва", "zh-CN"=>"莫斯科"}}, | |
"continent"=> | |
{"code"=>"EU", | |
"geoname_id"=>6255148, | |
"names"=>{"de"=>"Europa", "en"=>"Europe", "es"=>"Europa", "fr"=>"Europe", "ja"=>"ヨーロッパ", "pt-BR"=>"Europa", "ru"=>"Европа", "zh-CN"=>"欧洲"}}, | |
"country"=> | |
{"geoname_id"=>2017370, | |
"iso_code"=>"RU", | |
"names"=>{"de"=>"Russland", "en"=>"Russia", "es"=>"Rusia", "fr"=>"Russie", "ja"=>"ロシア", "pt-BR"=>"Rússia", "ru"=>"Россия", "zh-CN"=>"俄罗斯"}}, | |
"location"=>{"latitude"=>55.7522, "longitude"=>37.6156, "time_zone"=>"Europe/Moscow"}, |
NewerOlder