Skip to content

Instantly share code, notes, and snippets.


Przemyslaw Mroczek Lackoftactics

View GitHub Profile
View client_list.sql
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"
View marketing.sql
do $$
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
View CurrentWeather.vue
<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
Lackoftactics / oj.rb
Created Oct 7, 2018
Big note on json parsing
View oj.rb
gem 'oj'
gem 'oj_mimic_json'
#this will make you happy
# faster json rendering using oj
View index.html
<textarea name="comment" id="comment" cols="30" row="30" style="height:60px; width:300px" placeholder="Enter your comment..."></textarea>
View &method.rb
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))
View capybara_pause.rb
def pause_capybara
$stderr.write "
Capybara paused!
App running at http://localhost:#{Capybara.current_session.server.port}
Press enter to continue..."
View rotate
You are given an n x n 2D matrix that represents an image. Rotate the image by 90 degrees (clockwise).
a = [[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
the output should be
Lackoftactics / capybara_debug.rb
Created Mar 5, 2018
Capybara easier debugging, look on browser
View capybara_debug.rb
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|, browser: :chrome)
Lackoftactics /
Created Mar 5, 2018
Find process by port for later killing
netstat -vanp tcp | grep 3000
You can’t perform that action at this time.