Skip to content

Instantly share code, notes, and snippets.

View mkdynamic's full-sized avatar

Mark Dodwell mkdynamic

View GitHub Profile
@mkdynamic
mkdynamic / concerning.rb
Created March 3, 2012 11:03
ActiveSupport::Concern — why?
require 'active_support/concern'
module Foo
extend ActiveSupport::Concern
included do
class_eval do
def self.method_injected_by_foo
# ...
end
@mkdynamic
mkdynamic / ControllerFormAttributes.rb
Created March 11, 2012 23:46 — forked from TheEmpty/ControllerFormAttributes.rb
Trying some different ways to secure a Rails application with user input
module ControllerFormAttributes
def self.included(base)
base.extend ClassMethods
end
module ClassMethods
def form_params_accessors(type, attributes = [])
@form_params_accessors ||= {}
@form_params_accessors[type] ||= attributes
end
.browser {
h3 {
margin-bottom: 10px;
}
ol {
@include pie-clearfix;
}
}
@mkdynamic
mkdynamic / wysihtml5-resize.js
Created May 23, 2012 23:35 — forked from micho/wysihtml5-resize.js
wysihtml5 resize plugin. Depends on jQuery and Underscore
(function () {
var setupRegularResize, setupIframeResize, e;
function bind(a, b) {
return function () {
return a.apply(b, arguments);
};
}
setupRegularResize = (function () {
@mkdynamic
mkdynamic / CoreTextLabel.h
Created October 4, 2012 18:13 — forked from dkasper/CoreTextLabel.h
A multiline label drawn with core text. Needed it for line spacing, can easily be modified to use any core text properties though.
//
// CoreTextLabel.h
// Frost
//
// Created by David Kasper on 10/1/12.
//
#import <UIKit/UIKit.h>
#import <CoreText/CoreText.h>
@mkdynamic
mkdynamic / ios-media-queries.css.scss
Created October 17, 2012 07:30
SASS media query helper for iOS devices
@mixin respond-to($media) {
@if $media == iphone {
@media only screen and (device-width: 320px) and (device-height: 480px) { @content; }
}
@else if $media == iphone-portrait {
@media only screen and (device-width: 320px) and (device-height: 480px) and (orientation: portrait) { @content; }
}
@else if $media == iphone-landscape {
@media only screen and (device-width: 320px) and (device-height: 480px) and (orientation: landscape) { @content; }
}
@mkdynamic
mkdynamic / .gitconfig
Created November 9, 2012 20:04
Git aliases for removing branches
[alias]
begone = "!begone() { git branch -d $1 && git push origin :$1 && git remote prune origin; }; begone"
nix = "!nix() { git branch -D $1 && git push origin :$1; git remote prune origin; }; nix"
@mkdynamic
mkdynamic / file_descriptor_sentry.rb
Created November 21, 2012 23:56
Utility class to help monitor open file descriptors
# Utility class to help monitor open file descriptors
#
class FileDescriptorSentry
class << self
# Return a count of all open file descriptors in the current process.
#
def count_open_fds
ObjectSpace.each_object(IO).count { |o| o.respond_to?(:closed?) && !o.closed? rescue false }
end
@mkdynamic
mkdynamic / capybara_assertions.rb
Created November 25, 2012 03:56
Capybara assertion helpers for plain Test::Unit folks
require 'capybara/session'
# Provider `assert_page_has_X` helpers for all `has_X?` Capybara matchers
#
# For a full list, scope:
# https://github.com/jnicklas/capybara/blob/master/lib/capybara/session.rb
#
module CapybaraAssertions
Capybara::Session::DSL_METHODS.select { |m| m.to_s.match(/^has/) }.each do |m|
define_method "assert_page_#{m.to_s.sub(/\?$/, '')}" do |*args|
@mkdynamic
mkdynamic / Rakefile
Last active December 10, 2015 11:09 — forked from jenslukowski/Rakefile
Including MailCore for RubyMotion project.
# -*- coding: utf-8 -*-
$:.unshift("/Library/RubyMotion/lib")
require 'motion/project'
Motion::Project::App.setup do |app|
# Use `rake config' to see complete project settings.
app.name = 'HelloMailCore'
# Configure MailCore
app.vendor_project("vendor/MailCore", :xcode, :headers_dir => "{../include,libetpan/build-mac/.build/include/libetpan}", :target => "MailCore iOS")