make your own tools

17
MAKE YOUR OWN TOOLS ChristopherCotton.com @_cotton 2013-03-07 Nashville Ruby on Rails Meetup

Upload: christophercotton

Post on 26-May-2015

122 views

Category:

Technology


8 download

DESCRIPTION

Why and how you should make your own tools, with some examples. Talk for the Nashville Ruby on Rails Meetup

TRANSCRIPT

Page 1: Make Your Own Tools

MAKEYOUR OWN

TOOLS

ChristopherCotton.com @_cotton 2013-03-07

Nashville Ruby on Rails Meetup

Page 2: Make Your Own Tools

Why?

Repetition Sucks Repetition Sucks

Text

Repetition Sucks

Repetition Sucks

Repetition Sucks

Repetition Sucks

Repetition Sucks

Repetition SucksRepetition Sucks

Repetition Sucks

Repetition Sucks

Repetition Sucks

Repetition SucksRepetition Sucks

Repetition Sucks

Repetition Sucks

Repetition Sucks

Repetition SucksRepetition Sucks

Page 3: Make Your Own Tools

Why?

Code Easier than Manual

Page 4: Make Your Own Tools

Why?

Transferof Knowledge

Page 5: Make Your Own Tools

What?

Simple Lines of Ruby

Command Line Tools

Simple Webapps

Apply lots of Regex, Regex, Regex

Page 6: Make Your Own Tools

HOW?DOES IT WORK?

Page 7: Make Your Own Tools

NOT PRETTYHOW?

Page 8: Make Your Own Tools

I BUILT WHAT? HOW?

Page 9: Make Your Own Tools

EXAMPLES

Page 10: Make Your Own Tools

build.rbAndroid Building

OptionParser.new do |o| o.on('-d', '--deploy [DIR]', 'Deploy to HST, can pass in directory') { |dir| $deploy_dir = dir || "#{ENV['HOME']}/Hst/Dropbox" o.on('-r', '--release KEYSTORE', 'Keystore for the relase build') { |key| $keystore = key } o.on('-h', 'Print out help') { puts o; exit } o.parse!end

ensure_local_properies(File.join(buildtarget_dir, "facebook"), android_sdk_location)

# modify the AndroidManifest.xmlReplacement.file(File.join(buildtarget_dir, "AndroidManifest.xml")) do |rp| rp.buffer.gsub!(/package="#{package_prefix}.#{old_package}"/, "package=\"#{package_prefix}.#{package}\"")end

Page 11: Make Your Own Tools

copy_assets.rbImage Asset Copying

rsync to copy assets

scale for non-retina versions

create .h/.m Object C for constants

File.open(File.join(root_dir, "Primer", "AssetConstants.h"),'w') do |file| file.puts "// Do not edit this file, it is auto generated by #{File.basename(__FILE__)}" file.puts "" image_files.each do |image| file.puts "FOUNDATION_EXPORT NSString *const kAsset_#{File.basename(image, File.extname(image))};" endend

Page 12: Make Your Own Tools

Mini Server

Page 13: Make Your Own Tools

translation helper

def trans2(eng, language) File.open("otherresources/#{ARGV[0]}_trans2.txt", "w") do |o| eng.each_with_index.select do |line, index| if line =~ /<key>(.+)<\/key>/ o.puts("") o.puts("Category\t#{unquote($1)}") end

if line =~ /<string>(.+)<\/string>/ o.print("\t#{unquote($1)}") language[index] =~ /<string>(!?)(.+)<\/string>/ o.puts("\t#{unquote($2)}\t#{$1}") end end endend

Page 14: Make Your Own Tools

check_assets.rb

assets = {}total_dirs = 0

Dir.glob(File.join(dropbox, "*")).each do |root_dir|! next unless File.directory?(root_dir)! total_dirs += 1! dir_name = File.basename(root_dir)! Dir.glob(File.join(root_dir, "*")).each do |file|! ! name = File.basename(file)! ! assets[name] = (assets[name] || []).push(dir_name) ! !! end!end

assets.each do |key,value|!! puts "#{key} = #{value.inspect}" unless total_dirs == value.lengthend

Page 15: Make Your Own Tools

Image Extraction, Composition

Spaceward Ho!

Page 16: Make Your Own Tools

Share Your Tool

Open Source

Can Happen Much Later

Version Control

Page 17: Make Your Own Tools

Q & A