Skip to content

Instantly share code, notes, and snippets.

Caio Chassot kch

Block or report user

Report or block kch

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kch
kch / gist:1726439
Created Feb 2, 2012
Copy the URLs for the selected messages in Mail to the clipboard.
View gist:1726439
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
require 'cgi'
###################################################################
# Copy the URLs for the selected messages in Mail to the clipboard.
###################################################################
@kch
kch / unicode ops.hs
Created Oct 24, 2011
unicode operators yay!
View unicode ops.hs
#!/usr/bin/env runhaskell
(≤) = (<=)
(≥) = (>=)
(≠) = (/=)
(÷) = (div)
main = do
print (1 2)
print (2 1)
@kch
kch / target_browser.m
Created Jan 28, 2011
Get the path to the frontmost app if it's Safari or Webkit, fallsback to default browser.
View target_browser.m
// ## compile this with:
// clang \
// -framework Foundation \
// -framework AppKit \
// -framework ApplicationServices \
// -fobjc-gc-only \
// -o target_browser \
// target_browser.m
#import <Foundation/Foundation.h>
@kch
kch / browser.rb
Created Jan 28, 2011
browser function used in my appscripts to target Safari or WebKit dynamically
View browser.rb
#!/usr/bin/env ruby
# encoding: UTF-8
require 'appscript'
VALID_BROWSERS = %w[ WebKit Safari ]
# Used in my appscripts to target Safari or WebKit dynamically.
# Returns an Appscript::Application for one of these browsers following this priority:
# 1. is frontmost
# 2. is running and default
@kch
kch / frontmost-browser.sh
Created Jan 28, 2011
Test case for WTF is up with System Events getting the processes for Safari and WebKit
View frontmost-browser.sh
#!/bin/bash
function safari { open -a Safari; }
function webkit { open -a WebKit; }
function reset {
killall Safari 2>/dev/null
killall WebKit 2>/dev/null
}
@kch
kch / mvdn
Created Oct 19, 2010
Rename files to all lowercase in two steps, works on a case-insensitive FS like HFS.
View mvdn
#!/usr/bin/env ruby
# encoding: UTF-8
require 'fileutils'
require 'unicode_utils'
ARGV.each do |f|
f_ = UnicodeUtils.downcase(f)
f__ = "#{f_}_#{rand}"
FileUtils.mv(f, f__)
@kch
kch / ipv6.rb
Created Oct 14, 2010
QUIZZZZS validate an ip v6
View ipv6.rb
#!/usr/bin/env ruby
# encoding: UTF-8
require 'yaml'
def ipv6?(s)
raise NotImplementedError
end
good, bad = YAML::load(DATA.read).values_at *%w[ GOOD BAD ]
results = []
View rb_main.rb
framework 'Cocoa'
# store any new classes created during the requires that follow
LOADED_RUBY_CLASSES = []
class << Object
def inherited(m)
LOADED_RUBY_CLASSES << m
end
end
@kch
kch / gist:602174
Created Sep 29, 2010
NSArrays are tricky bastards
View gist:602174
#!/usr/bin/env macruby
framework 'Cocoa'
cocoa_array = NSArray.new
ruby_array = []
puts ruby_array.count # => 0
puts ruby_array.count { true } # => 0
puts ruby_array.count("whatever") # => 0
@kch
kch / rb-magic-comment
Created Sep 27, 2010
Add the encoding magic comment to the ruby files passed as arguments
View rb-magic-comment
#!/usr/bin/env ruby
# encoding: UTF-8
ARGV.reject! { |path| !File.file?(path) }
(puts DATA.read.gsub("$0", File.basename($0)); exit 1) if ARGV.empty?
ARGV.each do |path|
ls = IO.readlines(path)
ix = ls[0] !~ /^#!/ ? 0 : 1
next if ls[ix] =~ /#.*?coding\s*[:=]\s*\S/
You can’t perform that action at this time.