Skip to content

Instantly share code, notes, and snippets.

@gardym
gardym / gist:82ad6f8591b4a9c76ef4
Created June 13, 2015 15:35
Xcode's Core Data generated checkbox magic (replace YOUR_PROJECT)
lazy var applicationDocumentsDirectory: NSURL = {
let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)
return urls[urls.count-1] as! NSURL
}()
lazy var managedObjectModel: NSManagedObjectModel = {
// The managed object model for the application. This property is not optional. It is a fatal error for the application not to be able to find and load its model.
let modelURL = NSBundle.mainBundle().URLForResource("YOUR_PROJECT", withExtension: "momd")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()

In improve this we take a look at a reader submitted test, user interface, story or block of code and we try and improve it, without context, explaining what we did as we went.

In this issue, Mike sent a link to an [event source to a realtime social media visualization][source].

Before we ever apply brainpower, let's apply computer power. [JSLint][] and [JSHint][] are both tools to find mistakes and oversights.

@gardym
gardym / baz.js
Created July 14, 2012 05:46
Foo, bar, baz, qux - RequireJS/Jasmine-node
define(function() {
return {
qux: function() {
return "qux";
}
};
});
@gardym
gardym / foo.js
Created July 14, 2012 05:40
RequireJS/Jasmine-node
define(function() {
return {
bar: function() {
return "bar";
}
};
});
@gardym
gardym / heroku
Created April 26, 2012 04:18
logrotate.d/heroku - Rotate heroku log files. Execute this hourly via cron (cron.hourly)
create
compress
/var/log/heroku/*.log
{
# Keep logs for ten days
rotate 240
# Always rotate
size 1
missingok
@gardym
gardym / 90-heroku.conf
Created April 26, 2012 02:40
rsyslog.d/90-heroku.conf for capturing Heroku drains
:syslogtag, contains, "app[web.1]" /var/log/heroku/web.1.log
:syslogtag, contains, "app[web.2]" /var/log/heroku/web.2.log
:syslogtag, contains, "app[web.3]" /var/log/heroku/web.3.log
:syslogtag, contains, "app[web.4]" /var/log/heroku/web.4.log
:syslogtag, contains, "heroku[router]" /var/log/heroku/router.log
:syslogtag, contains, "run" /var/log/heroku/run.log
:inputname, isequal, "imtcp" /var/log/heroku/all.log
@gardym
gardym / jQuery.times.js
Created March 14, 2012 00:30
jQuery: $.times
(function($) {
$.times = function(x, f) {
for(var i = 0; i < x; i ++) {
f(i);
}
};
})($);
@gardym
gardym / IEnumerableLambdaDistinct
Created October 18, 2011 05:32
.NET Linq Extension: Use a lambda for Distinct() quality comparison
public static class IEnumerableExtensions
{
public static IEnumerable<T> Distinct<T>(this IEnumerable<T> enumerable, Func<T, T, bool> comparison)
{
return enumerable.Distinct(new LambdaEqualityComparison<T>(comparison));
}
internal class LambdaEqualityComparison<T> : IEqualityComparer<T>
{
private readonly Func<T, T, bool> comparison;
@gardym
gardym / gist:1183575
Created August 31, 2011 13:49
Gherkin with for
Given I have a new application form
When I enter "Shnoops" into the input named "textbox_surname"
And I click "Save"
...
Given I have a new application form
When I enter "Shnoops" into the box for "Surname"
And I click "Save"
....
IWebDriver driver = new FirefoxDriver();
label = driver.FindElement(By.Css(@"label:contains(\"Surname\")");
input = driver.FindElement(By.Name(label.GetAttribute("for"));
input.SendKeys("Shnoop");