Skip to content

Instantly share code, notes, and snippets.

View levi's full-sized avatar

Levi McCallum levi

View GitHub Profile
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
[layout prepareLayout];
CGSize size = [layout collectionViewContentSize];
CGRect rect = CGRectMake(0, 0, size.width, size.height);
NSArray *layoutAttributes = [layout layoutAttributesForElementsInRect:rect];
for (UICollectionViewLayoutAttributes *attributes in layoutAttributes) {
switch (attributes.representedElementCategory) {
case UICollectionElementCategoryCell:
NSLog(@"Cell");
break;
Set Plain Sprited
==============================================
About to open file
About to read file
File content:
{
"max-size": 1024
}
Could not load config file. Proceeding anyway. What's the worst tha
global 0 6
// VIEW
contentView: SC.CollectionView.design({
layout: { top: 0, right: 0, bottom: 0, left: 0 },
contentBinding: 'Ljm.entriesController.arrangedObjects',
selectionBinding: 'Ljm.entriesController.selection'
})
// CONTROLLER
(function($) {
$.fn.fakeSelect = function() {
$(this).each(function(idx, element) {
var container = $(element),
heading = $('h3', element),
menu = $('.dropdown', element);
container.addClass('fakeselect-js');
heading.click(function() {
container.addClass('fakeselect-js-active');
$(document.body).bind('click', function() {
@levi
levi / gist:315648
Created February 26, 2010 11:25
Name sc-build number with git's HEAD
module CT
module Git
def self.sha(repo)
result = `cd "#{repo}" && git log -1 --format=%H`.strip
return result =~ /^[0-9a-f]{40}$/ ? result : nil
end
end
end
config :sproutcore, :build_number => CT::Git::sha('frameworks/sproutcore')
rootNavigation: SC.Object.create({
treeItemIsExpanded: YES,
treeItemChildren: [
SC.Object.create({
name: "Home",
icon: 'home-16',
show: 'Ljm.HOME'
}),
SC.Object.create({
name: "Journal",
// View
calendar: Ljm.CalendarView.design({
...
selectionBinding: 'Ljm.calendarController.selectedDate'
...
})
// calendarController
MyApp.createController = SC.ObjectController.create({
_store: null,
content: null,
userBinding: SC.Binding.from('MyApp.currentController.content').oneWay(),
create: function() {
this._store = MyApp.store.chain();
/**
Takes the created date and returns a fuzzy time string.
ie. 2 hours ago, 3 weeks ago.
@property
*/
prettyDate: function() {
var created = this.get('created'),
createdMS = created.get('milliseconds'),
@levi
levi / rspec_mock_rails3_chained_queries.rb
Created October 30, 2010 01:32
A really smelly, but working way to mock test Active Record chained queries in Rails 3.
# @session and @mock_project instance variables are defined elsewhere.
before(:each) do
joins = mock(ActiveRecord::Relation)
ProjectUser.should_receive(:joins).with(:project_user_datum).and_return(joins)
joins.should_receive(:where).
with('project_user_data.project_id = :project_id', { :project_id => @mock_project }).
and_return(@mock_project)
get :index, {}, @session
end