Skip to content

Instantly share code, notes, and snippets.

View indirect's full-sized avatar

André Arko indirect

View GitHub Profile
@indirect
indirect / safari.rb
Created March 31, 2011 18:52
capture stdout from curl and display it in safari, useful for API debugging
#!/usr/bin/env ruby
# Pipe to Safari. Use like this:
# chmod +x safari.rb
# curl site.com/api/foo | safari.rb
File.open("/tmp/to_safari.html", "w") do |f|
f.write ARGF.read
end
`open -a 'Safari' /tmp/to_safari.html`
@indirect
indirect / clip.rb
Created April 1, 2011 18:00
filter the clipboard with a regex
module Kernel
def pbpaste
`pbpaste`
end
def pbcopy(object)
IO.popen('pbcopy', 'w') { |pb| pb << object.to_s }
end
def pbfilter(filter)
@indirect
indirect / .gitconfig
Created April 1, 2011 20:05
get the sha of the current commit
[alias]
sha = log -1 --pretty=format:%H
cpsha = !git sha | pbcopy
@indirect
indirect / hash_from_xml_fixer.rb
Created April 14, 2011 09:25
fix Hash.from_xml when tags with attributes are empty except for whitespace
# This seems somewhat silly, but in Rails (at least as of version 3.0.6), the
# Hash.from_xml method seems to consider a single newline so important that it
# will not parse any of the tag attributes, instead returning just the newline.
# This middleware fixes that by stripping out those newlines.
#
# The bug is fixed by a commit to rails that is not yet included in a 3.0.x
# release as of 2011-04-14. Hopefully this middleware can be removed once the
# next 3.0.x release comes out.
# https://github.com/rails/rails/commit/b41d8f30debc92ac24003d42c0b50a1d6e36cfa1
class HashFromXmlFixer
@indirect
indirect / better_logger.rb
Created July 19, 2011 07:00
Rails 3 logs with severity and PIDs
# You must require this file in application.rb, above the Application
# definition, for this to work. For example:
#
# # Syslog-like Rails logs
# if Rails.env.production?
# require File.expand_path('../../lib/better_logger', __FILE__)
# end
#
# module MyApp
# class Application < Rails::Application
@indirect
indirect / DefaultKeyBinding.dict
Last active February 7, 2020 04:55
Type many useful symbols like ↑, ⌘, and ★
/* Put this in ~/Library/KeyBindings/DefaultKeyBinding.dict */
/* Based on a file from @eventualbuddha */
{
/* Modifier keys: start with C-m */
"^m" = {
"^ " = ("insertText:", "\U2423"); /* C-space space */
"^e" = ("insertText:", "\U21A9"); /* C-e return */
"e" = ("insertText:", "\U2305"); /* e enter */
@indirect
indirect / SearchProviders.plist
Created July 23, 2011 16:06
SafariOmnibar search keywords
<key>SafariOmnibar_SearchProviders</key>
<array>
<dict>
<key>Name</key>
<string>Google</string>
<key>Keyword</key>
<string>g</string>
<key>Default</key>
<true/>
<key>SearchURLTemplate</key>
@indirect
indirect / snippet.sh
Created July 30, 2011 02:53
set PWD in Lion Terminal.app from screen
# Screen-compatible update_terminal_cwd()
update_terminal_cwd() {
# Identify the directory using a "file:" scheme URL,
# including the host name to disambiguate local vs.
# remote connections. Percent-escape spaces.
local SEARCH=' '
local REPLACE='%20'
local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
# Include the escapes needed for screen to forward to Terminal.app
printf '\eP\e]7;%s\a\e\\' "$PWD_URL"
@indirect
indirect / gist:1121595
Created August 3, 2011 00:20
mySQL launchd plist that stops mysql quickly
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>com.mysql.mysqld</string>
<key>Program</key>
@indirect
indirect / gist:1124029
Created August 3, 2011 22:39
print the definition of a function in bash
$ type -a psg
psg is a function
psg ()
{
ps wwwaux | egrep -i "($1|%CPU)" | grep --colour=auto -v grep
}