Skip to content

Instantly share code, notes, and snippets.

@mikbe
mikbe / pageload.coffee
Created May 11, 2014 19:47
TurboLink Workaround
$(window).on 'ready page:load', ->
# Your code
@mikbe
mikbe / gist:e4b68c89f678556afd8e
Created November 13, 2014 18:01
Never start tab index with zero!
<html>
<head>
<title>TabIndex Example - 0</title>
</head>
<body>
This will jump from tab 0 to the address bar.
<br />
<label>Tab 0</label>
<input tabindex="0" type="text" />
<br />
@mikbe
mikbe / gist:6cb1254a3cca53a2b8d2
Last active August 29, 2015 14:09
Always start tabindex with 1
<html>
<head>
<title>TabIndex Example - 1</title>
</head>
<body>
This will jump from tab 1 to tab 2.
<br />
<label>Tab 1</label>
<input tabindex="1" type="text" />
<br />
@mikbe
mikbe / md.sh
Created March 8, 2011 14:59
Bash: Make a directory and change into it in one easy command
#!/bin/bash
# You should add this to your .profile file
md () { mkdir -p "$@" && cd "$@"; }
@mikbe
mikbe / chd.sh
Created March 8, 2011 16:17
Bash: Change to a directory given a full or partial name
#!/bin/bash
# Change to a directory given a full or partial name
# You don't have to wrap directory names in quotes either
chd() {
if [ -n "$@" ]; then
if [ -n "`ls "$@"* 2>/dev/null`" ]; then
cd "$@"*
else
echo "-bash: chd: "$@": No directory could be extrapolated from partial name"
fi
@mikbe
mikbe / gist:1012758
Created June 7, 2011 17:57
spec/ruby/library/socket/tcpsocket/open_spec.rb
bin/mspec spec/ruby/library/socket/tcpsocket/open_spec.rb
rubinius 1.2.4dev (1.8.7 90126691 yyyy-mm-dd JI) [x86_64-apple-darwin10.7.0]
....E.
1)
TCPSocket.open with a running server connects to a server when passed local_host and local_port arguments ERROR
Errno::EAFNOSUPPORT: Address family not supported by protocol family - bind(2)
Errno.handle at kernel/common/errno.rb:16
TCPSocket#tcp_setup at lib/socket.rb:1085
TCPSocket#initialize at lib/socket.rb:1013
@mikbe
mikbe / argf.rb
Created June 8, 2011 00:05
Change to argf - works command line, not
kernel/loader.rb : line 279
options.on "-i", "[EXT]", "Edit ARGV files in place, making backup with EXT" do |ext|
# in place edit mode
$-i = ext || true
end
kernel/common/argf.rb : line 476
def advance!
@mikbe
mikbe / thread_unsafe.rb
Created June 17, 2011 12:17
Verify thread collisions are possible
require 'thread'
class Foo
attr_accessor :bar
def baz
@bar ||= rand(10000000000)
end
end
@mikbe
mikbe / ugly_spec.rb
Created July 6, 2011 01:20
What's a better way to test if a block is passed on?
it "should pass along blocks if given" do
class Baz3
def initialize(attributes = nil, &block)
yield if block_given?
end
end
class Qiz3 < Baz3
include Eventable
end
@mikbe
mikbe / class_mutex.rb
Created July 6, 2011 21:59
Class level mutex
require 'benchmark'
module SuperMutex
attr_reader :bar
def self.included(base)
base.extend(ThreadSafeClassMethods)
base.threadsafe_class_mutex = Mutex.new
end