Computers


160118

Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

For some reason I couldn't log into a remote server after recreating my ssh keys and cleaning up my keychain on my system. The error that kept coming up was Permission denied (publickey,gssapi-keyex,gssapi-with-mic) After searching around, I found this unanswered post on Stack Exchange that lead me to the solution that worked for me:
First generate the key-pair on your Ubuntu machine. After, copy the contents of the generated .pub file in your ssh folder (~/.ssh/id_rsa) and paste it to the username/.ssh/id_rsaauthorized_keys file, on a new line, on your CentOS for the specific user you are logging in with.
Share Button

151117

Command Line Mounting AFP over SSH with Spaces in the Shared Folder Name

I couldn't find an exact example of my implementation to mount an AFP share over SSH on my Mac, especially when the share has spaces in the shared folder name. I had seen a couple posts on forums that mention url-encoding the spaces, but since I'm on the command line, I often think of escaping spaces with a backslash. Well it turns out that url-encoding a space with %20 makes it work and here's a little script I run to mount remote AFP shares:
umount "/Volumes/Share With Spaces In Folder Name" # unmount any stale shares
rmdir "/Volumes/Share With Spaces In Folder Name" # remove any stale sharepoints
pkill ssh -NfL 5548:127.0.0.1:548 username@domainname.tld # kill any ssh sessions with specific port redirections
ssh -NfL 5548:127.0.0.1:548 username@domainname.tld # ssh and port redirect into your remote system
mkdir "/Volumes/Share With Spaces In Folder Name" # create a new sharepoint
mount_afp afp://username:password@localhost:5548/Share%20With%20Spaces%20In%20Folder%20Name /Volumes/Share\ With\ Spaces\ In\ Folder\ Name
With this method I realize that my password is in the clear on the command, but since it's mounting on my system to a port that is tunneling ssh, the password is encrypted in the transmission request so therefor not technically transmitted in the clear across the internet.
Share Button

130724

Time Machine Auto-mount/unmount Drive OS X

I have a USB backup drive connected through my monitor to my Macbook Pro and I often find myself wanting to quickly unplug and go without the consequences of the drive not being ejected properly. As well, I need the drive to be mounted so that Time Machine can do its automatic backups.

Well I found a way to avoid having to manually mount and unmount (eject) my drive by using shell scripts and LaunchAgents to achieve the task. The added benefit is that I have control over the timing of the frequency of the Time Machine backups too!

Note: This works on OS X Lion or later. There is one caveat, in that when attempting to restore files from your Time Machine drive, you will need to disable the launch agents, as well you should re-activate Time Machine in the system preferences so that the system recognizes the drive for restore purposes.

Step 1

Create a plain text file named timemachine_mounter.sh with the following contents:

#!/bin/bash
# Set the drive name that we mount for our backups 
vol_mount="Time Machine"
# Conditional argument: if mounted entry has the volume name in the variable string
if ! mount | grep "$vol_mount" ; then
	# Drive isn't mounted, so: mount. A LaunchAgent will pick this OnMount action up and run the backup script
	diskutil mount "$vol_mount"
else
	# Drive is mounted, so: run the backup script
	timemachine_backup.sh
fi

Save the file in the /usr/local/bin/ directory at the base of your system drive. You may need to first save the file to your desktop then use finder to move it to that directory, it will ask to authenticate. Or use sudo in Terminal to move the file there instead, and make sure that ownership belongs to you (the user that logs in), in my case the assigned user:group was mike:staff.

Step 2

Create a plain text file named timemachine_backup.sh with the following contents:

#!/bin/bash
# Set the drive name that we mount for our backups 
vol_mount="Time Machine"
# Conditional argument: if mounted entry has the volume name in the variable string
if mount | grep "$vol_mount" ; then
	# Drive is mounted, so: backup and then eject after
	tmutil startbackup -b && 
	diskutil unmount "$vol_mount"
fi

Save the file in the /usr/local/bin/ directory again with the same ownership credentials as the previous script.

Step 3

Create a plain text file named com.apple.TimeMachine_OnLoadSchedule.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.apple.TimeMachine_OnLoadSchedule</string>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>7200</integer>
	<key>Program</key>
	<string>/usr/local/bin/timemachine_mounter.sh</string>
</dict>
</plist>

Save the file in the ~/Library/LaunchAgents/ directory inside your User folder/directory (~/).

What the above file does is register in the system to run the mounter script:

  • when I first log in
  • consecutively every 2 hours

Step 4

Create a plain text file named com.apple.TimeMachine_OnMount.plist with the following contents:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd>
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>com.apple.TimeMachine_OnMount</string>
	<key>StartOnMount</key>
	<true/>
	<key>Program</key>
	<string>/usr/local/bin/timemachine_backup.sh</string>
</dict>
</plist>

Save the file in the ~/Library/LaunchAgents/ directory as well.

What the above file does is register the system to run the Time Machine backup script whenever the drive gets mounted. This can happen when:

  • I physically connect the drive
  • the scheduler LaunchAgent above, runs the driver mounter script

In Terminal, make sure the shell scripts are executable, unload the default plist (if you didn't turn off your Time Machine automatic backups in the System Preferences) and finally load the new LaunchAgent in your local LaunchAgent startup folder:

chmod +x /usr/local/bin/timemachine_*.sh
sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.backupd-auto.plist
launchctl load ~/Library/LaunchAgents/com.apple.TimeMachine_OnMount.plist
launchctl load ~/Library/LaunchAgents/com.apple.TimeMachine_OnLoadSchedule.plist

Lastly...

You can change the com.apple.TimeMachine_OnLoadSchedule.plist's integer value for the starting interval 7200 integer to something more reasonable (e.g., 3600 seconds is one hour,... multiply at will.) I have my backups run every two hours.

The good thing about using a LaunchAgent is that:

  • if your computer goes to sleep or is shut off, the backup will begin at the next time you log in and reset the countdown from that point onward
  • if Time Machine is already running it won't try to run the process until the next projected sync time
  • if the drive is freshly connected or mounted already, Time Machine will begin backing up your changes and eject after its done
Share Button

120927

Font rendering issues on Google Chrome on OS X

There seems to be a small problem with many websites viewed in the latest version of Chrome on OS X as of recently (version 22.0.1229.79, updated on September 26, 2012).

The issue, documented here on the chromium issues tracker, talks about the fonts looking slightly more bold, or heavier, thicker and sometimes fuzzy due to a small repair job done on CSS -webkit-font-smoothing property that many web designers and developers were using to make their custom web-font typefaces render as intended by the glyph outlines in the fonts that they embedded on their websites.

bungeman@chromium.org reports that the bug where it also affected the weight of the text as a side effect has been fixed.

He also mentions that the additional weight of the typeface is rendered on purpose by the CoreGraphics API on OS X. There is a setting on the system that smooths text for LCD monitors, dialating the glyph outline by a factor of two, and that there was in fact a bug with the previous -webkit-font-smoothing: antialiased CSS property that ignored the CoreGraphics doubling of the dilation effect and rendered the font to its intended outlines without any smoothing.

Now that the bug has been fixed in Chrome's code, the antialiasing bug is no longer dismissing the CoreGraphics LCD smoothing and therefor the fonts look heavier.

There isn't a straightforward solution to fix the bolding of type on webkit browsers on OS X, however one might try addressing Apple OS X's CoreGraphics LCD font smoothing directly by turning off your system's LCD smoothing in System Preferences (under Appearance or General Settings), or with the following command in Terminal and restarting your browser.

defaults -currentHost write -globalDomain AppleFontSmoothing -int 0

The default when using lcd smoothed text is 2. To reset to the default value, use this command:

defaults -currentHost write -globalDomain AppleFontSmoothing -int 2

Note: This won't modify the way your website is viewed on other people's computers with OS X and webkit-based browsers. This only affects your ownlocal OS X system LCD font smoothing rendering.

Update: apparently the Chrome team is going to revert the fix to a planned bug so that they can buy themselves time to release a proper solution.

Share Button

120604

Proper MIME types for Embedded @font-face Fonts

Article Update: August 16, 2013 Article Update: October 1, 2012 After some exhaustive research, I managed to find the best server settings for serving web fonts. This article replicates my comment in reply to this question on the Stack Exchange forum. There are a number of font formats that one can set MIME types for, on both Apache and IIS servers. I've traditionally had luck with the following:
svg  as "image/svg+xml"
ttf  as "application/x-font-ttf" or "application/x-font-truetype"
otf  as "application/x-font-opentype"
woff as "application/font-woff" (per my August 16, 2013 update below)
eot  as "application/vnd.ms-fontobject"
According to the Internet Engineering Task Force who maintain the initial document regarding Multipurpose Internet Mail Extensions (MIME types) here: http://tools.ietf.org/html/rfc2045#section-5 ... it says in specifics:
"It is expected that additions to the larger set of supported types can generally be accomplished by the creation of new subtypes of these initial types. In the future, more top-level types may be defined only by a standards-track extension to this standard. If another top-level type is to be used for any reason, it must be given a name starting with "X-" to indicate its non-standard status and to avoid a potential conflict with a future official name."
As it were, and over time, additional MIME types get added as standards are created and accepted, therefor we see examples of vendor specific MIME types such as vnd.ms-fontobject and the like. Update October 1, 2012: I've been in touch with some of the people at Monotype and Extensis who watch the W3C www-font listserve. Vladimir Levantovsky from Monotype mentioned to me that the media type “application/font-woff” has been discussed and approved by the W3C WebFonts WG, and as such is now the part of the WOFF spec. However, to the best of his knowledge, it has not yet been registered with IANA. Thomas Phinney from Extensis mentioned as well that he was recently discussing this among the engineering staff at Extensis the other day, and the conclusion was that having a real, dedicated MIME type for WOFF and fonts in general would be a good thing, from their point of view. Update August 16, 2013: On January 3, 2013 the WOFF MIME Type was formally registered as application/font-woff with IANA. Consequently, Webkit has been updated and browsers that incorporate this Webkit update (e.g., Chrome and Safari) will likely be showing an error that displays something like: "Resource interpreted as Font but transferred with MIME type application/x-font-woff: /location/of/font.woff" in your Developer Tools Code Inspector. To fix this, you need to change the media type on your server to “application/font-woff”. Since the warnings are only annoying I would recommend switching to the approved MIME type right away. In an ideal world, the warnings will resolve themselves in time. With that said, we may see an entirely new set of protocols for servers serving web-fonts, which may include things like security, management and new architectures for font storage on the server side. Stay tuned!
Share Button

100218

Understanding Flash Banner Advertising on Google

I am creating a unique set of banner advertisements for a client of mine and after quite an exhaustive search, without having to actually force myself or anyone into creating an AdWords account to glean more information I managed to come up with a list of how I believe Google AdWords advertising works with flash banners: 1. in your AdWords account, you create a campaign 2. the campain has details for keywords and descriptions of the campaign for relevance 3. you then input the destination for the campaign banners (http://www.yourwebsite.com/destination/) 4. then you upload your set of banners to the campaign (swfs, gifs, jpgs, or pngs) 5. then you pay for an advertising exposure package (how much money determines the quality of your campaigns exposure on Google's advertising network) 6. the rest, is all done by Google's servers and their advertising network Google's advertising partners must all have a specific set of javascript codes on their website to handle the banners embedded on their website by Google. If your banner shows up on XYZ.com,.. then XYZ.com's website has this javascript code to handle the ClickTag embedded in that Flash banner. As well, XYZ.com's website already knows to go to the destination (http://www.yourwebsite.com/destination/) because it got it from Google (when you gave it to Google in your campaign in your AdWords account). Google dynamically provided your campaign destination to their advertising partners, only when the banner was displayed on their ad partners' websites. In the meantime, the ClickTag, also allows Google to record how many people have clicked on a specific banner - and this allows them to provide a whole set of statistics based around the campaign - whether more money needs to be invested in the advertising, or maybe the banner needs to be more eye-catching. I found a website that explains the latest Actionscript 3 code to put into Flash (for Adobe Flash CS3 or CS4) for banners to be effective on Google's advertising network of partners: http://www.genelu.com/content/view/98/1 I hope this explains things a bit better, and regardless the banner should end up working once it's uploaded to Google AdWords.
Share Button

090723

Get URLs, Captions & Titles for Images Attached to Posts in WordPress

I've been working on a new WordPress theme for my client that involves a billboard concept where certain posts are categorized as homepage billboard items, and those post items have images attached to them within the Media gallery of WordPress. I found out how to pull out the URI address of the images that are attached to the posts, but it took me some time to figure out how to get the Title, Caption and Description text associated directly with that image attachment. I borrowed most of my code from here, but I think my example illustrates the concept of retrieving the data needed much easier.

General Code Concept

$size = "thumbnail"; // options: thumbnail, medium, large, full
$args = array(
	'numberposts' => null, // change this to a specific number of images to grab
	'post_parent' => '25',
	'post_type' => 'attachment',
	'nopaging' => false,
	'post_mime_type' => 'image',
	'order' => 'ASC', // change this to reverse the order
	'orderby' => 'menu_order ID', // select which type of sorting
	'post_status' => 'any'
);
$attachments =& get_children($args);
if ($attachments) {
	foreach($attachments as $attachment) {
		foreach($attachment as $attachment_key => $attachment_value) {
			$imageID = $attachment->ID;
			$imageTitle = $attachment->post_title;
			$imageCaption = $attachment->post_excerpt;
			$imageDescription = $attachment->post_content;
			$imageAlt = get_post_meta($imageID, '_wp_attachment_image_alt', true);
			// $imageAlt = $attachment->image_alt; // not sure about this one
			$imageArray = wp_get_attachment_image_src($attachment_value, $size, false);
			$imageURI = $imageArray[0]; // 0 is the URI
			$imageWidth = $imageArray[1]; // 1 is the width
			$imageHeight = $imageArray[2]; // 2 is the height
			echo "$imageURI \n";
			echo "$imageWidth \n";
			echo "$imageHeight \n";
			echo "$imageID \n";
			echo "$imageTitle \n";
			echo "$imageCaption \n";
			echo "$imageDescription \n";
			if(count($imageAlt)) {
				echo $imageAlt;
			}// if '_wp_attachment_image_alt' is not set, echo $alt; shows text like 'Array()'
			break;
		}
	}
}
unset($args); // clear out arguments if using code multiple times in a theme

Practical Usage #1

Use the following to iterate all images from a post Hint: can use the above example's variables to pull additional info for each.
$size = "medium";
$args = array(
	'numberposts' => null,
	'post_parent' => $post->ID,
	'post_type' => 'attachment',
	'nopaging' => false,
	'post_mime_type' => 'image',
	'order' => 'ASC',
	'orderby' => 'menu_order ID',
	'post_status' => 'any'
);
$attachments =& get_children($args);
if ($attachments) {
	foreach($attachments as $attachment) {
		foreach($attachment as $attachment_key => $attachment_value) {
			$imageID = $attachment->ID;
			$imageTitle = $attachment->post_title;
			$imagearray = wp_get_attachment_image_src($attachment_value, $size, false);
			$imageURI = $imagearray[0]; // 0 is the URI
			$imageWidth = $imagearray[1]; // 1 is the width
			$imageHeight = $imagearray[2]; // 2 is the height
			echo "\t<img src="$imageURI" width="$imageWidth" height="$imageHeight" border="0">\n";
			break;
		}
	}
}
unset($args);

Practical Usage #2

If you want to get a specific image ..
$size = "medium";
$args = array(
	'numberposts' => 2, //change this to the image you want
	'post_parent' => $post->ID,
	'post_type' => 'attachment',
	'nopaging' => false,
	'post_mime_type' => 'image',
	'order' => 'ASC',
	'orderby' => 'menu_order ID',
	'post_status' => 'any'
);
$attachments =& get_children($args);
if ($attachments) {
	foreach($attachments as $attachment) {
		foreach($attachment as $attachment_key => $attachment_value) {
			$imageID = $attachment->ID;
			$imageTitle = $attachment->post_title;
			$imagearray = wp_get_attachment_image_src($attachment_value, $size, false);
			$imageURI = $imagearray[0]; // 0 is the URI
			$imageWidth = $imagearray[1]; // 1 is the width
			$imageHeight = $imagearray[2]; // 2 is the height
			// move this down below
			// echo "\t<img src="$imageURI" width="$imageWidth" height="$imageHeight" border="0">\n";
			break;
		}
	}
}
unset($args);
echo "\t<img src="$imageURI" width="$imageWidth" height="$imageHeight" border="0">\n";
The way the code above works is: the foreach loop, loops from the beginning and iterates through, but doesn't output .. until it's done the loop. It loops through 1, populating all of the variables, and then loops through 2, replacing all of the variables with 2's values. Because we changed the number of posts to retrieve, we only retrieve the last one we wanted, in this case the second image! This can also be changed to work backwards too (ie. we can get the "second last" image). This can be modified to work with any sort of suitable sorting option: alphanumerically, rating, by ID, etc. - all just by changing the orderby and order setting! Hope this solution works for your custom PHP queries and image retrieval via WordPress' Media gallery.
Share Button