Skip to content

Instantly share code, notes, and snippets.

View unixmonkey's full-sized avatar

David Jones unixmonkey

View GitHub Profile
@unixmonkey
unixmonkey / deprecation_handler.rb
Created March 26, 2020 19:11
Deprecation Handler for Rails that ignores deprecations emitted more than once, or custom message regular expressions
# Override Deprecation warnings to only show each unique deprecation message
# once instead of repeating it every time the deprecated code is run.
# This can help prevent the "wall of deprecations" when one commonly-called
# action produces a deprecation over and over again.
#
# You can also add regular expressions to the `@@ignored` array to silence them.
#
if Rails.env.test?
module ActiveSupport
class Deprecation
@unixmonkey
unixmonkey / gist:6b25b404009ed8754cfef58e5df648ed
Created April 1, 2018 12:50
Remove specific validation from model in Rails
def remove_validator!(validator_class, model_class, field)
model_class.class_eval do
_validators[field].reject! { |v| v.class == validator_class }
cb = _validate_callbacks.detect { |c| c.raw_filter.class == validator_class }
_validate_callbacks.delete(cb) if cb
end
end
#!/usr/bin/env ruby
require 'pathname'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file:
@unixmonkey
unixmonkey / capybara_helper_resize.rb
Last active March 10, 2016 19:18
Capybara helper to resize browser for an action, then put it back.
# Wrap some code with this block to change the browser window size
# When the block exits, it will resize to its original dimensions
# with_browser_size(1024, 768) { find('.hidden-sm').click }
def with_browser_size(width, height, &block)
window = Capybara.current_session.driver.browser.manage.window
before_size = window.size
window.resize_to(width, height)
yield
window.resize_to(before_size[:width], before_size[:height])
end
@unixmonkey
unixmonkey / smoosh.rb
Created January 26, 2016 04:56
Object#smoosh
# Fun stuff for training purposes
# Demonstrates:
# Monkey-Patching
# Polymorphism
# Case statements
# Type matching
# Regular Expressions
# Raising errors
# Enumurable#map
# Symbol to Proc
@unixmonkey
unixmonkey / angular_1_router.js
Created September 26, 2015 16:24
Angular 2.0's angular_1_router.js (built at commit #4087e31)
(function(){
'use strict';
/*
* A module for adding new a routing system Angular 1.
*/
angular.module('ngComponentRouter', [])
.directive('ngOutlet', ngOutletDirective)
.directive('ngOutlet', ngOutletFillContentDirective)
.directive('ngLink', ngLinkDirective);
@unixmonkey
unixmonkey / keybase.md
Created January 13, 2015 03:04
keybase.md

Keybase proof

I hereby claim:

  • I am unixmonkey on github.
  • I am unixmonkey (https://keybase.io/unixmonkey) on keybase.
  • I have a public key whose fingerprint is 4410 F05C 0581 480F 39BB 6636 8DBB 5317 AFCF B014

To claim this, I am signing this object:

@unixmonkey
unixmonkey / pre-commit
Last active August 1, 2018 20:34
git pre-commit hook to prevent check-in of debugger stuff
#!/usr/bin/env ruby
# This pre-commit hook aims to prevent you from *accidentally* committing debugger
# statements if installed in your project. You can force a commit if necessary with:
# `git commit --no-verify`.
# Install by copying it to <your-project-dir>/.git/hooks/pre-commit'
hits = []
rb_debuggers = ['binding\.pry', 'binding\.remote_pry', 'debugger', 'focus: true', ':focus => true', 'save_and_open_page', 'save_and_open_screenshot']
js_debuggers = ['console\.log', 'debugger']
/*
* Copyright (c) 2007-2014 by Apple Inc.. All rights reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
@unixmonkey
unixmonkey / qt_on_osx_yosimite.patch
Created June 12, 2014 19:38
QT 4.8.6 on OSX Yosemite
--- ./qt-everywhere-opensource-src-4.8.6/src/gui/kernel/qcocoaapplicationdelegate_mac.mm 2014-06-12 10:20:38.000000000 +0300
+++ ./qt-everywhere-opensource-src-4.8.6/src/gui/kernel/qcocoaapplicationdelegate_mac.mm 2014-06-12 21:59:18.000000000 +0300
@@ -122,7 +122,7 @@
[dockMenu release];
[qtMenuLoader release];
if (reflectionDelegate) {
- [NSApp setDelegate:reflectionDelegate];
+ [[NSApplication sharedApplication] setDelegate:reflectionDelegate];
[reflectionDelegate release];
}