Skip to content

Instantly share code, notes, and snippets.

View NeuralGlue's full-sized avatar

Charles Young NeuralGlue

View GitHub Profile
export interface IPageMetadata {
position: {
current: number,
max: number
},
data: {
per: number,
total: number
}
}
export class MyObjectDatasourceService implements DataSource<MyObject> {
private myObjectSubject = new BehaviorSubject<MyObject[]>([]);
constructor(private myObjectService: MyObjectService){}
connect(collectionViewer: CollectionViewer): Observable<MyObject[]> {
return this.myObjectSubject.asObservable();
}
//Assuming that you have a route such as: /things/Thing.parameter
// Alo that you have decorated the route to use authentication via the auth module
func patchThing (_ req: Request) throws -> Future<Thing> {
let user = try req.requireAuthenticated(User.self)
return try flatMap(
to: Thing.self,
req.parameters.next(Thing.self),
req.content.decode(Thing.self)) { thing, updatedThing in
// ensure the thing belongs to this user
// assuming a route such as /parents/Parent.parameter/children/
func addChildtoParent(_ req: Request) throws -> Future<Child> {
return try flatMap(
to: Child.self, // what we will get back
req.parameters.next(Parent.self), // an already existing Parameter conforming instance
req.content.decode(Child.self)) { // a Content conforming instance
parent, child in
child.parentId = try parent.requireId()
@NeuralGlue
NeuralGlue / nestedMap_antipattern.swift
Last active November 27, 2019 22:08
AntiPatterns in Vapor 3
// assuming a route such as /parents/Parent.parameter/children/
func addChildtoParent(_ req: Request) throws -> Future<Child> {
return try req.parameters.next(Parent.self).flatMap(to: Child.self) { parent in
return try req.content.decode(Child.self).flatMap{ child in
child.parentId = try parent.requireId()
return try child.save(on:req)
}
}
}
#!/bin/bash
#
# Check_mk
# plugin for freebsd based systems that have disks on /dev/ada?
#
# This plugin produces the correct output to be parsed by the smart.temperature and the smart.stats checks
echo '<<<smart>>>'
for disk in `ls /dev/ada?`;
@NeuralGlue
NeuralGlue / gist:6907596
Last active March 3, 2016 12:42
Category to hide the status bar for a UIImagePickerController in IOS 7+
//
// UIImagePickerController+RemoveStatusBar.m
// CarpeWorkshop
// With thanks to:http://stackoverflow.com/users/2797041/user2797041
// Created by Charles Young on 10/9/13.
// Copyright (c) 2013 Charles Young. All rights reserved.
//
#import "UIImagePickerController+RemoveStatusBar.h"