Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Alex Burghardt aal89

🎯
Focusing
View GitHub Profile
@aal89
aal89 / ObjectMapperMoyaExt.swift
Created Sep 12, 2017
Easy and small extension to increase usability of Moya & ObjectMapper for backend abstraction layers. Easily turn a http response into an new-ed, mapped <T: Mappable>
View ObjectMapperMoyaExt.swift
// 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 {
@aal89
aal89 / fizzbuzz.swift
Last active Feb 14, 2018
FizzBuzz Swift 4 + functional solution
View fizzbuzz.swift
// 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)}
@aal89
aal89 / 420.swift
Last active Jul 23, 2019
A pure functional way to blaze some sick clouds in Swift.
View 420.swift
// 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))
@aal89
aal89 / 1000documents_couchdb.js
Created Sep 17, 2018
TamperMonkey script to add a 1000 documents per page option for CouchDB.
View 1000documents_couchdb.js
// ==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==
@aal89
aal89 / keyexists.js
Last active Oct 17, 2018
One line utility function to determine if a certain key or a point separated key list exists on any given object for Javascript. Also accounts for empty strings and all other falsey values.
View keyexists.js
// 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
@aal89
aal89 / prblock.js
Last active Oct 18, 2018
Tampermonkey script to clearly notify users of PR's that should not get approved/merged yet.
View prblock.js
// ==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==
@aal89
aal89 / stretchy_header.swift
Created Oct 22, 2018
Simple stretchy header example for Swift.
View stretchy_header.swift
//
// ViewController.swift
// stretchy header example
//
// Created by Alex on 07/03/2018.
// Copyright © 2018. All rights reserved.
//
import UIKit
@aal89
aal89 / shell.sh
Created Oct 22, 2018
Generate rsa public/private key pair using openssl
View shell.sh
openssl genrsa -out key.pem 512
openssl rsa -in key.pem -outform PEM -pubout -out public.pem
@aal89
aal89 / filter06.js
Last active Nov 2, 2018
A Javascript regex to filter all dutch cellphone numbers from a particular text and filter for uniqueness. Works for no mathces, one match and multiple matches.
View filter06.js
var text = `
the text containing a couple of 0612345678 numbers. like so: 0612345678 and so:
0687654321
and
another
example
0674839201
`;
// Approach one: returns an ES6 Set.
@aal89
aal89 / DataRequest.d.ts
Created Apr 29, 2019
Declaration merging. Swift like extensions for TypeScript. Extending an Express Request object per example.
View DataRequest.d.ts
// tslint:disable
declare namespace Express {
export interface Request {
locals: {
data: unknown;
}
}
}
You can’t perform that action at this time.