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 / 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 / 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 / Gemfile
Created June 2, 2017 20:58 — forked from palkan/Gemfile
RSpec profiling with RubyProf and StackProf
gem 'stackprof', require: false
gem 'ruby-prof', require: false
@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 / geo_distance.rb
Last active February 28, 2018 07:40
Distance between two coordinates on earth is usually calculated using Haversine formula
def geo_distance(loc1, loc2)
rad_per_deg = Math::PI/180 # PI / 180
rkm = 6371 # Earth radius in kilometers
rm = rkm * 1000 # Radius in meters
dlat_rad = (loc2[0]-loc1[0]) * rad_per_deg # Delta, converted to rad
dlon_rad = (loc2[1]-loc1[1]) * rad_per_deg
lat1_rad, lon1_rad = loc1.map {|i| i * rad_per_deg }
lat2_rad, lon2_rad = loc2.map {|i| i * rad_per_deg }
@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_locations_importer.rb
Last active October 18, 2017 05:56
MapFilter elasticsearch locations importer
class ElasticsearchLocationsImporter
def call
ElasticsearchImporter.new(
index_alias: 'locations',
mapping: mapping,
payload: locations_body
).call
end
private