Skip to content

Instantly share code, notes, and snippets.

View rlisowski's full-sized avatar

Rafał Lisowski rlisowski

  • Warsaw, Poland
View GitHub Profile
  1. Open Automator.app
  2. Create new Quick Action
  3. Select Run AppleScript
  4. Add this:
set inputVolume to input volume of (get volume settings)
if inputVolume = 0 then
	set inputVolume to 100
	display notification "Volume set to 100" with title "✅ Microphone is on"
@rlisowski
rlisowski / arel_cheatsheet_on_steroids.md
Created February 7, 2020 08:14 — forked from ProGM/arel_cheatsheet_on_steroids.md
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

@rlisowski
rlisowski / TabNineExample.toml
Created February 5, 2019 08:50
TabNineExample.toml
[language.rust]
command = "rls"
install = [
["rustup", "update"],
["rustup", "component", "add", "rls", "rust-analysis", "rust-src"],
]
[language.javascript]
command = "flow"
args = ["lsp"]
@rlisowski
rlisowski / I18njs_pluralization_pl.js
Created September 24, 2018 14:23
I18njs pluralization pl
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 August 24, 2018 07:00 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

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 February 28, 2018 07:34
Using date ordinals in Rails through an I18n time format.
# 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 November 9, 2017 08:44
MapFIlter filter
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)))'
@rlisowski
rlisowski / elasticsearch_importer.rb
Created October 18, 2017 05:54
MapFilter importer
# 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 October 17, 2017 09:31
MapFilter performance check
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 October 17, 2017 09:28
MapFilter es query indexed shape
query = {
"_source":false,
"query":{
"bool":{
"must":{ "match_all":{} },
"filter":{
"geo_shape":{
"location":{
"relation":"within",
"indexed_shape": {