Skip to content

Instantly share code, notes, and snippets.

View werner-freytag's full-sized avatar

Werner Freytag werner-freytag

View GitHub Profile
@werner-freytag
werner-freytag / AnyEquatable.swift
Created March 1, 2018 11:17
Allow any protocol to conform to Equatable using a wrapper
import Foundation
protocol AnyEquatableWrappable {
func isEqualTo(_ other: AnyEquatableWrappable) -> Bool
var asEquatable: AnyEquatable { get }
}
extension AnyEquatableWrappable where Self: Equatable {
func isEqualTo(_ other: AnyEquatableWrappable) -> Bool {
guard let other = other as? Self else { return false }
extension Array {
var shuffled:[Element] {
var clone = self
for index1 in 0..<count {
let index2 = Int(arc4random_uniform(UInt32(count)))
guard index1 != index2 else { continue }
swap( &clone[index1], &clone[index2] )
}
return clone
@werner-freytag
werner-freytag / php-xhprof
Last active August 29, 2015 14:23
One-liner for profiling a PHP page with XHProf
register_shutdown_function(function(){$d=xhprof_disable();uasort($d,function($a,$b){$k='wt';return$a[$k]>$b[$k]?-1:$a[$k]!=$b[$k];});var_export($d);});xhprof_enable();
@werner-freytag
werner-freytag / Vagrantfile
Last active May 24, 2017 15:04
Vagrant files for Ubuntu 14.04 (Trusty Tahr) with lighttpd and php
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu-14.04"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
config.vm.network :forwarded_port, guest: 80, host: 8888
@werner-freytag
werner-freytag / Fix VirtualBox Guest Additions update
Last active August 29, 2015 13:58
Fix for vagrant: "An error occurred during installation of VirtualBox Guest Additions" after updating virtual box additions
1. Connect to vagrant:
----------------------
vagrant ssh
2. In Vagrant:
--------------
sudo ln -s /opt/VBoxGuestAdditions-*/lib/VBoxGuestAdditions /usr/lib/VBoxGuestAdditions
exit
@werner-freytag
werner-freytag / Vagrantfile
Last active August 29, 2015 13:58 — forked from erochest/Vagrantfile
Bare-bones vagrant files for Ubuntu 14.04 (Trusty Tahr) 64 bit
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu-14.04"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
end