Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| Inspired from https://drboolean.gitbooks.io/mostly-adequate-guide/content/ch5.html | |
| // Curries by partially applying 1 out of 2 arguments | |
| func curry<A, B, C>(fn: (A, B) -> C, _ val: A) -> (B -> C) { | |
| return { b in | |
| fn(val, b) | |
| } | |
| } | |
| // "compose" operator |
| //: Playground - noun: a place where people can play | |
| struct Room: IntegerLiteralConvertible { | |
| let number: Int | |
| init(integerLiteral value: Int) { | |
| number = value | |
| } | |
| } |
| // | |
| // PersistenceStack.swift | |
| import CoreData | |
| public class PersistenceStack: NSObject { | |
| let mainContext: NSManagedObjectContext = { | |
| let context = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType) | |
| context.undoManager = nil | |
| context.mergePolicy = NSMergeByPropertyObjectTrumpMergePolicy |
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)That's it!
| import java.util.Random; | |
| class Counter { | |
| private int c=0; | |
| public synchronized void increment() { | |
| c++; | |
| } | |
| public synchronized void decrement() { | |
| c--; |
| import java.util.Random; | |
| class Runner implements Runnable { | |
| public void run() { | |
| int c = 0; | |
| while (c++ < 10000) | |
| if (c % 100 == 0) | |
| System.out.println("still at " + c); | |
| } | |
| } |
| import java.util.Random; | |
| public class ThreadingThings implements Runnable{ | |
| int myID; | |
| Random gen; | |
| public ThreadingThings(int anID) { | |
| myID = anID; | |
| gen = new Random(); |
| #import <Foundation/Foundation.h> | |
| @interface MyClass : NSObject | |
| @end | |
| @implementation MyClass | |
| static NSMutableArray *instances; |
| totalInversions = 0 | |
| countInversions (array, start, end) | |
| if (start < end) | |
| int mid = (start + end)/2 | |
| countInversions(array, start, mid) | |
| countInversion(array, mid+1, end) | |
| merge(array, start, mid, end) | |
| // else do nothing | |
| - (BOOL) createRelationshipsForDestinationInstance:(NSManagedObject *) destinationAttendance entityMapping:(NSEntityMapping *)mapping manager:(NSMigrationManager *)manager error:(NSError **)error { | |
| NSArray *sourceAttendances = [manager sourceInstancesForEntityMappingNamed:[mapping name] | |
| destinationInstances:[NSArray arrayWithObject:destinationAttendance]]; | |
| NSManagedObject *sourceAttendance = [sourceAttendances objectAtIndex:0]; | |
| NSArray *allStudents = [[[sourceAttendance valueForKey:@"theSchedule"] valueForKey:@"theCourse"] valueForKey:@"students"]; | |
| NSArray *presentStudents = [sourceAttendance valueForKey:@"students"]; | |
| NSLog(@"For attendance on %@", [sourceAttendance valueForKey:@"date"]); | |