Skip to content

Instantly share code, notes, and snippets.

View aal89's full-sized avatar
🎯
Focusing

Alex Burghardt aal89

🎯
Focusing
View GitHub Profile
@aal89
aal89 / filter06.js
Last active November 2, 2018 09:57
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.
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 / shell.sh
Created October 22, 2018 15:28
Generate rsa public/private key pair using openssl
openssl genrsa -out key.pem 512
openssl rsa -in key.pem -outform PEM -pubout -out public.pem
@aal89
aal89 / prblock.js
Last active October 18, 2018 14:30
Tampermonkey script to clearly notify users of PR's that should not get approved/merged yet.
// ==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 / keyexists.js
Last active October 17, 2018 12:53
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.
// 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 / 1000documents_couchdb.js
Created September 17, 2018 11:58
TamperMonkey script to add a 1000 documents per page option for CouchDB.
// ==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 / ObjectMapperMoyaExt.swift
Created September 12, 2017 10:28
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>
// 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 February 14, 2018 12:01
FizzBuzz Swift 4 + functional solution
// 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)}