Nathan Colgate RSS

This is the personal blog of Nathan Colgate Clark. I work at Brand New Box. I developed a content management system for churches.

Archive

Mar
19th
Tue
permalink
Feb
20th
Wed
permalink

mustache.js in_groups_of

I needed mustache.js to iterate over a list in groups of 2 to take advantage of Twitter Bootstraps “row” and “span” classes.  Here is how I got it done (using jQuery).

$.fn.inGroupsOf = function( countPerGroup, groupName ) {
  var groups = [], offset = 0, $group, jsonOptions;
  while ( ($group = this.slice( offset, (countPerGroup + offset) )).length ) {
      jsonOptions = {};
      jsonOptions[groupName] = $group.toArray();
      groups.push( jsonOptions );
      offset += countPerGroup;
  }
  return groups;
};

      
var renderEmailImageCategories = function(email_image_categories){
  $.each(email_image_categories, function(index, email_image_category) {
    email_image_category.image_groups = function() {
      return $(this.images).inGroupsOf(2,'images');
    };
  });
  template = $.mustache('{{#email_image_categories}}<h4>{{name}}{{^name}}My Images{{/name}}</h4>{{#image_groups}}<div class="row">{{#images}}{{#.}}<a href="#" class="email_image_link" data-id="{{id}}" data-url="{{file.span3.url}}"><img src="{{file.span3.url}}" class="span3" style="margin-bottom:1em;" /></a>{{/.}}{{/images}}</div>{{/image_groups}}{{/email_image_categories}}',{"email_image_categories": email_image_categories});
  $('#custom_email_image_body').html(template);
};
Jan
2nd
Wed
permalink

How to set your rackspace_temp_url_key (CarrierWave)

$ curl -v -H "X-Auth-User: <your_rackspace_username>" -H "X-Auth-Key: <your_rackspace_api_key>" https://auth.api.rackspacecloud.com/v1.0
* About to connect() to auth.api.rackspacecloud.com port 443 (#0)
*   Trying 67.192.1.11... connected
* Connected to auth.api.rackspacecloud.com (67.192.1.11) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
* 	 subject: C=US; O=auth.api.rackspacecloud.com; OU=GT47404894; OU=See www.geotrust.com/resources/cps (c)09; OU=Domain Control Validated - QuickSSL(R); CN=auth.api.rackspacecloud.com
* 	 start date: 2009-07-10 11:34:54 GMT
* 	 expire date: 2014-07-11 02:57:59 GMT
* 	 common name: auth.api.rackspacecloud.com (matched)
* 	 issuer: C=US; O=Equifax; OU=Equifax Secure Certificate Authority
* 	 SSL certificate verify ok.
> GET /v1.0 HTTP/1.1
> User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4 OpenSSL/0.9.8r zlib/1.2.5
> Host: auth.api.rackspacecloud.com
> Accept: */*
> X-Auth-User: <your_rackspace_username>
> X-Auth-Key: <your_rackspace_api_key>
> 
< HTTP/1.1 204 No Content
< Server: Apache/2.2.3 (Red Hat)
< vary: X-Auth-User,X-Auth-Key,X-Storage-User,X-Storage-Pass
< X-Storage-Url: <your_x_storage_url>
< Cache-Control: s-maxage=84787
< Content-Type: text/xml
< Date: Wed, 02 Jan 2013 19:05:23 GMT
< X-Auth-Token: <your_x_auth_token>
< X-Server-Management-Url: <your_x_server_management_url>
< X-Storage-Token: <your_x_storage_token>
< Connection: Keep-Alive
< X-CDN-Management-Url: <your_x_cdn_management_url>
< Content-Length: 0
< 
* Connection #0 to host auth.api.rackspacecloud.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):
$ curl -X POST -H "X-Auth-Token: <your_x_auth_token>" -H "X-Account-Meta-Temp-Url-Key: <your_rackspace_temp_url_key>" <your_x_storage_url>

Aug
7th
Tue
permalink
Aug
6th
Mon
permalink
Jul
12th
Thu
permalink
Regex find and replace in textmate: You can use part of the matched search in the replacement. You do this by placing () around each part of the search you want to use, and referring to them in the replacement with $1, $2 etc.

Regex find and replace in textmate: You can use part of the matched search in the replacement. You do this by placing () around each part of the search you want to use, and referring to them in the replacement with $1, $2 etc.

Jun
14th
Thu
permalink

Check Your IP Address from the Command Line

wget -q -O - checkip.dyndns.org

Feb
13th
Mon
permalink
It wouldn&#8217;t take much to make this into clark

It wouldn’t take much to make this into clark

Feb
6th
Mon
permalink

Switch heroku accounts in the console

1. Delete the SSH keys from your current account:

$ heroku keys:clear

You have to clear these first because Heroku won’t allow two accounts to have the same SSH key.

2. Delete your locally stored credentials:

$ rm ~/.heroku/credentials

3. Re-enter your (new) credentials by entering any command that requires access to an account, e.g.:

$ heroku create

Enter your Heroku credentials.

Email: my@email.com

Pass: mypass

The command line utility will record your new credentials in your ~/.heroku/credentials file and automatically add your machine’s SSH key. If you hadn’t deleted the key from your other account, it would complain about multiple accounts using the same key.

Feb
2nd
Thu
permalink