Skip to content

Instantly share code, notes, and snippets.

View Lackoftactics's full-sized avatar

Przemyslaw Mroczek Lackoftactics

  • Warsaw, Poland
  • 00:25 (UTC +02:00)
View GitHub Profile
EXPLAIN SELECT "customers".*,
coalesce("customer_bookings"."appointments", 0) AS "appointments",
coalesce("customer_bookings"."no_shows", 0) AS "no_shows",
"customer_bookings"."last_appointment" AS "last_appointment",
coalesce("customer_sales"."total_sales", 0) AS "total_sales",
greatest("customer_payments_accumulators"."unpaid_amount", 0) AS "outstanding",
"locations"."name" AS "last_location"
FROM "customers"
LEFT OUTER JOIN
(SELECT COUNT(*) FILTER(
@Lackoftactics
Lackoftactics / marketing.sql
Created May 21, 2019 09:52
Marketing populate
do $$
begin
for i in 1..10 loop
INSERT INTO public.providers (name, description, address, online_booking, cancellation_policy, cancellation_time, website, contact_numbers, currency_code, country_code, time_zone, created_at, updated_at, print_receipts, receipt_message, prices_include_tax, beginning_of_week, default_calendar_view, time_slot_minutes, sms_enabled, business_type_id, widget_allows_employee_selection, widget_max_advance_time_in_months, commission_before_discount, commission_after_tax, time_format, voucher_expiration_period, locale, payments_activated, marketplace_enabled, marketplace_info, checkout_version, sale_custom_header_1, sale_custom_header_2, sale_show_customer_info, new_appointment_modal, new_appointment_summary, advance_notice_time_in_seconds, appointment_color_source, custom_invoice_title, payments_coming_soon, payments_enabled, new_taxes, sale_show_customer_address, zendesk_enabled, payments_enabled_by_provider, hidden_from_marketplace, payments_required, payment_due, new_cal
@Lackoftactics
Lackoftactics / CurrentWeather.vue
Last active February 24, 2019 21:43
Code review part I
<div class="row">
{{ $t("WIND") }}:
{{
** This ternary operator looks weird here, logic should be probably moved to function **
getWindDirection(weather.wind ? weather.wind.direction : 400)
}}
| {{ weather.wind ? weather.wind.speed : "n/a" }}m/s
</div>
@Lackoftactics
Lackoftactics / oj.rb
Created October 7, 2018 00:15
Big note on json parsing
gem 'oj'
gem 'oj_mimic_json'
#this will make you happy
# faster json rendering using oj
@Lackoftactics
Lackoftactics / index.html
Created July 11, 2018 14:50
Inline style
<textarea name="comment" id="comment" cols="30" row="30" style="height:60px; width:300px" placeholder="Enter your comment..."></textarea>
In Ruby, &method passes you!
Most Rubyists would know what the following does.
[1, 2, 3].map(&:to_s)
It takes the array of numbers, calls to_s on each item, and returns an array of the return values.
But what if you want to do the opposite? Rather than calling a method on the object, what if you want to call a method with the object as a parameter? Simple!
["1", "2", "3"].map(&method(:Integer))
def pause_capybara
$stderr.write "
Capybara paused!
App running at http://localhost:#{Capybara.current_session.server.port}
Press enter to continue..."
$stdin.gets
end
@Lackoftactics
Lackoftactics / rotate
Created March 6, 2018 12:44
rotate matrix
You are given an n x n 2D matrix that represents an image. Rotate the image by 90 degrees (clockwise).
Example
For
a = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
the output should be
@Lackoftactics
Lackoftactics / capybara_debug.rb
Created March 5, 2018 12:59
Capybara easier debugging, look on browser
Capybara.server_port = 9887
Capybara.app_host = "http://#{ENV['APP_HOST']}:#{Capybara.server_port}"
Capybara.always_include_port = true
Capybara.register_driver :chrome do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
@Lackoftactics
Lackoftactics / kill_by_port.sh
Created March 5, 2018 12:23
Find process by port for later killing
netstat -vanp tcp | grep 3000