Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View craigmarvelley's full-sized avatar

Craig Marvelley craigmarvelley

View GitHub Profile
@craigmarvelley
craigmarvelley / commands.txt
Created May 11, 2011 16:33
Setting up a Symfony 2 project with bleeding edge vendors on Windows
git init
mkdir vendor
git submodule add git://github.com/kriswallsmith/assetic.git vendor/assetic
mkdir vendor\bundles\JMS
git submodule add https://github.com/schmittjoh/SecurityExtraBundle.git vendor/bundles/JMS/SecurityExtraBundle
mkdir vendor\bundles\Sensio\Bundle
- (NSMutableDictionary *)throttleActionHash
{
NSMutableDictionary *throttleData = objc_getAssociatedObject(self, THROTTLE_ACTION_HASH_PROPERTY_KEY);
if (!throttleData) {
throttleData = [[NSMutableDictionary alloc] init];
objc_setAssociatedObject(self, THROTTLE_ACTION_HASH_PROPERTY_KEY, throttleData, OBJC_ASSOCIATION_RETAIN);
}
return throttleData;
// Assume we have an NSPersistentStoreCoordinator which has been initialised with our entity model, and
// an NSURL which points to our store's location on disk
NSDictionary *sourceMetadata = [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:NSSQLiteStoreType URL:storeUrl options:options error:&error];
NSManagedObjectModel *destinationModel = coordinator.managedObjectModel;
BOOL storeIsCompatible = [destinationModel isConfiguration:nil compatibleWithStoreMetadata:sourceMetadata];
@craigmarvelley
craigmarvelley / progress.m
Last active April 26, 2017 08:33
NSProgress/UIProgressView example
// Create a progress bar view
UIProgressView *progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
progressView.progress = 0;
// Assume we have a progress object
NSProgress *progress = [self progressForOngoingTask];
// Observe the 'fractionCompleted' property and update the progress view as it changes
[self.KVOController observe:progress keyPath:@"fractionCompleted" options:NSKeyValueObservingOptionNew block:^(id _Nullable observer, id _Nonnull object, NSDictionary<NSString *, id> *_Nonnull change) {
dispatch_async(dispatch_get_main_queue(), ^{
NSURL *pathToPdfFile;
UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:@[ result ] applicationActivities:nil];
NSMutableArray *excludedActivities = [NSMutableArray array];
NSNumber *emailOutEnabled = [self.userPreferences.featureFlags valueForKeyPath:@"research.share.email"];
if (!emailOutEnabled.boolValue) {
[excludedActivities addObject:UIActivityTypeMail];
}
<?php
namespace Acme\DemoBundle\Handler;
use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationFailureHandler;
use Symfony\Component\Security\Core\Exception\AuthenticationException;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\JsonResponse;
class XHRAuthenticationFailureHandler extends DefaultAuthenticationFailureHandler
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.net.*;
import javax.swing.event.*;
public class Internet extends JFrame
{
final JDesktopPane theDesktop;
@implementation ExampleAssembly
- (MyModel *)model {
return [TyphoonDefinition withClass:[MyModel class]
configuration:^(TyphoonDefinition* definition) {
[definition useInitializer:@selector(initWithDependency:)
parameters:^(TyphoonMethod *initializer) {
[initializer injectParameterWith:[self exampleDependency]];
- (void)interceptSeguesToPerformDependencyInjection {
NSError *error;
id<AspectToken> DIAspectToken = [UIViewController aspect_hookSelector:@selector(prepareForSegue:sender:) withOptions:AspectPositionBefore usingBlock:^(id<AspectInfo> aspectInfo, UIStoryboardSegue *segue, id sender) {
UIViewController *destinationController = segue.destinationViewController;
[self.UIAssembly inject:destinationController];
- (void)showNoteSplitViewWithDataController:(DataController *)dataController searchController:(SearchController *)searchController {
NSParameterAssert(dataController);
NSParameterAssert(searchController);
NSString *authenticatedUserId = self.applicationSessionCredentialStore.userId;
NoteSplitViewAssembly *assembly = [self.assembly noteSplitViewAssemblyWithApplicationSession:self.applicationSession dataController:dataController searchController:searchController authenticatedUserId:authenticatedUserId];
[assembly activate];