Skip to content

Instantly share code, notes, and snippets.

View mkdynamic's full-sized avatar

Mark Dodwell mkdynamic

View GitHub Profile
@mkdynamic
mkdynamic / web-servers.md
Created September 30, 2022 00:29 — forked from willurd/web-servers.md
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@mkdynamic
mkdynamic / bundles.sh
Created June 18, 2010 02:31
Install all of http://github.com/phuibonhoa's TM bundles (OS X only)
#!/usr/bin/env bash
#
# install all of http://github.com/phuibonhoa's TM bundles (OS X only)
#
echo "Installing bundles..."
# backup dir
if [ -d ~/desktop/_tm_bundle_backups ]; then rm -rf ~/desktop/_tm_bundle_backups; fi
@mkdynamic
mkdynamic / ajaxsubscribe.html
Last active December 7, 2017 08:18 — forked from jdennes/LICENSE
<!-- 1. Take your Campaign Monitor subscribe form as generated from within your account: -->
<form action="http://myaccount.createsend.com/t/r/s/aljhk/" method="post" id="subForm">
<div>
<label for="name">Name:</label><br /><input type="text" name="cm-name" id="name" /><br />
<label for="aljhk-aljhk">Email:</label><br /><input type="text" name="cm-aljhk-aljhk" id="aljhk-aljhk" /><br />
<input type="submit" value="Subscribe" />
</div>
</form>
@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 / jpp.rb
Created December 19, 2013 08:35
Pretty print JSON command.
#!/usr/bin/env ruby
require 'optparse'
require 'json'
options = {}
OptionParser.new do |opts|
opts.banner = "Usage: example.rb [options]"
opts.on("-x", "--extended", "Use awesome print") do |*|
class Todo < ActiveRecord::Base
concerning :EventTracking do
included do
has_many :events
end
def latest_event
...
end
@mkdynamic
mkdynamic / monkey.rb
Created December 15, 2013 05:23
Use class_eval for monkey patching classes, to avoid forgetting to load the target class and ending up with a more cryptic type error.
# 1. in one file, assuming that Foo is loaded/auto-loaded
class Foo
def monkey_patch
# ...
end
end
# 2. later, the real Foo (in another file) is loaded
class Foo < File
end
@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")
@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 / 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