This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// stretchy header example | |
// | |
// Created by Alex on 07/03/2018. | |
// Copyright © 2018. All rights reserved. | |
// | |
import UIKit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Clearly notify for unstable builds in Bitbucket | |
// @namespace http://tampermonkey.net/ | |
// @version 0.1 | |
// @description Clearly notifies the user if the PR should not be merged and/or approved. | |
// @author Alex | |
// @match https://bitbucket.org/vdgsecurity/vdg-vms/pull-requests/* | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Regular Javascript version (in the end we have to evaluate the return into the proper boolean, an empty string is | |
// falsey in Javascript, but in this case we want it to behave as truthy. The OR operator with: '|| 1' is there to 'cast' | |
// false property values into a truthy value. | |
var keyExistsOn = (o, k) => k.split(".").reduce((a, c) => a.hasOwnProperty(c) ? a[c] || 1 : false, Object.assign({}, o)) === false ? false : true; | |
// Curried Javascript version, with the same boolean evaluation at the end. | |
var keyExistsOn = (k) => (o) => k.split(".").reduce((a, c) => a.hasOwnProperty(c) ? a[c] || 1 : false, Object.assign({}, o)) === false ? false : true; | |
// OUTPUT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Documents per page (1000 option) | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Adds a '1000' option for 'Documents per page' in CouchDB portal overview (localhost). | |
// @author Alex (https://github.com/aal89) | |
// @match http://127.0.0.1:5984/_utils/ | |
// @grant none | |
// ==/UserScript== |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Higher order functions, being curried. Considered pure functional, because they don't have any side effects | |
// (mutate any given data). They just derive data from data. | |
let plus = { (first: Int) in { (second: Int) in first + second } } | |
let multiplesOf = { (first: Int) in { (second: Int) in second % first != 0 } } | |
// Just a simple first class function, not per se functional. Usable to reduce a collection of integers into the total. | |
let total: (Int, Int) -> Int = { $0 + $1 } | |
let calculation = (1...30) | |
.map(plus(2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Single line 84 chars, not really an accepted answer (???). | |
// It prints an array containing the right answers in the right order, but not each individual number, just this array. | |
print((1...100).map{$0%3==0 ? $0%5==0 ? "FizzBuzz":"Fizz":$0%5==0 ? "Buzz":"\($0)"}) | |
// Slightly adjusted version to make it an accepted answer, increasing byte count to 92 | |
(1...100).map{$0%3==0 ? $0%5==0 ? "FizzBuzz":"Fizz":$0%5==0 ? "Buzz":"\($0)"}.map{print($0)} | |
// Single line 100 chars, not really a readable solution, but it also prints each individual number. | |
// One extra map call dissolved into individual print calls. | |
(1...100).map{$0%3==0 ? $0%5==0 ? print("FizzBuzz"):print("Fizz"):$0%5==0 ? print("Buzz"):print($0)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// MARK: | |
// usage example: | |
// let test: Hello = "{\"hello\": \"world\"}".conform(Hello()) | |
// The class Hello() should extend Mappable, also see ObjectMapper docs. | |
import ObjectMapper | |
extension String { | |
func conform<T: Mappable>(_ model: T) -> T { |
NewerOlder