Skip to content

Instantly share code, notes, and snippets.

View wkrsz's full-sized avatar

Wojtek Kruszewski wkrsz

View GitHub Profile
wkrsz / application.rb
Created April 14, 2016 07:08
Log request details at Rack level
View application.rb
config.middleware.use "Loggo"
wkrsz / bootstrap-reload-remote.js
Last active May 3, 2018 08:33
Reload remote bootstrap modal each time it is opened
View bootstrap-reload-remote.js
$(document).on('', '.modal', function () {
var modalData = $(this).data('bs.modal');
// Destroy modal if has remote source – don't want to destroy modals with static content.
if (modalData && modalData.options.remote) {
// Destroy component. Next time new component is created and loads fresh content
// Also clear loaded content, otherwise it would flash before new one is loaded.
wkrsz / gist:3d5ff7f908a180b87498
Last active December 11, 2018 07:03
Stop Safari hanging when selecting the address bar or opening a new tab
View gist:3d5ff7f908a180b87498
This shit has been bugging me for too long, so I went on a hunt and found a workaround.
The Symptoms are as follows:
* Clicking the address bar results in a 1-4 second delay
* Opening links in new tabs results in a 1-4 second delay
* +T results in a 1-4 second delay
* `PressAndHold[<pid>]: IMKServer Stall detected` is present in `/var/log/system.log` at the time of the hang.
It appears to be to do with the PressAndHold helper - the thing that shows an IOS style selection of accents when you hold a key down.
The fix may have some unwanted effects, I haven't really noticed any.
wkrsz / README
Last active March 6, 2018 03:12
Git pre-push hook that shows changes and ask for confirmation when pushing to production repo.
Whenever you push to remote that has "production" in its name,
this hook will show commits and changes and then ask for confirmation.
Copy or symlink to .git/hooks/pre-push.
Deployment by pushing code to remote github repo are very convenient
but prone to accidents. I wanted something that would force me to
review what's being pushed.
My Bash-foo is very limited to suggestions for improvements are very welcome.
wkrsz / gist:ed2407a0c131e094a333
Created August 22, 2014 12:55
assert_select to test helper output
View gist:ed2407a0c131e094a333
class ExampleTest < ActionView::TestCase
test "example" do
helper_output = "<p class='error'>Yo!</p>"
parsed =
assert_select parsed, "p.error"
wkrsz / simple_form.rb
Created September 15, 2013 12:01
I'm using SimpleForm and I wanted to display validation errors as label tags, which has (arguably) accessibility benefits. Here's how to add a custom error_label component that adds correct "for" attribute.
View simple_form.rb
module SimpleForm
module Components
module ErrorLabel
def error_label
if has_errors?
@builder.label(label_target, error_text, label_html_options)
wkrsz / backbone-rivets.config.js
Last active December 18, 2015 04:49 — forked from wulftone/backbone-rivets.config.js
Some funky syntax for Rivets: model.@Attribute, model.attribute, model.computed().
View backbone-rivets.config.js
// Bind to backbone attribute (read/write with get/set, subscribe to change:attribute event):
// data-text="model.@attribute"
// Bind to output of function (calls the function to get value, subscribes to 'change' event):
// data-text="model.computedProperty()
// Bind to attribute (subscribes to 'change' event):
// data-text="model.attr"
wkrsz / config-application.rb
Last active September 19, 2018 00:36
Example on how to extract Devise user ID for Rails TaggedLogger.
View config-application.rb
config.log_tags = [
if user_id = WardenTaggedLogger.extract_user_id_from_request(req)
"#" + user_id.to_s