Skip to content

Instantly share code, notes, and snippets.

View kobus1998's full-sized avatar
😳
-10x programmer

Kobus kobus1998

😳
-10x programmer
View GitHub Profile
@kobus1998
kobus1998 / FizzBuzz.rs
Created March 9, 2018 10:33
Rust fizzbuzz
fn main() {
let max: i32 = 101;
let mut l: Vec<String> = Vec::new();
for i in 0..max
{
l.push(fizz_buzz(i));
}
@kobus1998
kobus1998 / index.php
Created March 21, 2018 15:52
Event dispatcher
<?php
class Event
{
public static $events;
public function __construct()
{
self::$events = [];
@kobus1998
kobus1998 / index.php
Created March 22, 2018 11:34
Modify all html and xml nodes
<?php
$p = "/<\s*[^\/].*\s*>/";
$str = "
<div>
<p>
Tessttst jhsdfb skfsdk
</p>
</div>
@kobus1998
kobus1998 / Iter.php
Created April 20, 2018 13:59
Iterator
<?php
class Iter {
private $arr;
private $result;
public function __construct($array) {
$this->arr = $array;
}
@kobus1998
kobus1998 / Enum.php
Created April 30, 2018 15:04
Enum in php
<?php
class Enum {
private static $constCacheArray = NULL;
private static function getConstants() {
if (self::$constCacheArray == NULL) {
self::$constCacheArray = [];
}
$calledClass = get_called_class();
@kobus1998
kobus1998 / FlashMsg.php
Created May 9, 2018 14:32
Flash messages
<?php
class FlashMsg {
const SUCCESS = 'success';
const WARNING = 'warning';
const ERROR = 'error';
/**
* Static msgs holder
@kobus1998
kobus1998 / something.php
Created July 18, 2018 13:50
PHP Validate mail body
<?php
/**
* Make sure lines are right length in mail body
* @param string mail body
* @param int max line length (default 68)
* @param bool only return bool instead of modified body (default false)
* @return string|bool validated body
*/
function validateMailBody($sBody, $iMaxLen = 68, $bReturnBool = false)
@kobus1998
kobus1998 / index.php
Created August 13, 2018 08:50
PHP Reflection get type hint
<?php
class X {
public function get(array $arr) {
return $arr;
}
}
$reflect = new ReflectionMethod('X', 'get');
// first param for sake of example
@kobus1998
kobus1998 / MyService.php
Created August 14, 2018 15:08
SImple service runner including adapter
<?php
class MyService implements ServiceInterface
{
public function boot() {
echo "booting..\n";
}
public function run() {
echo "running...\n";
@kobus1998
kobus1998 / index.php
Created August 27, 2018 14:47
array to xml
<?php
function isAssoc(array $arr)
{
if (array() === $arr) return false;
return array_keys($arr) !== range(0, count($arr) - 1);
}
function toXml($name, $a) {
$sReturn = "<$name>";