Skip to content

Instantly share code, notes, and snippets.

@stanislaw
stanislaw / gist:a82b3573704f2336fb41
Created August 31, 2014 15:16
RestKit Core Data concurrency problems (fix applied)
2014-08-31 19:13:18.928 SportUp[1006:410f] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 SportUp 0x002a320b ValidateConcurrency + 267
1 SportUp 0x002a2e04 CustomSubclassRelease + 36
2 libobjc.A.dylib 0x02ce5e97 objc_release + 71
3 SportUp 0x0032cdeb RKManagedObjectsFromMappingResultWithMappingInfo + 1147
4 SportUp 0x0032c344 -[RKManagedObjectRequestOperation deleteLocalObjectsMissingFromMappingResult:error:] + 1188
5 SportUp 0x00329ba5 __79-[RKManagedObjectRequestOperation performMappingOnResponseWithCompletionBlock:]_block_invoke356 + 1589
6 SportUp 0x0038d634 -[RKResponseMapperOperation willFinish] + 788
7 SportUp 0x0038e6c1 -[RKResponseMapperOperation main] + 4161
8 Foundation 0x01095c79 -[__NSOperationInternal
@stanislaw
stanislaw / gist:d12c750b7cfc20dc399e
Created August 31, 2014 15:21
RestKit Core Data concurrency problems (fix NOT applied)
2014-08-31 19:19:34.170 SportUp[1152:607] I restkit.network:RKObjectRequestOperation.m:150 GET 'https://d3scr0eofaakvi.cloudfront.net/uploads/teams/194/original/public.png?1405607852'
2014-08-31 19:19:34.172 SportUp[1152:607] I restkit.network:RKObjectRequestOperation.m:186 GET 'https://d3scr0eofaakvi.cloudfront.net/uploads/teams/194/original/public.png?1405607852' (200 OK) [0.0013 s]
2014-08-31 19:19:42.677 SportUp[1152:5003] Invalid concurrent access to managed object calling 'release'; Stacktrace: (
0 SportUp 0x002a300b ValidateConcurrency + 267
1 SportUp 0x002a2c04 CustomSubclassRelease + 36
2 CoreFoundation 0x033ffbf0 CFRelease + 272
3 CoreFoundation 0x03432b82 -[__NSArrayI dealloc] + 82
4 libobjc.A.dylib 0x02ce6692 _ZN11objc_object17sidetable_releaseEb + 268
5 libobjc.A.dylib 0x02ce7aeb -[NSObject release] + 25
6 libobjc.A.dylib
#!/usr/bin/env bash
declare -i ERRORS=0
if git rev-parse --verify HEAD > /dev/null 2>&1
then
AGAINST=HEAD
else
AGAINST=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi
Ну условно говоря:
Модеь: АААА! Давление 1960 на 1230!!!
Viewmodel : состояние лампочки: красное
View; Окей, отобразим ! красным
# и в обратную сторону
(Пользователь жмет педальку)
View : -> ViewModel
Слушай, тут пользователь жмякнул педальку.
@stanislaw
stanislaw / warden.rb
Created May 16, 2011 05:45 — forked from cavalle/warden.rb
Testing Warden/Devise with Steak
# Create a file `spec/acceptance/support/warden.rb' with the following
# contents:
Spec::Runner.configure do |config|
config.include Warden::Test::Helpers, :type => :acceptance
config.after(:each, :type => :acceptance) { Warden.test_reset! }
end
# Or, if you're using RSpec 2 / Rails 3, the contents should be the following
# instead:
@stanislaw
stanislaw / handystuff.md
Created September 19, 2011 21:19 — forked from gilgen/handystuff.md
Handy stuff
@stanislaw
stanislaw / ruby-1.9-tips.rb
Created November 25, 2011 19:13 — forked from igrigorik/ruby-1.9-tips.rb
Ruby 1.9 features, tips & tricks you may not know about...
def tip(msg); puts; puts msg; puts "-"*100; end
#
# 30 Ruby 1.9 Tips, Tricks & Features:
# http://www.igvita.com/2011/02/03/new-ruby-19-features-tips-tricks/
#
tip "Upgrading to Ruby 1.9 is simple: rvm install 1.9.2 && rvm --default 1.9.2"
tip "Ruby 1.9 supports named captures in regular expressions!"
@stanislaw
stanislaw / README.md
Created December 27, 2011 19:15 — forked from jlecour/README.md
Identify paperclip attachment files that are not attached to any record

Let's say you have a model, with an files attached, using Paperclip. You have a couple millions of those files and you're not sure that every one of them (and all its thumbnails) are still used by a database record.

You could use this rake task to recursively scan all the directories and check if the files need to be kept or destroyed.

In this example, the model is called Picture, the attachment is image and the path is partitioned like images/001/412/497/actual_file.jpg

The task is going down the path. Each time the path ends with 3 triplets of digits ("001/412/497" for example) it looks for a record with the ID 1412497. If such a record doesn't exist, the whole directory is moved to a parallel images_deleted directory. At the end you can delete the files if you like, or move them to an archive location.

You can use the "dry run" mode : to print which files would be removed

@stanislaw
stanislaw / gist:2049280
Created March 16, 2012 09:32
Cucumber & Capybara against Spork - Always run tests in the same browser.
require 'rubygems'
require 'spork'
ENV["RAILS_ENV"] = 'test'
Spork.prefork do
require 'cucumber/rails'
require 'capybara/rails'
@stanislaw
stanislaw / sunrise.rb
Created March 25, 2012 21:23 — forked from njh/sunrise.rb
Ruby Code to calculate sunrise and sunset times where I live
#!/usr/bin/env ruby
require 'rubygems'
require 'solareventcalculator'
solar = SolarEventCalculator.new(Date.today, BigDecimal.new('51.563'), BigDecimal.new('-0.499'))
puts "Sunrise: #{solar.compute_utc_civil_sunrise.getlocal}"
puts "Sunset: #{solar.compute_utc_civil_sunset.getlocal}"