Skip to content

Instantly share code, notes, and snippets.

View MNoorFawi's full-sized avatar

Muhammad Noor Fawi MNoorFawi

View GitHub Profile
@MNoorFawi
MNoorFawi / bit_count.sql
Created May 29, 2020 22:34
Implementing bit count function in PostgreSQL database
CREATE OR REPLACE FUNCTION bits_count(value bigint) RETURNS integer AS $$
DECLARE i integer;
c integer;
bits BIT(25);
BEGIN
c := 0;
bits := value::BIT(25);
FOR i IN 1..LENGTH(bits) LOOP
IF substring(bits, i, 1) = B'1' THEN
c := c + 1;
@MNoorFawi
MNoorFawi / range_binary_search.c
Created August 3, 2020 01:14
Range Binary Search in C
void range_binary_search(int *array, int len, int val, int *res) {
int right = 0;
int left = 0;
int middle;
// not found
if(val < array[0] || val > array[len - 1]){
right = 0;
left = -1;
}
@MNoorFawi
MNoorFawi / stack.c
Created August 21, 2020 18:06
Stack data structure implementation in C
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
void create_stack(stack * st) {
st -> indx = -1;
st -> size = 0;
}
// check empty
@MNoorFawi
MNoorFawi / priority_queue.c
Created August 21, 2020 18:08
Priority queue data structure implementation in C
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define STRLEN 20
struct linked_queue {
char data[STRLEN];
float priority;
struct linked_queue * next;
};
@MNoorFawi
MNoorFawi / pymc3_bayesian_nn.py
Last active July 1, 2023 08:19
bayesian neural network using pymc3 library with residual block and dropout
import pickle
import numpy as np
import theano
import pymc3 as pm
def relu(x):
return pm.math.maximum(0, x)