Skip to content

Instantly share code, notes, and snippets.

View hadaytullah's full-sized avatar

Hadaytullah hadaytullah

View GitHub Profile
@hadaytullah
hadaytullah / highOrderBitmask.php
Last active October 25, 2019 09:18
Calculates high order bit mask for a word size
<? php
function high_order_bitmask($wordSize) {
if($wordSize == 0 or $wordSize == 1){
return 0;
}
$bitmask = 0;
for($i=$wordSize-1; $i >= $wordSize/2; $i-- ){
$bitmask += pow(2,$i);
}
return $bitmask;
@hadaytullah
hadaytullah / markdownToPhp.php
Last active October 25, 2019 09:19
Convert header h1-h6 markdown in php to html
<? php
function markdown_parser ($markdown) {
$segments = explode('# ', trim($markdown), 2);
if(count($segments)>1){
//adding back the hash that explode removed, this simplifies the logic below
$segments[0] = $segments[0].'#';
//making sure that all are hashes and nothing else at the start of markdown
$first_array = str_split($segments[0]);
$unique = array_unique($first_array);