Skip to content

Instantly share code, notes, and snippets.

Rafał Lisowski rlisowski

  • Warsaw, Poland
Block or report user

Report or block rlisowski

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View TabNineExample.toml
[language.rust]
command = "rls"
install = [
["rustup", "update"],
["rustup", "component", "add", "rls", "rust-analysis", "rust-src"],
]
[language.javascript]
command = "flow"
args = ["lsp"]
View I18njs_pluralization_pl.js
I18n.pluralization["pl"] = function (count) {
var n = count || 0
var mod10 = count % 10
var mod100 = count % 100
key = "zero"
if ( n == 0 ) {
key = "zero";
} else if ( n == 1 ) {
@rlisowski
rlisowski / clean_code.md
Created Aug 24, 2018 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin
View clean_code.md

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@rlisowski
rlisowski / en.rb
Created Feb 28, 2018
Using date ordinals in Rails through an I18n time format.
View en.rb
# This goes in config/locales/en.rb (*not* en.yml)
{
:en => {
:date => {
:formats => {
:short => lambda { |date, _| "%b #{date.day.ordinalize}" },
:long => lambda { |date, _| "%B #{date.day.ordinalize}, %Y" }
}
},
:time => {
@rlisowski
rlisowski / filter.rb
Created Nov 9, 2017
MapFIlter filter
View filter.rb
Location.
where('ST_Covers(?, coordinates)', Shapefile.where(area_name: 'BR2').first.geometry.to_s).
size
# produces two SQL queries, the filter query look like
# SELECT Count(*)
# FROM "location"
# WHERE (
# St_covers(
# 'MULTIPOLYGON (((0.004218521268697022 51.38840811418139, ... , 0.004218521268697022 51.38840811418139)))'
View elasticsearch_importer.rb
# Import the data into Elasticsearch
class ElasticsearchImporter
def call
create_new_index
swap_alias
import
delete_old_index
end
# == Parameters:
@rlisowski
rlisowski / performance.txt
Created Oct 17, 2017
MapFilter performance check
View performance.txt
Warming up --------------------------------------
PostgreSQL join 1.000 i/100ms
PostgreSQL param 1.000 i/100ms
ES indexed shape 8.000 i/100ms
ES shape in query 2.000 i/100ms
Calculating -------------------------------------
PostgreSQL join 4.282 (± 0.0%) i/s - 22.000 in 5.139615s
PostgreSQL param 3.637 (± 0.0%) i/s - 19.000 in 5.231438s
ES indexed shape 115.272 (±10.4%) i/s - 576.000 in 5.054716s
ES shape in query 21.279 (± 4.7%) i/s - 106.000 in 5.006692s
@rlisowski
rlisowski / es_query.rb
Created Oct 17, 2017
MapFilter es query indexed shape
View es_query.rb
query = {
"_source":false,
"query":{
"bool":{
"must":{ "match_all":{} },
"filter":{
"geo_shape":{
"location":{
"relation":"within",
"indexed_shape": {
@rlisowski
rlisowski / es_query.rb
Created Oct 17, 2017
MapFilter es query
View es_query.rb
query = {
"_source":false,
"query":{
"bool":{
"must":{ "match_all":{} },
"filter":{
"geo_shape":{
"location":{
"relation": "within",
"shape": RGeo::GeoJSON.encode(Shapefile.where(area_name: 'BR2').first.geometry)
@rlisowski
rlisowski / elasticsearch_locations_importer.rb
Last active Oct 18, 2017
MapFilter elasticsearch locations importer
View elasticsearch_locations_importer.rb
class ElasticsearchLocationsImporter
def call
ElasticsearchImporter.new(
index_alias: 'locations',
mapping: mapping,
payload: locations_body
).call
end
private
You can’t perform that action at this time.