Skip to content

Instantly share code, notes, and snippets.

View Nydhal's full-sized avatar
🎯
Focusing

Nidhal Selmi Nydhal

🎯
Focusing
View GitHub Profile
time valueA valueB valueC
1 2 5 13
2 3 4 14
3 1 4 16
4 7 4 12
5 8 8 7
6 8 13 9
7 5 15 3
8 4 17 2
9 9 18 1
@Nydhal
Nydhal / queue.cpp
Last active November 12, 2021 04:47
Queue Class example with explanations in C++
#include <iostream>
using namespace std;
class Queue { // Class definition
private: //private members can only be accessed in the class
int queue_size;
protected: // protected members can ba accessed in derived classes
int* buffer; // pointer to first element of array
int front; // used for removing an element of array
int rear; // user for adding an element into queue
@Nydhal
Nydhal / hn_upvoted_scraper.js
Created July 25, 2020 11:24
Scrape all your HN upvoted links and Export to CSV or HTML (from your browser).
/*
Search HN upvoted from your browser and Export to CSV or HTML.
1. Navigate your browser to https://news.ycombinator.com/user?id=YOUR_USER_ID
2. Copy code to the browser console and run.
4. Look for the popup window in the upper-left corner of your browser.
*/
(function () {
const popup = createPopup('HN upvoted');
const base = 'news.ycombinator.com';
@Nydhal
Nydhal / coupon_cover.py
Created December 4, 2019 14:54
Python Simulation of the Coupon Collector Problem Expectation a.k.a Mean Cover Time of a Random Walk on a Complete Graph K_n (n=52, 10000 trials).
import random as rd
for _ in range(10000): seen, n_draws = set(), 0
while len(seen)<52:
seen.add(rd.randint(1,52))
n_draws +=1
result.append(n_draws)
print (sum(result) / len(result))
@Nydhal
Nydhal / app.gif
Last active April 16, 2019 03:50
Gif in the Gist
app.gif
import asyncio
async def FizzBuzz(i: int):
await asyncio.sleep(i)
print("Fizz"*(i%3==0)+"Buzz"*(i%5==0) or i)
async def SleepFizzBuzz(l,loop):
tasks = [loop.create_task(FizzBuzz(i)) for i in range(1,l+1)]
for t in tasks:
await t
@Nydhal
Nydhal / Corr_Matrix_Generation.ipynb
Last active December 31, 2018 17:30
Based on this tweet: DATA SCIENCE TRICK DU JOUR https://twitter.com/nntaleb/status/1079029317814890497
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# coding=utf-8
import urllib3 as u
from bs4 import BeautifulSoup
from tabulate import tabulate
import pandas as pd
digikey_id_list = ['product-details', 'prod-att-table'] # Digi-Key tables
def get_soup(url):
@Nydhal
Nydhal / audio.html
Last active July 6, 2018 00:40
Stylized HTML5 audio player
<!DOCTYPE html><html><body>
<style> audio { filter:
sepia(100%)
saturate(220%)
grayscale(0)
contrast(60%)
hue-rotate(50deg)
invert(100%)
drop-shadow(0px 0px 0px #ff0000);
</style>
from sympy import binomial as b
def getA2B(X,Y,x,y):
U,D,s = X==x,Y==y,x+y
u = sum([b(s,i) for i in range(0,y)])
d = sum([b(s,i) for i in range(y+1,s+1)])
r = u*U+b(s,y)+D*d
return r/2**s
print('B(3,4) C(3,3) => ',getA2B(3,4,3,3))
# Problem represnetation :
# Enter destination coordinates B(X,Y) and intercept point C(x,y)