Skip to content

Instantly share code, notes, and snippets.

View omargfh's full-sized avatar

Omar Ibrahim omargfh

View GitHub Profile
@omargfh
omargfh / check.py
Created December 10, 2020 01:35
CS50 PSET6 Check50 Alternative
import os
import re
with open("makefile", "r") as file:
data = file.read().split('\n')
i, error = 1, 0
for argument in data:
pattern = re.compile(r'(?:as\s)(python)(\sdna.py\sdatabases/[a-zA-Z]+\.csv\ssequences/[0-9]+\.txt)')
command = pattern.finditer(argument)
namept = re.compile(r'(No\s)?[a-zA-Z]+\.$')
@omargfh
omargfh / index.html
Created December 24, 2020 01:32
Web Pop-up Window using jQuery
<div id="pop-up" class="pop-up hidden">
<div class="pop-up-window" id="pop-up-window">
<div id="pop-up-close" class="pop-up-close">✕</div>
<div id="pop-up-content" class="pop-up-content">
</div>
</div>
</div>
<div class="pop-up-call" data-content="(some HTML)"></div>
@omargfh
omargfh / index.html
Last active December 24, 2020 07:34
Hover-to-expand Effect in jQuery
<div class="flex">
<div class="show-gallery-item-on-hover"></div>
<div class="gallery-item" id="gallery-item-first">
<img src="https://via.placeholder.com/350x250/0000FF/808080%20" alt="placeholder">
</div>
<div class="gallery-item" id="gallery-item-second">
<img src="https://via.placeholder.com/350x250" alt="placeholder">
</div>
<div class="gallery-item" id="gallery-item-third">
<img src="https://via.placeholder.com/350x250/FF10A8/202020%20">
@omargfh
omargfh / csv-dictwriter-to-string.py
Created June 24, 2021 13:15
essentially a csv.dictwriter() with a string output, takes in a list of dictionaries and returns the values separated by commas
import re
def dictwriter(dict_list, delimiter=",", end="\n"):
return re.sub(",,", "", end.join([delimiter.join(items) for items in [list([str(v) for (k,v) in list_item.items()]) for list_item in dict_list]]))
@omargfh
omargfh / print_array_in_c.c
Last active January 26, 2022 18:30
Prints an array as a string in C for testing and debugging. The function takes an array of numbers, the size of that array, a string (out variable), and the size of that string. The string must be of sufficient memory space to store all characters in array. This implementation is MEMORY SAFE.
// TESTING PURPOSES: converts an array as a string for printing
// e.g., show_arr({1, 2, 3}, 3, char[10], 10) (psuedo-code)
void show_arr(int arr[], int len_a, char* p, int len_p) {
// The function begins by testing whether the passed string container has
// sufficient space to store the string-casted array. It accounts for the
// opening and closing curly braces, each digit, and a separating comma
// between values. Thus, character_count starts at 2 for curly braces.
// Then it is incremented by 1 for each value in the array and
// incremented by the number of digits in each value as well.
@omargfh
omargfh / binary_search.js
Created February 18, 2022 17:48
Binary Search in Javascript
const binary_search = (arr, q) => {
const halfway = (l, h) => { return Math.floor((l + h) / 2) }
const strcmp = ( str1, str2 ) => {
// http://kevin.vanzonneveld.net
// + original by: Waldo Malqui Silva
// + input by: Steve Hilder
// + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// + revised by: gorthaur
@omargfh
omargfh / displayBits.c
Created April 14, 2022 02:47
displayBits.c
void display(int val) {
for(int i = 0, s = sizeof(val) * 8; i < s; i++) {
if (!(i % 8) && i != 0) {
printf(" ");
}
printf("%d", (val >> (s - 1 - i)) & 0x01);
}
printf("\n");
}
@omargfh
omargfh / Gallery.js
Created July 24, 2022 22:42
Next.js Bootstrap Gallery with Image Viewer
@omargfh
omargfh / index.js
Created August 13, 2022 20:36
React Custom Select Dropdown
import {useState} from 'react';
import Select from 'select';
export default function index() {
const options = ['Option A', 'Option B', 'Option C'];
const [activeOption, setActiveOption] = useState('Option A');
return (
<>
<Select options={options} setSelected={setActiveOption} />
import numpy as np
class Trial(object):
def __init__(self, mass, data, height):
self.mass = mass
self.data = data
self.energy = self.mass * 9.8 * height
self.average = np.average(self.data)
self.std = np.std(self.data)
self.error = self.std / np.sqrt(len(self.data))