<?php
class Net
{
public static function netMask($cidr)
{
$ipc = explode('/', $cidr);
$ip = $ipc[0];
$bc = $ipc[1];
$netmask = str_split(str_pad(str_pad('', $bc, '1'), 32, '0'), 8);
foreach ($netmask as &$element) {
$element = bindec($element);
}
return array($ip, join('.', $netmask));
}
}
print_r(Net::netMask('84.22.142.192/27'));
// Выхлоп:
// Array
// (
// [0] => 84.22.142.192
// [1] => 255.255.255.224
// )
extension String {
func components(withLength length: Int) -> [String] {
return stride(from:0, to: self.count, by: length).map {
let start = self.index(self.startIndex, offsetBy: $0)
let end = self.index(start, offsetBy: length, limitedBy: self.endIndex) ?? self.endIndex
return String(self[start ..< end])
}
}
}
let str = "123456789"
let comp1 = str.components(withLength: 4)
let comp2 = str.components(withLength: 3)
dump(comp1)
dump(comp2)
on idle
display notification "Человек, тебе необходимо отвлечься от монитора" with title "Notification" subtitle "Следующее напоминание через 10 минут." sound name "Bell"
say "Человек, тебе необходимо отвлечься"
return 10 * 60
end idle