How to read files from dir and generate html output

2 Comments

When creating videos, I take snapshots of keynote, upload to website, and then manually handcraft the html to include in the show notes. It’s slow, tedious, and not a lot of fun.

So today I created a ruby script to do this for me.

imageconverter.rb

date = ARGV[0] # 2013/06
alt = ARGV[1] # iteration mechanics
basedir = "/Users/jrasmusson/Desktop"
files = Dir.glob(basedir + "/*.png")
files.each do |k|   puts "<img src=\"http://xxx/" + date + "/" + File.basename(k) + "?w=500\" alt=\"" + alt + "\" /><hr>"
end

> ruby imageconverter.rb 2013/06 “iteration mechanics” | pbcopy

<img src="http://xxx/2013/06/im-analysis.png?w=500" alt="iteration mechanics" /><hr>
<img src="http://xxx/2013/06/im-check-the-work.png?w=500" alt="iteration mechanics" /><hr>
<img src="http://xxx/2013/06/im-do-the-work.png?w=500" alt="iteration mechanics" /><hr>
...

To see the output on screen, run without the pbcopy mac command at the end which copies to clip board.

The only thing I haven’t been able to do is make this ruby script globally available from any directory (like a bash script).

If anyone has any ideas on how to do that I would be very grateful.

Advertisements

.bash_profile and handy scripts

2 Comments

Just a copy of my .bash_profile in case I ever forget it.

Misc unix commands
> du -sh *

.bash_profile

export PATH=$PATH:~/scripts
export JAVA_HOME=/Library/Java/Home
alias nutshell='cd /Users/jrasmusson/Developer/agilenutshell'
alias reduce='sips --resampleWidth 200 a.png --out b.png'
alias ios='cd /Users/jrasmusson/Developer/iosbyexample'
alias gs='git status'
alias test='bundle exec rspec spec'

My scripts directory:

ci.sh easy git checkin

#!/bin/bash
echo "Checking in..." 

git add .

if [ -z "$1" ]
then
 git commit -a -m "cleanup"
else
 git commit -a -m "$1"
fi

git push
echo "Done!"

reset.sh resets my git repository

!/bin/bash
echo &amp;amp;quot;Reseting git repository&amp;amp;quot;
git reset --hard HEAD^
git clean -f
git merge origin/master

chmod 711 ci.sh reset.sh

Something that handles ssh

#!/bin/sh

echo "ssh mount..."
ssh -t -t root@192.168.1.107 <<EOF
mount -o remount,rw /system
exit
EOF

echo "copying..."
scp libspotify.so root@192.168.1.107:/system/chrome/plugins/libspotify.so
echo "ssh chmod"
ssh root@192.168.1.107 <<EOF
chmod 0744 /system/chrome/plugins/libspotify.so
reboot
exit
EOF

iOS Boot Camp Coming to Montreal Nov 7-8

Leave a comment

November 7-8 me and my colleagues are going to Montreal for the first time offering our iOS Bootcamp at the Apple Regional office in St-Laurent.

This course is perfect for developers looking to get into iPhone development or just have an idea for an app they’d like build to turn into reality.

If you want to get into iOS development, and you would like a distilled, tight, 2 day course to get you there this is the course for you.

Signup now

See you there.

Jonathan

History of Cocoa

Leave a comment

Some good history of Cocoa from Aaron Hillegass’s book Cocoa Programming.

The window server on Mac OS X is like the X window server on Unix. It gets events from the user, forwards them to the application, and puts data on the screen.

NeXTSTEP came up with a set of libraries to enable programmers to deal with the window manager in an elegant manner. These frameworks were originally called OpenStep, which was later renamed Cocoa.

Programmers loved OpenStep. Tim Berners-Lee developed the first Web browser and the first Web server on NeXTSTEP.

Apple selected NeXTSTEP as there next operating and bought the whole company in December 1996.

NeXTSTEP became Mac OS X. It’s Unix underneath.

Cocao Touch is built on top Cocoa (many of the classes are identical). Most importantly, the principles and design patterns are essentially unchanged.

Objective-C ternary operator

1 Comment

int velocity;
if (isCar)
   velocity = 100;
else
   velocity = 10;

Is the same as:

int velocity = isCar ? 100 : 10;

Another handy NSLog:

NSLog(@"mondaySwitch: %@", (onOff ? @"ON" :@"OFF"));

Computers and School

2 Comments

Hi all. This is a guest post by Olivia Leonardi who asked if I would post this on her behalf.

It’s a post about computers, schools, students, and the important role they play in our society. Regardless of how you feel about computers, it’s pretty clear there’s a big demand for people with computer skills and that trend seems to be ever increasing.

Happy reading.

===========================

In today’s post, Olivia Leonardi finds it hard to believe that American high school students, whose use and reliance on computers and the internet is well documented, often graduate without ever being introduced to computer science and programming languages. Although traditional schools are missing out on computer science curriculum, online programs offer everything from certificates in computer science to full-fledged, fully online degrees. As evidenced by the Agile Warrior’s blog about working with XCode, the online platform of learning allows anyone interested in computer science to learn with and from leaders and fellow students.

Because of School Oversights, Consumers See Dramatic Increase in Online Computer Science Programs

Despite stubbornly high unemployment, in February 2012 more than 5,000 cloud computing job ads were posted online in the U.S. In the past two years, demand for cloud computing skills shot up 400%. However, despite heavy demand, recruiters find that most candidates simply lack the technology skills necessary for these jobs. Even though computer skills becoming increasingly necessary both in the workplace and everyday life, most students in the U.S. can graduate with a high school diploma or even a bachelor’s degree without ever acquiring basic skills in computer programming and functions. In response to this oversight, learners of all types are utilizing online programs and applications to gain valuable computer science skills.

While the outlook for almost every career path today seems fraught with pessimism and uncertainty, computer science is still an unusually safe choice for those entering the workforce. The U.S. Bureau of Labor Statistics predicts that opportunities for computer programmers in the U.S. IT market will grow by 12%. Furthermore, in Computerworld’s Forecast survey, 61% of polled IT executives stated that they plan to hire programmers and application developers through 2012. “Web development continues to be very strong,” says John Reed, executive director of staffing firm Robert Half Technology. Reed asserts that as companies try to improve the user experience, there will also be a lot of effort to develop mobile technology to improve customer access via smart phones, leading to increased need for talented programmers and application developers.

As markets become increasingly global and internet proliferation stretches to the furthest reaches of the planet, freelance positions for computer programmers and technicians are expected to see significant growth, as well. Freelance employment site Elance predicts that more than half the workforce in the U.S. will be freelance by 2020. By that time, savvy internet users will have a marked advantage as they vie for jobs in a truly global candidate pool. Even today, there are myriad excellent resources online for those looking for education in computer sciences.

Web development sites like Webmonkey offer tutorials for various web programming languages as well as user forums that allow fellow users to communicate and aid each other through the lessons. Veteran computer technicians who received their degrees decades ago might be shocked to find the resources available through MITs OpenCourseWare. OCW offers accessible courses in computer science, including introduction to Java, Python, C++ among others from their esteemed faculty for free. Essentially, ambitious coders can experience the same education that students receive at one of the world’s most prestigious technical universities, and despite not receiving course credit, the skills learned can ultimately prove valuable.

Among online programming resources, though, Codecademy has ranked as the most popular. The site allows users to build websites, games and apps while learning alongside fellow users in an interactive and user friendly way. While challenging, Codecademy is also designed to be fully engaging and fun for the learner, offering chances to track progress on a regular basis.

As technology changes the job market, it also changes the way we learn and acquire new skills. Though traditional education has often failed to adequately prepare students with the computer skills they will need for most careers in the 21st century, the innovative online marketplace has assured that low cost resources will be available to any enterprising student willing to learn. As computers continue to connect our planet, resources for education will increasingly become available to those with the drive to learn.

How to create an Objective-C category

1 Comment

What

Categories are objective-c’s way of allowing you to add methods to an existing class without having to touch it’s source.

For example, say we wished had a method on NSString that decorated our string with some pretty output.

- (NSString *) decorate
{
    return [NSString stringWithFormat:@"=== %@ ===", self];;
}

And we wished we could call it directly on NSString like this:

NSLog(@"%@", @"Booya".decorate);

Outputs:

=== Booya ===

Categories allow us to do that. Here’s how.

How

The format of a category is the ClassName you are extending, followed by the name you want to give your category (i.e. “Utils”).

#import "ClassName.h"

@interface ClassName ( CategoryName )
// method declarations
@end

To make a new category in Xcode we basically create a new class. Go:

New File (Command + N).
Select ‘Objective-C category’.

Specify the class you want to add a category onto (i.e. NSString).

Then add your category method to your .h file.

#import <Foundation/Foundation.h>

@interface NSString (Utils)
- (NSString *) decorate;
@end

And your implementation to you .m file.

#import "NSString+Utils.h"

@implementation NSString (Utils)
- (NSString *) decorate
{
    return [NSString stringWithFormat:@"=== %@ ===", self];;
}
@end

Now you can go to the class where you want to use the extension, import your category header and make your method call.

#import "NSString+Utils.h"

- (IBAction)tapMePressed:(id)sender
{
    NSLog(@"%@", @"Booya".decorate);
}

That’s it!

Links that help

Apple documentation on category

Older Entries

%d bloggers like this: