Skip to content

Instantly share code, notes, and snippets.

View maltebucksch's full-sized avatar

Malte Bucksch maltebucksch

View GitHub Profile
describe(`Quickbird Studios Team`, function() {
it(`should be an awesome team`, function() {
const quickBirdTeamMembers = fetchTeamMembers();
const awesomeTeamMembers = quickBirdTeamMembers.filter(teamMember =>
teamMember.isPassionate &&
teamMember.isFriendly &&
teamMember.isConstantlyImproving
);
// let’s say we have 2 variables
b = 1, c = 1
// and a third which is the sum of both
a := b + c
print(a)  // output wil be “2” (so far, so good)
// now let’s change the value of “c”
c = 2
print(a)
@maltebucksch
maltebucksch / Count.java
Created August 20, 2018 09:44
Counting Non-Functional
private int count = 0;
// returns something different every time you call the function (not functional!)
private int getCount(){
count++;
return count;
}
@maltebucksch
maltebucksch / EmailInput.java
Last active August 20, 2018 09:27
EmailInput
keyboardInput.filter(input -> isEmailValid(input))
.map(email -> getEmailPrefix(email))
.subscribe(emailPrefix ->
System.out.println("New User: " + emailPrefix)
);
interface PatternDetector {
fun findPatterns(data: List<Weight>): List<Pattern>
}
@maltebucksch
maltebucksch / PerformRequest.swift
Created June 26, 2018 08:10
Realm Sync Service: Perform-Request
private static func performRequest(method: String, url: URL, data: Data? = nil) {
if let data = data {
let json = String(decoding: data, as: UTF8.self)
print("\(method): \(url.path)\n\(json)")
} else {
print("\(method): \(url.path)")
}
}
@maltebucksch
maltebucksch / UploadDelete.swift
Created June 26, 2018 08:07
Realm Sync Service: Upload + Delete
private static func upload(_ object: Syncable, isUpdated: Bool) {
let url: URL
let httpMethod: String
if isUpdated {
url = object.resourceURL.appendingPathComponent("/\(object.getId())")
httpMethod = "PUT"
} else {
url = object.resourceURL
httpMethod = "POST"
@maltebucksch
maltebucksch / HandleUpdate.swift
Created June 26, 2018 08:06
Realm Sync Service: handleUpdate
private static func handleUpdate(_ update: Update) {
update.insertions.forEach { upload($0, isUpdated: false) }
update.modifications.forEach { upload($0, isUpdated: true) }
update.deletions.forEach { deleteObject(withId: $0, ofType: update.type) }
}
@maltebucksch
maltebucksch / SyncService.swift
Created June 26, 2018 08:05
Realm Sync Service: Sync-Service
class SyncService {
private let realm: Realm
private let tokens: [NotificationToken]
init(modelTypes: [Syncable.Type], realm: Realm = try! Realm()) {
self.realm = realm
tokens = modelTypes.map { modelType in
modelType.registerNotificationObserver(for: realm, callback: SyncService.handleUpdate)
@maltebucksch
maltebucksch / AppDelegate-whole.swift
Created June 26, 2018 08:04
Realm Sync Service: AppDelegate Whole
var syncService: SyncService!
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
syncService = SyncService(modelTypes: [User.self])
return true
}