Skip to content

Instantly share code, notes, and snippets.

@mtkd
mtkd / gist:2438167
Created April 21, 2012 16:27
Remove delay from OSX dock show/hide
defaults write com.apple.Dock autohide-delay -float 0 && killall Dock
@mtkd
mtkd / status_codes.txt
Created July 6, 2012 19:55
HTTP Status Code Symbols
1xx Informational
100 Continue :continue
101 Switching Protocols :switching_protocols
102 Processing :processing
2xx Success
200 OK :ok
201 Created :created
202 Accepted :accepted
203 Non-Authoritative Information :non_authoritative_information
@mtkd
mtkd / sublime_user.txt
Last active October 7, 2015 18:57
Sublime User Settings
{
"auto_complete": false,
"auto_match_enabled": false,
"bold_folder_labels": true,
"color_scheme": "Packages/Color Scheme - Default/Twilight.tmTheme",
"drag_text": false,
"draw_white_space": "selection",
"fold_buttons": false,
"font_face": "M+ 1M thin",
"font_size": 16.0,
@mtkd
mtkd / gist:3393155
Created August 19, 2012 07:16
Pretty print a mongoid document
JSON.pretty_generate(JSON.parse(obj.to_json))
@mtkd
mtkd / gist:3586053
Created September 1, 2012 20:19
Mongoid array timings
#188s
(0..10000).each do
document1.sub_documents << document2
end
#119s
(0..10000).each do
document1.push(:sub_document_ids, document2._id)
end
@mtkd
mtkd / gist:3728976
Created September 15, 2012 17:34
ActiveModel::Serializer and :only
class FooSerializer < ActiveModel::Serializer
attributes :_id, :name
def attributes
h = super
h.select! { |x| options[:only].include? x } if options[:only]
h
end
end
@mtkd
mtkd / gist:3729321
Last active October 10, 2015 17:58
Curl options
# return only HTTP status code
curl -sL -w "%{http_code}\\n" "http://news.ycombinator.com/" -o /dev/null
# return only HTTP status code and 302 URL
curl -sL -w "%{http_code} %{url_effective}\\n" "http://news.ycombinator.com/" -o /dev/null
# header only
curl -I news.ycombinator.com
# basic auth
@mtkd
mtkd / mail_send_example.rb
Created March 17, 2013 12:55
Simple Ruby SMTP send example
require 'net/smtp'
message = <<MESSAGE_END
From: Sender <name@sender_domain.com>
To: Receiver <name@receiver_domain.com>
Subject: SMTP e-mail test
This is a test e-mail message.
MESSAGE_END
@mtkd
mtkd / gist:5608396
Last active December 17, 2015 12:19
Install Sublime Text 2 settings
cd ~/Library/Application Support/Sublime Text 2/Packages
mv ./User/ ./User_old/
ln -s ~/Dropbox/Sublime/Packages/User ./User
# Edit this in Package/Color Scheme - Default/Twilight
# <key>lineHighlight</key>
# <string>#302030</string>
@mtkd
mtkd / test_exception_message
Last active December 27, 2015 19:29
Test exception message
exc = assert_raises Mongoid::Errors::Validations do
subject.do_something
end
assert exc.message.include?("something failed")